diff options
author | Benoit Daloze <eregontp@gmail.com> | 2023-06-26 15:55:11 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2023-06-26 15:55:11 +0200 |
commit | 515bd4214497b3af02f6eef51b496ad9a0cf6b3b (patch) | |
tree | 4554360d275a3bb9dc696f952b8f3d1bcd88f18a /spec/ruby/core/module | |
parent | f73fa299279ac322bd921691d1ba0e8bf2b39b5f (diff) |
Update to ruby/spec@30e1c35
Diffstat (limited to 'spec/ruby/core/module')
-rw-r--r-- | spec/ruby/core/module/alias_method_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/module/attr_accessor_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/module/attr_reader_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/module/attr_spec.rb | 22 | ||||
-rw-r--r-- | spec/ruby/core/module/attr_writer_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/module/const_set_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/core/module/fixtures/module.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/module/name_spec.rb | 54 | ||||
-rw-r--r-- | spec/ruby/core/module/prepend_spec.rb | 39 | ||||
-rw-r--r-- | spec/ruby/core/module/private_class_method_spec.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/module/public_class_method_spec.rb | 20 | ||||
-rw-r--r-- | spec/ruby/core/module/ruby2_keywords_spec.rb | 23 | ||||
-rw-r--r-- | spec/ruby/core/module/shared/set_visibility.rb | 28 |
13 files changed, 103 insertions, 181 deletions
diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb index 391efa227a..c36dedd2d8 100644 --- a/spec/ruby/core/module/alias_method_spec.rb +++ b/spec/ruby/core/module/alias_method_spec.rb @@ -92,17 +92,9 @@ describe "Module#alias_method" do end describe "returned value" do - ruby_version_is ""..."3.0" do - it "returns self" do - @class.send(:alias_method, :checking_return_value, :public_one).should equal(@class) - end - end - - ruby_version_is "3.0" do - it "returns symbol of the defined method name" do - @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value) - @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value) - end + it "returns symbol of the defined method name" do + @class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value) + @class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value) end end diff --git a/spec/ruby/core/module/attr_accessor_spec.rb b/spec/ruby/core/module/attr_accessor_spec.rb index ba5289cbea..eea5b4b64b 100644 --- a/spec/ruby/core/module/attr_accessor_spec.rb +++ b/spec/ruby/core/module/attr_accessor_spec.rb @@ -80,19 +80,9 @@ describe "Module#attr_accessor" do Module.should have_public_instance_method(:attr_accessor, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_accessor :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=] end end diff --git a/spec/ruby/core/module/attr_reader_spec.rb b/spec/ruby/core/module/attr_reader_spec.rb index b0ae906ab5..0b6d996719 100644 --- a/spec/ruby/core/module/attr_reader_spec.rb +++ b/spec/ruby/core/module/attr_reader_spec.rb @@ -62,19 +62,9 @@ describe "Module#attr_reader" do Module.should have_public_instance_method(:attr_reader, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_reader :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_reader :foo, 'bar').should == [:foo, :bar] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_reader :foo, 'bar').should == [:foo, :bar] end end end diff --git a/spec/ruby/core/module/attr_spec.rb b/spec/ruby/core/module/attr_spec.rb index 33e0eb8628..72a6646b1e 100644 --- a/spec/ruby/core/module/attr_spec.rb +++ b/spec/ruby/core/module/attr_spec.rb @@ -146,23 +146,11 @@ describe "Module#attr" do Module.should have_public_instance_method(:attr, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr :foo, 'bar').should == nil - (attr :baz, false).should == nil - (attr :qux, true).should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr :foo, 'bar').should == [:foo, :bar] - (attr :baz, false).should == [:baz] - (attr :qux, true).should == [:qux, :qux=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr :foo, 'bar').should == [:foo, :bar] + (attr :baz, false).should == [:baz] + (attr :qux, true).should == [:qux, :qux=] end end end diff --git a/spec/ruby/core/module/attr_writer_spec.rb b/spec/ruby/core/module/attr_writer_spec.rb index 0e9d201317..aaea0ce43f 100644 --- a/spec/ruby/core/module/attr_writer_spec.rb +++ b/spec/ruby/core/module/attr_writer_spec.rb @@ -72,19 +72,9 @@ describe "Module#attr_writer" do Module.should have_public_instance_method(:attr_writer, false) end - ruby_version_is ""..."3.0" do - it "returns nil" do - Class.new do - (attr_writer :foo, 'bar').should == nil - end - end - end - - ruby_version_is "3.0" do - it "returns an array of defined method names as symbols" do - Class.new do - (attr_writer :foo, 'bar').should == [:foo=, :bar=] - end + it "returns an array of defined method names as symbols" do + Class.new do + (attr_writer :foo, 'bar').should == [:foo=, :bar=] end end end diff --git a/spec/ruby/core/module/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb index ba7810d17b..5bdfd7b68f 100644 --- a/spec/ruby/core/module/const_set_spec.rb +++ b/spec/ruby/core/module/const_set_spec.rb @@ -20,20 +20,10 @@ describe "Module#const_set" do m.name.should == "ConstantSpecs::CS_CONST1000" end - ruby_version_is ""..."3.0" do - it "does not set the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a.const_set :B, b - b.name.should be_nil - end - end - - ruby_version_is "3.0" do - it "sets the name of a module scoped by an anonymous module" do - a, b = Module.new, Module.new - a.const_set :B, b - b.name.should.end_with? '::B' - end + it "sets the name of a module scoped by an anonymous module" do + a, b = Module.new, Module.new + a.const_set :B, b + b.name.should.end_with? '::B' end it "sets the name of contained modules when assigning a toplevel anonymous module" do diff --git a/spec/ruby/core/module/fixtures/module.rb b/spec/ruby/core/module/fixtures/module.rb index 9050a272ec..34543ca2b4 100644 --- a/spec/ruby/core/module/fixtures/module.rb +++ b/spec/ruby/core/module/fixtures/module.rb @@ -1,4 +1,8 @@ module ModuleSpecs module Anonymous + module Child + end + + SameChild = Child end end diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index bbc1841239..bb7fa1761c 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -55,20 +55,10 @@ describe "Module#name" do end end - ruby_version_is ""..."3.0" do - it "is nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should be_nil - end - end - - ruby_version_is "3.0" do - it "is not nil when assigned to a constant in an anonymous module" do - m = Module.new - m::N = Module.new - m::N.name.should.end_with? '::N' - end + it "is not nil when assigned to a constant in an anonymous module" do + m = Module.new + m::N = Module.new + m::N.name.should.end_with? '::N' end it "is not nil for a nested module created with the module keyword" do @@ -91,6 +81,19 @@ describe "Module#name" do m::N.name.should == "ModuleSpecs::Anonymous::WasAnnon" end + it "may be the repeated in different module objects" do + m = Module.new + n = Module.new + + suppress_warning do + ModuleSpecs::Anonymous::SameName = m + ModuleSpecs::Anonymous::SameName = n + end + + m.name.should == "ModuleSpecs::Anonymous::SameName" + n.name.should == "ModuleSpecs::Anonymous::SameName" + end + it "is set after it is removed from a constant" do module ModuleSpecs module ModuleToRemove @@ -118,12 +121,18 @@ describe "Module#name" do ModuleSpecs::Anonymous.name.should == "ModuleSpecs::Anonymous" end - it "is set when assigning to a constant" do + it "is set when assigning to a constant (constant path matches outer module name)" do m = Module.new ModuleSpecs::Anonymous::A = m m.name.should == "ModuleSpecs::Anonymous::A" end + it "is set when assigning to a constant (constant path does not match outer module name)" do + m = Module.new + ModuleSpecs::Anonymous::SameChild::A = m + m.name.should == "ModuleSpecs::Anonymous::Child::A" + end + it "is not modified when assigning to a new constant after it has been accessed" do m = Module.new ModuleSpecs::Anonymous::B = m @@ -160,13 +169,26 @@ describe "Module#name" do ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8 end - it "is set when the anonymous outer module name is set" do + it "is set when the anonymous outer module name is set (module in one single constant)" do m = Module.new m::N = Module.new ModuleSpecs::Anonymous::E = m m::N.name.should == "ModuleSpecs::Anonymous::E::N" end + # https://bugs.ruby-lang.org/issues/19681 + it "is set when the anonymous outer module name is set (module in several constants)" do + m = Module.new + m::N = Module.new + m::O = m::N + ModuleSpecs::Anonymous::StoredInMultiplePlaces = m + valid_names = [ + "ModuleSpecs::Anonymous::StoredInMultiplePlaces::N", + "ModuleSpecs::Anonymous::StoredInMultiplePlaces::O" + ] + valid_names.should include(m::N.name) # You get one of the two, but you don't know which one. + end + it "returns a frozen String" do ModuleSpecs.name.should.frozen? end diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index 976b09b105..96598e7209 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -499,34 +499,17 @@ describe "Module#prepend" do c.dup.new.should be_kind_of(m) end - ruby_version_is ''...'3.0' do - it "keeps the module in the chain when dupping an intermediate module" do - m1 = Module.new { def calc(x) x end } - m2 = Module.new { prepend(m1) } - c1 = Class.new { prepend(m2) } - m2dup = m2.dup - m2dup.ancestors.should == [m2dup,m1,m2] - c2 = Class.new { prepend(m2dup) } - c1.ancestors[0,3].should == [m1,m2,c1] - c1.new.should be_kind_of(m1) - c2.ancestors[0,4].should == [m2dup,m1,m2,c2] - c2.new.should be_kind_of(m1) - end - end - - ruby_version_is '3.0' do - it "uses only new module when dupping the module" do - m1 = Module.new { def calc(x) x end } - m2 = Module.new { prepend(m1) } - c1 = Class.new { prepend(m2) } - m2dup = m2.dup - m2dup.ancestors.should == [m1,m2dup] - c2 = Class.new { prepend(m2dup) } - c1.ancestors[0,3].should == [m1,m2,c1] - c1.new.should be_kind_of(m1) - c2.ancestors[0,3].should == [m1,m2dup,c2] - c2.new.should be_kind_of(m1) - end + it "uses only new module when dupping the module" do + m1 = Module.new { def calc(x) x end } + m2 = Module.new { prepend(m1) } + c1 = Class.new { prepend(m2) } + m2dup = m2.dup + m2dup.ancestors.should == [m1,m2dup] + c2 = Class.new { prepend(m2dup) } + c1.ancestors[0,3].should == [m1,m2,c1] + c1.new.should be_kind_of(m1) + c2.ancestors[0,3].should == [m1,m2dup,c2] + c2.new.should be_kind_of(m1) end it "depends on prepend_features to add the module" do diff --git a/spec/ruby/core/module/private_class_method_spec.rb b/spec/ruby/core/module/private_class_method_spec.rb index 407779cccc..f899c71a57 100644 --- a/spec/ruby/core/module/private_class_method_spec.rb +++ b/spec/ruby/core/module/private_class_method_spec.rb @@ -79,15 +79,13 @@ describe "Module#private_class_method" do end.should raise_error(NameError) end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "sets the visibility of the given methods to private" do - c = Class.new do - def self.foo() "foo" end - private_class_method [:foo] - end - -> { c.foo }.should raise_error(NoMethodError) + context "when single argument is passed and is an array" do + it "sets the visibility of the given methods to private" do + c = Class.new do + def self.foo() "foo" end + private_class_method [:foo] end + -> { c.foo }.should raise_error(NoMethodError) end end end diff --git a/spec/ruby/core/module/public_class_method_spec.rb b/spec/ruby/core/module/public_class_method_spec.rb index b5d76e7b7a..71b20acda5 100644 --- a/spec/ruby/core/module/public_class_method_spec.rb +++ b/spec/ruby/core/module/public_class_method_spec.rb @@ -78,19 +78,17 @@ describe "Module#public_class_method" do end.should raise_error(NameError) end - ruby_version_is "3.0" do - context "when single argument is passed and is an array" do - it "makes a class method public" do - c = Class.new do - class << self - private - def foo() "foo" end - end - public_class_method [:foo] + context "when single argument is passed and is an array" do + it "makes a class method public" do + c = Class.new do + class << self + private + def foo() "foo" end end - - c.foo.should == "foo" + public_class_method [:foo] end + + c.foo.should == "foo" end end end diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb index 80a99e2624..dc16d712c7 100644 --- a/spec/ruby/core/module/ruby2_keywords_spec.rb +++ b/spec/ruby/core/module/ruby2_keywords_spec.rb @@ -22,9 +22,7 @@ describe "Module#ruby2_keywords" do end h = {a: 1} - ruby_version_is "3.0" do - obj.regular(**h).should.equal?(h) - end + obj.regular(**h).should.equal?(h) last = mark(**h).last Hash.ruby2_keywords_hash?(last).should == true @@ -223,25 +221,6 @@ describe "Module#ruby2_keywords" do Hash.ruby2_keywords_hash?(last).should == true end - ruby_version_is ""..."3.0" do - it "fixes delegation warnings when calling a method accepting keywords" do - obj = Object.new - - obj.singleton_class.class_exec do - def foo(*a) bar(*a) end - def bar(*a, **b) end - end - - -> { obj.foo(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/) - - obj.singleton_class.class_exec do - ruby2_keywords :foo - end - - -> { obj.foo(1, 2, {a: "a"}) }.should_not complain - end - end - it "returns nil" do obj = Object.new diff --git a/spec/ruby/core/module/shared/set_visibility.rb b/spec/ruby/core/module/shared/set_visibility.rb index 9f31e230ca..a1586dd2bd 100644 --- a/spec/ruby/core/module/shared/set_visibility.rb +++ b/spec/ruby/core/module/shared/set_visibility.rb @@ -22,21 +22,19 @@ describe :set_visibility, shared: true do end end - ruby_version_is "3.0" do - describe "array as a single argument" do - it "sets visibility of given method names" do - visibility = @method - old_visibility = [:protected, :private].find {|vis| vis != visibility } - - mod = Module.new { - send old_visibility - def test1() end - 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) - end + describe "array as a single argument" do + it "sets visibility of given method names" do + visibility = @method + old_visibility = [:protected, :private].find {|vis| vis != visibility } + + mod = Module.new { + send old_visibility + def test1() end + 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) end end |