summaryrefslogtreecommitdiff
path: root/spec/ruby/core/exception
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-29 16:08:16 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-29 16:08:16 +0000
commit3fa5bd38af50fb3d98de0ea51043d73f8d06a24b (patch)
treed473b71cc6925ee1e17727215e9f9a66e3f24802 /spec/ruby/core/exception
parent1e658d45e1f8dbadab18f9c35b5cfb5a5fec98bf (diff)
Update to ruby/spec@83063a3
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r--spec/ruby/core/exception/exception_spec.rb2
-rw-r--r--spec/ruby/core/exception/fixtures/common.rb3
-rw-r--r--spec/ruby/core/exception/new_spec.rb2
-rw-r--r--spec/ruby/core/exception/no_method_error_spec.rb36
4 files changed, 41 insertions, 2 deletions
diff --git a/spec/ruby/core/exception/exception_spec.rb b/spec/ruby/core/exception/exception_spec.rb
index afa482b9d7..780bfa4831 100644
--- a/spec/ruby/core/exception/exception_spec.rb
+++ b/spec/ruby/core/exception/exception_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../fixtures/common', __FILE__)
require File.expand_path('../shared/new', __FILE__)
describe "Exception.exception" do
- it_behaves_like(:exception_new, :exception)
+ it_behaves_like :exception_new, :exception
end
describe "Exception" do
diff --git a/spec/ruby/core/exception/fixtures/common.rb b/spec/ruby/core/exception/fixtures/common.rb
index 51dd0bf9ed..e1ba102197 100644
--- a/spec/ruby/core/exception/fixtures/common.rb
+++ b/spec/ruby/core/exception/fixtures/common.rb
@@ -53,6 +53,9 @@ module NoMethodErrorSpecs
end
class NoMethodErrorD; end
+
+ class InstanceException < Exception
+ end
end
class NameErrorSpecs
diff --git a/spec/ruby/core/exception/new_spec.rb b/spec/ruby/core/exception/new_spec.rb
index 61d35a1dfa..2fc7ca9f88 100644
--- a/spec/ruby/core/exception/new_spec.rb
+++ b/spec/ruby/core/exception/new_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/common', __FILE__)
require File.expand_path('../shared/new', __FILE__)
describe "Exception.new" do
- it_behaves_like(:exception_new, :new)
+ it_behaves_like :exception_new, :new
end
diff --git a/spec/ruby/core/exception/no_method_error_spec.rb b/spec/ruby/core/exception/no_method_error_spec.rb
index cf3fe58b1d..321b2b4a8f 100644
--- a/spec/ruby/core/exception/no_method_error_spec.rb
+++ b/spec/ruby/core/exception/no_method_error_spec.rb
@@ -56,4 +56,40 @@ describe "NoMethodError#message" do
e.message.match(/private method/).should_not == nil
end
end
+
+ it "calls receiver.inspect only when calling Exception#message" do
+ ScratchPad.record []
+ test_class = Class.new do
+ def inspect
+ ScratchPad << :inspect_called
+ "<inspect>"
+ end
+ end
+ instance = test_class.new
+ begin
+ instance.bar
+ rescue Exception => e
+ e.name.should == :bar
+ ScratchPad.recorded.should == []
+ e.message.should =~ /undefined method.+\bbar\b/
+ ScratchPad.recorded.should == [:inspect_called]
+ end
+ end
+
+ it "fallbacks to a simpler representation of the receiver when receiver.inspect raises an exception" do
+ test_class = Class.new do
+ def inspect
+ raise NoMethodErrorSpecs::InstanceException
+ end
+ end
+ instance = test_class.new
+ begin
+ instance.bar
+ rescue Exception => e
+ e.name.should == :bar
+ message = e.message
+ message.should =~ /undefined method.+\bbar\b/
+ message.should include test_class.inspect
+ end
+ end
end