How to use Cucumber and Factory Girl together?
Asked Answered
O

3

8

I'm trying to configure FactoryGirl to work with my Cucumber tests. I added the following lines in env.rb

require 'factory_girl'
Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }

When I run 'cucumber features', there's no problem. I now add a file called teacher.rb to spec/factories and add the following in:

FactoryGirl.define do
  factory :teacher do
    first_name "John"
    last_name "Smith"
  end
end

Now when I run cucumber features I get: uninitialized constant FactoryGirl (NameError)

I'm obviously missing something, but what is it? How do I get Cucumber to work with Factory Girl?

Thanks!

Omphalos answered 23/12, 2010 at 11:12 Comment(1)
You're trying to follow documentation for an unreleased version of Factory Girl. Take a look at the docs for the most recent version here: rdoc.info/gems/factory_girl/1.3.3/framesDicrotic
T
11

Make sure you have these steps covered. They worked for me flawlessly.

http://collectiveidea.com/blog/archives/2010/09/09/practical-cucumber-factory-girl-steps/

Mainly you have to require "factory_girl/step_definitions"

Tague answered 23/12, 2010 at 11:15 Comment(1)
Old integration is now deprecated, read this article for more information. robots.thoughtbot.com/…Responsiveness
A
4

I'm just going to repeat what Dan Croak said, as it can be incredibly frustrating. (Even the factory_girl_rails plugin points to the wrong file.) You need to follow the syntax here, instead:

https://github.com/thoughtbot/factory_girl/tree/1.3.x

Thanks Dan!!

Antiscorbutic answered 5/2, 2011 at 4:6 Comment(0)
E
0

I had the same problem with cucumber in rails4. Running rake cucumber features instead of just cucumber features solved the problem.

Endometrium answered 27/10, 2013 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.