Factory_Girl + RSpec: undefined method 'create' when create(:user)
You need to move the create
line inside of the spec it's being used in:
it 'should have a single registered user.' do
dummy = create(:user)
expect(User.count).to eq(1)
end
Right now, that line is without context (not in a spec and not in a before
block). That is probably why you're getting the error. You probably have all the setup correct, but just have one line in the wrong place.
Another reason for getting the undefined method 'create'
error could be that you're missing this piece of configuration in spec/support/factory_girl.rb
:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
I found that code here.