Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber and Rspec sharing factory girl factories

I'm designing a test around rails using Cucumber and Rspec and I was wondering if it is good practice sharing the Factory Girl factory code between the Cucumber acceptance test and Rspec unit tests.

And if it is good practice where would be the best place neutral location to place the factories for rspec and cucumber.

Thanks a lot

like image 325
GTDev Avatar asked Sep 16 '11 06:09

GTDev


2 Answers

You can use factories anywhere you like. I generally use them in rspec and my Cucumber stories.

Factories are fixture replacements. General idea is to be able to right readable tests and move away from the "fixtures" hell scenario.

I think its fine if you place in spec/factories , there is no standard location. But I generally place it in my spec folder. No need to use a separate neutral location for it.

like image 188
Rishav Rastogi Avatar answered Oct 21 '22 17:10

Rishav Rastogi


Yes, it is a good practice to not repeat the same factory definitions (if they are shared... which I would content there SHOULD be some overlap). One way to do this is to create a new directory in your project called factories and then add the following to your rspec and cucumber configurations:

/features/support/app.rb
    Dir[Rails.root.join("factories/**/*.rb")].each {|f| require f}

/spec/spec_help.rb
    Dir[Rails.root.join("factories/**/*.rb")].each {|f| require f}
like image 20
Mainguy Avatar answered Oct 21 '22 16:10

Mainguy