diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/commands/wtf_spec.rb | 38 | ||||
-rw-r--r-- | spec/fixtures/test_task.rb | 5 | ||||
-rw-r--r-- | spec/method_spec.rb | 38 | ||||
-rw-r--r-- | spec/pry_spec.rb | 1 |
4 files changed, 63 insertions, 19 deletions
diff --git a/spec/commands/wtf_spec.rb b/spec/commands/wtf_spec.rb index c4af0cc5..52ad0251 100644 --- a/spec/commands/wtf_spec.rb +++ b/spec/commands/wtf_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Pry::Command::Wtf do it "prints only a part of the exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -55,7 +55,7 @@ RSpec.describe Pry::Command::Wtf do it "prints full exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -73,7 +73,7 @@ RSpec.describe Pry::Command::Wtf do it "prints more of backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -116,14 +116,14 @@ RSpec.describe Pry::Command::Wtf do it "prints parts of both original and nested exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: outer\n" \ + "\e[1mException:\e[0m RuntimeError: outer\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ "2: /bin/pry:23:in `<main>'\n" \ "3: /bin/pry:23:in `<main>'\n" \ "4: /bin/pry:23:in `<main>'\n" \ - "\001\e[1m\002Caused by:\001\e[0m\002 RuntimeError: inner\n" \ + "\e[1mCaused by:\e[0m RuntimeError: inner\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -140,7 +140,7 @@ RSpec.describe Pry::Command::Wtf do it "prints both original and nested exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: outer\n" \ + "\e[1mException:\e[0m RuntimeError: outer\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -148,7 +148,7 @@ RSpec.describe Pry::Command::Wtf do "3: /bin/pry:23:in `<main>'\n" \ "4: /bin/pry:23:in `<main>'\n" \ "5: /bin/pry:23:in `<main>'\n" \ - "\001\e[1m\002Caused by:\001\e[0m\002 RuntimeError: inner\n" \ + "\e[1mCaused by:\e[0m RuntimeError: inner\n" \ "--\n" \ "0: /bin/pry:23:in `<main>'\n" \ "1: /bin/pry:23:in `<main>'\n" \ @@ -177,17 +177,17 @@ RSpec.describe Pry::Command::Wtf do it "prints lines of code that exception frame references" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ - "0: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ + "0: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \ - "1: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ + "1: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \ - "2: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ + "2: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \ - "3: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ + "3: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" \ - "4: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ + "4: \e[1m#{__FILE__}:168:in `<main>'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `<main>'\" }\n" ) end @@ -200,13 +200,13 @@ RSpec.describe Pry::Command::Wtf do it "skips code and prints only the backtrace frame" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ - "0: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ - "1: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ - "2: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ - "3: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\n" \ - "4: \001\e[1m\002#{__FILE__}:168:in `<main>'\001\e[0m\002\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 diff --git a/spec/fixtures/test_task.rb b/spec/fixtures/test_task.rb new file mode 100644 index 00000000..714128f1 --- /dev/null +++ b/spec/fixtures/test_task.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +task :test_task do + binding +end diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 95ac075c..137a9d11 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -208,6 +208,44 @@ describe Pry::Method do m = Pry::Method.from_binding(o.borscht) expect(m.source).to eq Pry::Method(o.method(:paella)).source end + + it 'should not find a wrong method by matching on nil source location' do + included_module = Module.new do + def self.included(base) + base.send :alias_method, "respond_to_without_variables?", "respond_to?" + base.send :alias_method, "respond_to?", "respond_to_with_variables?" + end + + def respond_to_with_variables?(sym, include_priv = false) + respond_to_without_variables?(sym, include_priv) + end + end + + o = Object.new + class << o + attr_reader :tasks + def task(name, &block) + @tasks ||= {} + @tasks[name] = block + end + + def load_task + path = File.expand_path("spec/fixtures/test_task.rb") + instance_eval File.read(path), path + end + end + + o.load_task + + o2 = Object.new + o2.singleton_class.send(:include, included_module) + + # Verify preconditions. + expect(o2.method(:respond_to_without_variables?).source_location).to be_nil + + b = o2.instance_eval(&o.tasks[:test_task]) + expect(Pry::Method.from_binding(b).name).to eq "load_task" + end end describe 'super' do diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb index a1bf9669..892b437d 100644 --- a/spec/pry_spec.rb +++ b/spec/pry_spec.rb @@ -208,6 +208,7 @@ describe Pry do end it "should return with error message" do + expect(mock_pry('1 + 1')).to eql("=> 2\n") Process.kill("USR1", Process.pid) expect(@str_output).to match(/Unable to obtain mutex lock/) end |