Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Cucumber and Factory Girl together?

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!

like image 513
Yuval Karmi Avatar asked Dec 23 '10 11:12

Yuval Karmi


2 Answers

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"

like image 129
Jinesh Parekh Avatar answered Sep 20 '22 23:09

Jinesh Parekh


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!!

like image 36
Peter Ehrlich Avatar answered Sep 22 '22 23:09

Peter Ehrlich