diff options
Diffstat (limited to 'spec/ruby/core/module/shared')
| -rw-r--r-- | spec/ruby/core/module/shared/class_eval.rb | 22 | ||||
| -rw-r--r-- | spec/ruby/core/module/shared/class_exec.rb | 12 | ||||
| -rw-r--r-- | spec/ruby/core/module/shared/set_visibility.rb | 36 |
3 files changed, 37 insertions, 33 deletions
diff --git a/spec/ruby/core/module/shared/class_eval.rb b/spec/ruby/core/module/shared/class_eval.rb index b1d5cb3814..ee2860449a 100644 --- a/spec/ruby/core/module/shared/class_eval.rb +++ b/spec/ruby/core/module/shared/class_eval.rb @@ -14,7 +14,7 @@ describe :module_class_eval, shared: true do 'foo' end end - -> {42.foo}.should raise_error(NoMethodError) + -> {42.foo}.should.raise(NoMethodError) end it "resolves constants in the caller scope" do @@ -45,17 +45,15 @@ describe :module_class_eval, shared: true do ModuleSpecs.send(@method) do |block_parameter| given = block_parameter end - given.should equal ModuleSpecs + given.should.equal? ModuleSpecs end it "uses the optional filename and lineno parameters for error messages" do ModuleSpecs.send(@method, "[__FILE__, __LINE__]", "test", 102).should == ["test", 102] end - ruby_version_is "3.3" do - it "uses the caller location as default filename" do - ModuleSpecs.send(@method, "[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] - end + it "uses the caller location as default filename" do + ModuleSpecs.send(@method, "[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] end it "converts a non-string filename to a string using to_str" do @@ -68,7 +66,7 @@ describe :module_class_eval, shared: true do it "raises a TypeError when the given filename can't be converted to string using to_str" do (file = mock('123')).should_receive(:to_str).and_return(123) - -> { ModuleSpecs.send(@method, "1+1", file) }.should raise_error(TypeError, /can't convert MockObject to String/) + -> { ModuleSpecs.send(@method, "1+1", file) }.should raise_consistent_error(TypeError, /can't convert MockObject into String/) end it "converts non string eval-string to string using to_str" do @@ -84,26 +82,26 @@ describe :module_class_eval, shared: true do it "raises a TypeError when the given eval-string can't be converted to string using to_str" do o = mock('x') - -> { ModuleSpecs.send(@method, o) }.should raise_error(TypeError, "no implicit conversion of MockObject into String") + -> { ModuleSpecs.send(@method, o) }.should.raise(TypeError, "no implicit conversion of MockObject into String") (o = mock('123')).should_receive(:to_str).and_return(123) - -> { ModuleSpecs.send(@method, o) }.should raise_error(TypeError, /can't convert MockObject to String/) + -> { ModuleSpecs.send(@method, o) }.should raise_consistent_error(TypeError, /can't convert MockObject into String/) end it "raises an ArgumentError when no arguments and no block are given" do - -> { ModuleSpecs.send(@method) }.should raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1..3)") + -> { ModuleSpecs.send(@method) }.should.raise(ArgumentError, "wrong number of arguments (given 0, expected 1..3)") end it "raises an ArgumentError when more than 3 arguments are given" do -> { ModuleSpecs.send(@method, "1 + 1", "some file", 0, "bogus") - }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") + }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end it "raises an ArgumentError when a block and normal arguments are given" do -> { ModuleSpecs.send(@method, "1 + 1") { 1 + 1 } - }.should raise_error(ArgumentError, "wrong number of arguments (given 1, expected 0)") + }.should.raise(ArgumentError, "wrong number of arguments (given 1, expected 0)") end # This case was found because Rubinius was caching the compiled diff --git a/spec/ruby/core/module/shared/class_exec.rb b/spec/ruby/core/module/shared/class_exec.rb index c7a9e5297f..e51af1966d 100644 --- a/spec/ruby/core/module/shared/class_exec.rb +++ b/spec/ruby/core/module/shared/class_exec.rb @@ -5,7 +5,7 @@ describe :module_class_exec, shared: true do 'foo' end end - -> {42.foo}.should raise_error(NoMethodError) + -> {42.foo}.should.raise(NoMethodError) end it "defines method in the receiver's scope" do @@ -19,11 +19,17 @@ describe :module_class_exec, shared: true do end it "raises a LocalJumpError when no block is given" do - -> { ModuleSpecs::Subclass.send(@method) }.should raise_error(LocalJumpError) + -> { ModuleSpecs::Subclass.send(@method) }.should.raise(LocalJumpError) end it "passes arguments to the block" do a = ModuleSpecs::Subclass - a.send(@method, 1) { |b| b }.should equal(1) + a.send(@method, 1) { |b| b }.should.equal?(1) + end + + describe "with optional argument" do + it "does not destructure a single array argument" do + ModuleSpecs::Subclass.send(@method, [1, 2, 3]) { |a = 99| a }.should == [1, 2, 3] + end end end diff --git a/spec/ruby/core/module/shared/set_visibility.rb b/spec/ruby/core/module/shared/set_visibility.rb index a1586dd2bd..38cc2ad260 100644 --- a/spec/ruby/core/module/shared/set_visibility.rb +++ b/spec/ruby/core/module/shared/set_visibility.rb @@ -2,7 +2,7 @@ describe :set_visibility, shared: true do it "is a private method" do - Module.should have_private_instance_method(@method, false) + Module.private_instance_methods(false).should.include?(@method) end describe "with argument" do @@ -17,8 +17,8 @@ describe :set_visibility, shared: true do def test2() end send visibility, :test1, :test2 } - mod.should send(:"have_#{visibility}_instance_method", :test1, false) - mod.should send(:"have_#{visibility}_instance_method", :test2, false) + mod.send(:"#{visibility}_instance_methods", false).should.include?(:test1) + mod.send(:"#{visibility}_instance_methods", false).should.include?(:test2) end end @@ -33,8 +33,8 @@ describe :set_visibility, shared: true do def test2() end send visibility, [:test1, :test2] } - mod.should send(:"have_#{visibility}_instance_method", :test1, false) - mod.should send(:"have_#{visibility}_instance_method", :test2, false) + mod.send(:"#{visibility}_instance_methods", false).should.include?(:test1) + mod.send(:"#{visibility}_instance_methods", false).should.include?(:test2) end end @@ -50,7 +50,7 @@ describe :set_visibility, shared: true do send(visibility, :test_method) } - child.should_not send(:"have_#{visibility}_instance_method", :test_method, false) + child.send(:"#{visibility}_instance_methods", false).should_not.include?(:test_method) end end @@ -64,8 +64,8 @@ describe :set_visibility, shared: true do def test2() end } - mod.should send(:"have_#{@method}_instance_method", :test1, false) - mod.should send(:"have_#{@method}_instance_method", :test2, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test1) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test2) end it "stops setting visibility if the body encounters other visibility setters without arguments" do @@ -78,7 +78,7 @@ describe :set_visibility, shared: true do def test1() end } - mod.should send(:"have_#{new_visibility}_instance_method", :test1, false) + mod.send(:"#{new_visibility}_instance_methods", false).should.include?(:test1) end it "continues setting visibility if the body encounters other visibility setters with arguments" do @@ -90,7 +90,7 @@ describe :set_visibility, shared: true do def test2() end } - mod.should send(:"have_#{@method}_instance_method", :test2, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test2) end it "does not affect module_evaled method definitions when itself is outside the eval" do @@ -102,8 +102,8 @@ describe :set_visibility, shared: true do module_eval " def test2() end " } - mod.should have_public_instance_method(:test1, false) - mod.should have_public_instance_method(:test2, false) + mod.public_instance_methods(false).should.include?(:test1) + mod.public_instance_methods(false).should.include?(:test2) end it "does not affect outside method definitions when itself is inside a module_eval" do @@ -114,7 +114,7 @@ describe :set_visibility, shared: true do def test1() end } - mod.should have_public_instance_method(:test1, false) + mod.public_instance_methods(false).should.include?(:test1) end it "affects normally if itself and method definitions are inside a module_eval" do @@ -127,7 +127,7 @@ describe :set_visibility, shared: true do } } - mod.should send(:"have_#{@method}_instance_method", :test1, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test1) end it "does not affect method definitions when itself is inside an eval and method definitions are outside" do @@ -140,7 +140,7 @@ describe :set_visibility, shared: true do def test1() end } - mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false) + mod.send(:"#{initialized_visibility}_instance_methods", false).should.include?(:test1) end it "affects evaled method definitions when itself is outside the eval" do @@ -151,7 +151,7 @@ describe :set_visibility, shared: true do eval "def test1() end" } - mod.should send(:"have_#{@method}_instance_method", :test1, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test1) end it "affects normally if itself and following method definitions are inside a eval" do @@ -164,7 +164,7 @@ describe :set_visibility, shared: true do CODE } - mod.should send(:"have_#{@method}_instance_method", :test1, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test1) end describe "within a closure" do @@ -177,7 +177,7 @@ describe :set_visibility, shared: true do def test1() end } - mod.should send(:"have_#{@method}_instance_method", :test1, false) + mod.send(:"#{@method}_instance_methods", false).should.include?(:test1) end end end |
