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

Upgrading to 5.0.0 breaks all RSpec tests #315

Closed
colinwarmstrong opened this issue Feb 1, 2019 · 7 comments
Closed

Upgrading to 5.0.0 breaks all RSpec tests #315

colinwarmstrong opened this issue Feb 1, 2019 · 7 comments

Comments

@colinwarmstrong
Copy link

colinwarmstrong commented Feb 1, 2019

After upgrading to 5.0.0, I receive the following error for all of my RSpec spec files:

An error occurred while loading ./spec/*/*_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', __FILE__)

RuntimeError:
  can't modify frozen Array
# ./config/initializers/apartment.rb:102:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `<top (required)>'

Downgrading solves the issue, not sure what exactly is going on.

@composerinteralia
Copy link
Collaborator

That may be related to #303.
Do you get a different error if you run just one test at a time?

@kofronpi
Copy link

kofronpi commented Feb 6, 2019

Same here. I (finally) did the upgrade process from factory_girl to factory_bot, it upgraded factory_bot to 5.0.0 and I have the same issue. I'm trying downgrading it a bit

@composerinteralia
Copy link
Collaborator

@kofronpi if you are coming from factory_girl I would recommend upgrading to factory_bot 4.11.1 first so you can catch any deprecation warnings.

@kofronpi
Copy link

kofronpi commented Feb 6, 2019 via email

@composerinteralia
Copy link
Collaborator

OK, if you do plan on upgrading later, my experience with that Frozen Array issue is that if you run just a single test you will get the "real" error message. I once traced through why we end up with a Frozen Array error instead of the underlying factory_bot error, if that helps at all: #303 (comment)

@colinwarmstrong
Copy link
Author

colinwarmstrong commented Feb 6, 2019

Ended up going back this morning to try and figure out the issue when upgrading.

So I ran an individual test like you suggested and got the "real" error message I was looking for:

NoMethodError:
  undefined method 'name' in 'award' factory

Apparently in the newest version of FactoryBot, factory attribute values must be defined using bracket notation like so:

FactoryBot.define do
  factory :award do
    name { 'Teamwork' }
  end
end

Without the brackets, you get an undefined method error for your attribute names. When you get multiple errors of this kind happening, it triggers a Frozen Array error instead.

So using the curly-bracket notation in all of my factories allowed me to run all my tests again without issues.


Also I was just reading through some of the FactoryBot docs and came across this:

Static attributes, without a block, are deprecated and will be removed in factory_bot 5.

So it makes sense that I was getting an error.

@composerinteralia
Copy link
Collaborator

composerinteralia commented Feb 6, 2019

Yup, static attributes were deprecated in 4.11 and then removed in 5.0 (you can read this blog post for more details on why). The deprecation warning in 4.11 mentions a rubocop-rspec cop that can help change all the static attributes to dynamic ones. Let me know if you run into any other problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants