Cucumbers and rspec share factory girls factory

I am developing a test around rails using Cucumber and Rspec, and I was wondering if there is good practice exchanging Factory Girl Factory code between the Cucumber acceptance test and the Rspec unit tests.

And if it's good practice, where would it be an ideal place for a neutral placement of factories for rspec and cucumbers.

thanks a lot

+6
source share
2 answers

You can use factories anywhere. I usually use them in rspec and my cucumber stories.

Factories replace fittings. The general idea is to be able to read readable tests and move away from the β€œartifacts” poster script.

I think this is great if you put in spec / factory, there is no standard location. But I usually place it in the specification folder. No need to use a separate neutral place for this.

+5
source

Yes, it is good practice not to repeat the same factory definitions (if they are separated ... which I would contain there MUST be partially overlapped). One way to do this is to create a new directory in your project called "factories", and then add the following parameters in the rspec and oucumber configuration:

/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} 
+1
source

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


All Articles