mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
bf04aaa068
Most of this was fixed by adding the `attribute-defined-statically-cop` branch of `thoughtbot/rubocop-rspec` to the Gemfile and running: ```sh rubocop \ --require rubocop-rspec \ --only FactoryBot/AttributeDefinedStatically \ --auto-correct ``` I had to update the cucumber tests manually, and I realized our changes don't handle `ignore` blocks or blocks with arity 1 that use the yielded DefinitionProxy. I will update https://github.com/rubocop-hq/rubocop-rspec/pull/666to handle these cases.
31 lines
875 B
Ruby
31 lines
875 B
Ruby
describe "finding factories keyed by class instead of symbol" do
|
|
before do
|
|
define_model("User") do
|
|
attr_accessor :name, :email
|
|
end
|
|
|
|
FactoryBot.define do
|
|
factory :user do
|
|
name { "John Doe" }
|
|
sequence(:email) { |n| "person#{n}@example.com" }
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when deprecated class lookup if allowed", :silence_deprecation do
|
|
it "allows interaction based on class name" do
|
|
user = FactoryBot.create User, email: "person@example.com"
|
|
expect(user.email).to eq "person@example.com"
|
|
expect(user.name).to eq "John Doe"
|
|
end
|
|
end
|
|
|
|
context "when class lookup is disallowed" do
|
|
it "doesn't find the factory" do
|
|
FactoryBot.allow_class_lookup = false
|
|
expect { FactoryBot.create(User) }.to(
|
|
raise_error(ArgumentError, "Factory not registered: User"),
|
|
)
|
|
end
|
|
end
|
|
end
|