Skip to content

Commit

Permalink
Upcoming Struct#new behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jan 18, 2021
1 parent a3851d9 commit c3d6bac
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions spec/ruby/core/struct/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,30 @@ def platform
-> { 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

Expand Down

0 comments on commit c3d6bac

Please sign in to comment.