From 3f5f71bae149bbf3c4ecfa5cd92a6e3fd7b441f2 Mon Sep 17 00:00:00 2001 From: Eloy Duran Date: Thu, 31 Mar 2011 00:11:56 +0200 Subject: [PATCH] Swap comparison of result object with the IGNORE_RESULT symbol. [Closes #1046] --- lib/irb/context.rb | 2 +- spec/context_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/irb/context.rb b/lib/irb/context.rb index afcc109..0b03d00 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -38,7 +38,7 @@ def to_s def evaluate(source) result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1) - unless result == IGNORE_RESULT + unless IGNORE_RESULT == result store_result(result) output(formatter.result(result)) result diff --git a/spec/context_spec.rb b/spec/context_spec.rb index 4c637a8..5cbb57d 100644 --- a/spec/context_spec.rb +++ b/spec/context_spec.rb @@ -110,6 +110,15 @@ def o.to_s; "self"; end @output.printed.should == "=> :bananas\n" @context.evaluate("_").should == :bananas end + + describe "regression specs" do + it "does not try to convert an object to a string when checking if the evaluate result should be ignored" do + o = @context.__evaluate__("o = Object.new") + def o.==(other); raise "Ohnoes!"; end + lambda { @context.evaluate("o") }.should_not raise_error + @context.__evaluate__("exception").should == nil + end + end end describe "IRB::Context, when receiving input" do