Cucumber and Rspec sharing factory girl factories
Asked Answered
B

2

6

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

Buttonhole answered 16/9, 2011 at 6:38 Comment(0)
M
5

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.

Massengale answered 16/9, 2011 at 7:44 Comment(1)
Thanks will leave it in spec directory. Was mainly wondering if I needed another factory.rbButtonhole
R
1

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}
Reforest answered 30/8, 2012 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.