Update some ruby specs for the new message format of NoMethodError

This commit is contained in:
Yusuke Endoh 2023-01-24 17:44:14 +09:00
Родитель 8f868a1a65
Коммит 0e830e6373
1 изменённых файлов: 40 добавлений и 17 удалений

Просмотреть файл

@ -62,26 +62,49 @@ describe "NoMethodError#message" do
NoMethodErrorSpecs::NoMethodErrorC.new.a_private_method
rescue Exception => e
e.should be_kind_of(NoMethodError)
e.message.lines[0].should =~ /private method `a_private_method' called for #<NoMethodErrorSpecs::NoMethodErrorC:0x[\h]+>/
e.message.lines[0].should =~ /private method `a_private_method' called for /
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>"
ruby_version_is ""..."3.3" do
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
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
ruby_version_is "3.3" do
it "does not call receiver.inspect even 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 == []
end
end
end
@ -108,14 +131,14 @@ describe "NoMethodError#message" do
begin
klass.foo
rescue NoMethodError => error
error.message.lines.first.chomp.should == "undefined method `foo' for MyClass:Class"
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
end
mod = Module.new { def self.name; "MyModule"; end }
begin
mod.foo
rescue NoMethodError => error
error.message.lines.first.chomp.should == "undefined method `foo' for MyModule:Module"
error.message.lines.first.chomp.should =~ /^undefined method `foo' for /
end
end
end