Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby 3.1: Add spec for StructClass#keyword_init? #953

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/struct/keyword_init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'

ruby_version_is "3.1" do
# See https://bugs.ruby-lang.org/issues/18008
describe "StructClass#keyword_init?" do
it "returns true for a struct that accepts keyword arguments to initialize" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is maybe a bit verbose but i borrowed it from Struct's new_spec.rb for the sake of consistency. Open to make it shorter if requested.

struct = Struct.new(:arg, keyword_init: true)
struct.keyword_init?.should be_true
end

it "returns false for a struct that does not accept keyword arguments to initialize" do
struct = Struct.new(:arg, keyword_init: false)
struct.keyword_init?.should be_false
end

it "returns nil for a struct that did not explicitly specify keyword_init" do
struct = Struct.new(:arg)
struct.keyword_init?.should be_nil
end
end
end