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
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.
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With