How to use cucumber and factory girl together?

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

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

When I run the "cucumber function", there is no problem. Now I add a file called teacher.rb to spec/factories and add the following:

 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 obviously missed something, but what is it? How to get a cucumber to work with Factory Girl?

Thanks!

+8
ruby-on-rails-3 integration-testing cucumber factory-bot
source share
3 answers

Make sure these steps are enabled. They worked flawlessly for me.

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

Basically you should require "factory_girl / step_definitions"

+12
source share

I'm just going to repeat what Dan Crook said, as it can be incredibly frustrating. (Even the factory_girl_rails plugin points to the wrong file.) Instead, you should follow the syntax:

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

Thanks Dan !!

+4
source share

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

0
source share

Source: https://habr.com/ru/post/650406/


All Articles