2

A lot of times, when I use FactoryGirl in my specs, I keep receiving errors like:

Failure/Error: f = FactoryGirl.build(:my_model)
     ActiveRecord::RecordInvalid:
       translation missing: de.activerecord.errors.messages.record_invalid

Now, if I start a console in test mode, I get a record back, and I don't get any errors. How should I proceed with this?

EDIT: I was missing the translation and did not see the relevant message. After I switched to a :en locale, the errors were clear.

Geo
  • 93,257
  • 117
  • 344
  • 520

1 Answers1

1

Probably you can't build your model, because it requires some parameters during initialization. Use initialize_with:

factory :user do
  name "John Doe"

  initialize_with { new(name) }
end

Look at https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#custom-construction for details

denis.peplin
  • 9,585
  • 3
  • 48
  • 55