Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Exception#inspect returns class name if #to_s is empty

  • Loading branch information...
commit 1187a83e775b0d492d5687906e2a9e4b24ac4b30 1 parent b25c5ff
@jfirebaugh jfirebaugh authored brixen committed
View
6 core/exception/fixtures/common.rb
@@ -47,4 +47,10 @@ def to_s
"this is from #to_s"
end
end
+
+ class EmptyToS < RuntimeError
+ def to_s
+ ""
+ end
+ end
end
View
9 core/exception/inspect_spec.rb
@@ -1,11 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
describe "Exception#inspect" do
it "returns '#<Exception: Exception>' when no message given" do
Exception.new.inspect.should == "#<Exception: Exception>"
end
- it "includes message when given" do
- [Exception.new("foobar").inspect].should == ["#<Exception: foobar>"]
+ it "includes #to_s when the result is non-empty" do
+ ExceptionSpecs::OverrideToS.new.inspect.should == "#<ExceptionSpecs::OverrideToS: this is from #to_s>"
+ end
+
+ it "returns the class name when #to_s returns an empty string" do
+ ExceptionSpecs::EmptyToS.new.inspect.should == "ExceptionSpecs::EmptyToS"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.