2

I'm making an integration tests with cucumber in rails i already have all my scenarios working fine, but i need that the seeds on my db/seed.rb file running before all scenarios start to running,

i tried add this in my support/env.rb: require File.dirname(__FILE__) + '/seeds'

but does'n work.

how can i do this?

Thanks !

ljrzarate
  • 21
  • 2

2 Answers2

4

There are various thoughts on if you should or should not use seeds for this.

I want to know if each discrete scenario works or does not work, with no interplay between them. This can make the suite take longer, but provides confidence in your testing that another scenario did not cause a chain reaction. Therefore, I choose to use seeds for this.

I have a support/seeds.rb with contents:

Before do |scenario|
  load Rails.root.join('db/seeds.rb')
end

Note, you might want to combine this with something like:

begin
  # start off entire run with with a full truncation
  #  DatabaseCleaner.clean_with :truncation, {:except => %w[plans]}
  DatabaseCleaner.clean_with :truncation
  # continue with the :transaction strategy to be faster while running tests.
  DatabaseCleaner.strategy = :transaction
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
kross
  • 3,627
  • 2
  • 32
  • 60
0

Adding require_relative '../../db/seeds' in features/support/env.rb works.

Emil
  • 1,240
  • 1
  • 15
  • 27