File: attributes_for_destructuring.rb

package info (click to toggle)
ruby-factory-bot 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: ruby: 7,827; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
    # rubocop:disable Lint/Syntax
    attributes_for(:user) => {name:, **attributes}
    # rubocop:enable Lint/Syntax

    expect(name).to eq("John Doe")
    expect(attributes.keys).to eq([:email])
    expect(attributes.fetch(:email)).to match(/email_\d+@example.com/)
  end
end