-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document integration with 2.7 and 3.0 syntactic sugars
Ruby 2.7 introduced [numbered block parameters][], and 3.0 introduced [Hash literal value omission][], so document how they integrate with Factory Bot. [numbered block parameters]: https://ruby-doc.org/core-2.7.1/Proc.html#class-Proc-label-Numbered+parameters [Hash literal value omission]: https://docs.ruby-lang.org/en/3.1/syntax/literals_rdoc.html#label-Hash+Literals
- Loading branch information
1 parent
3585b46
commit d391321
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
describe "Ruby 3.0: attributes_for destructuring syntax" do | ||
include FactoryBot::Syntax::Methods | ||
|
||
before do | ||
define_model("User", name: :string) | ||
|
||
FactoryBot.define do | ||
factory :user do | ||
sequence(:email) { "email_#{_1}@example.com" } | ||
name { "John Doe" } | ||
end | ||
end | ||
end | ||
|
||
it "supports being destructured" do | ||
attributes_for(:user) => {name:, **attributes} | ||
|
||
expect(name).to eq("John Doe") | ||
expect(attributes.keys).to eq([:email]) | ||
expect(attributes.fetch(:email)).to match(/email_\d+@example.com/) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters