summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-05-11 18:33:46 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-05-12 00:13:11 +0300
commit6fd2ca3b0dfda1e453ee6199888981bb58f1d51d (patch)
tree199819eb6dd357f658617aa7dccd3abfeab14cab /spec
parent68cc7fe99b94cf435b10219feabb6bfab1ddd6d3 (diff)
downloadpry-6fd2ca3b0dfda1e453ee6199888981bb58f1d51d.tar.gz
commands/wtf: add the --code flag
Fixes #1876 (Make `wtf` show code)
Diffstat (limited to 'spec')
-rw-r--r--spec/commands/wtf_spec.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/commands/wtf_spec.rb b/spec/commands/wtf_spec.rb
index 3af52eff..52ad0251 100644
--- a/spec/commands/wtf_spec.rb
+++ b/spec/commands/wtf_spec.rb
@@ -160,5 +160,56 @@ RSpec.describe Pry::Command::Wtf do
end
end
end
+
+ context "when the code flag is present" do
+ let(:exception) do
+ error = RuntimeError.new('oops')
+ error.set_backtrace(
+ Array.new(6) { "#{__FILE__}:#{__LINE__}:in `<main>'" }
+ )
+ error
+ end
+
+ before do
+ expect(subject.opts).to receive(:code?).at_least(:once).and_return(true)
+ end
+
+ it "prints lines of code that exception frame references" do
+ subject.process
+ expect(subject.output.string).to eq(
+ "\e[1mException:\e[0m RuntimeError: oops\n" \
+ "--\n" \
+ "0: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \
+ "1: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \
+ "2: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \
+ "3: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \
+ "4: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n"
+ )
+ end
+
+ context "and when referenced frame doesn't exist" do
+ before do
+ expect(File).to receive(:open).at_least(:once).and_raise(Errno::ENOENT)
+ end
+
+ it "skips code and prints only the backtrace frame" do
+ subject.process
+ expect(subject.output.string).to eq(
+ "\e[1mException:\e[0m RuntimeError: oops\n" \
+ "--\n" \
+ "0: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ "1: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ "2: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ "3: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \
+ "4: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n"
+ )
+ end
+ end
+ end
end
end