Factory.next not working in FactoryGirl 4.x and Rails 3.0. Anyone know the replacement?

Posted by cchapman900 on Stack Overflow See other posts from Stack Overflow or by cchapman900
Published on 2012-11-27T05:01:33Z Indexed on 2012/11/27 5:03 UTC
Read the original article Hit count: 326

I'm very new to Rails and am following along in the Ruby on Rails 3 Tutorial book by Michael Hartl and am running into a little bump while using the factory_girl gem.

Specifically, I'm not sure how to update the code

Factory.next(...)

Before coming to this, I did run into a little problem between the older version of FactoryGirl used in the book and the current 4.1 version I'm using now, but was able to resolve it.

Specifically, the old way of writing code as

user = Factory(:user)

needed to be updated to

user = FactoryGirl.create(:user)

That was fine, but now I'm coming to the code (as written in the book):

spec/controllers/users_controler_spec.rb

.    
@users << Factory(:user, :email => Factory.next(:email))
.

which I've tried updating to

.
@users << FactoryGirl.create(:user, :email => FactoryGirl.next(:email))
.

but get the error:

Failure/Error: @users << FactoryGirl.create(:user, :email => FactoryGirl.next(:email))
 NoMethodError:
   undefined method `next' for FactoryGirl:Module

I've tried a few different variations but still can't quite get it. Is the problem I'm having with FactoryGirl and just not using the gem correctly or does it have something to do with the Ruby methods?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3.2