aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-18 15:55:10 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-18 15:55:10 +0900
commitc3d6bac325dcc4868977b15503641afa48092119 (patch)
tree4aedcd3472810c96a4837323786e2e2a620f4997
parenta3851d97edec4979b886428136b1c62089d57d17 (diff)
downloadruby-c3d6bac325dcc4868977b15503641afa48092119.tar.gz
Upcoming Struct#new behavior
-rw-r--r--spec/ruby/core/struct/new_spec.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb
index bb814e7..cbbec82 100644
--- a/spec/ruby/core/struct/new_spec.rb
+++ b/spec/ruby/core/struct/new_spec.rb
@@ -127,15 +127,30 @@ describe "Struct.new" do
-> { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
end
- it "passes a hash as a normal argument" do
- type = Struct.new(:args)
+ ruby_version_is ''...'3.1' do
+ it "passes a hash as a normal argument" do
+ type = Struct.new(:args)
- obj = type.new(keyword: :arg)
- obj2 = type.new(*[{keyword: :arg}])
+ obj = suppress_warning {type.new(keyword: :arg)}
+ obj2 = type.new(*[{keyword: :arg}])
- obj.should == obj2
- obj.args.should == {keyword: :arg}
- obj2.args.should == {keyword: :arg}
+ obj.should == obj2
+ obj.args.should == {keyword: :arg}
+ obj2.args.should == {keyword: :arg}
+ end
+ end
+
+ ruby_version_is '3.2' do
+ it "accepts keyword arguments to initialize" do
+ type = Struct.new(:args)
+
+ obj = type.new(args: 42)
+ obj2 = type.new(42)
+
+ obj.should == obj2
+ obj.args.should == 42
+ obj2.args.should == 42
+ end
end
end