简体   繁体   中英

How to set up Factory Girl related configuration to be used by both RSpec and cucumber in Rails 3.2

How do I set up Factory Girl related configuration to be used by both RSpec and cucumber in Rails 3.2?

The configuration is something like

FactoryGirl.aliases = [
  [/([^(?:address)].+)_id/, '\1'],
  [/([^(?:address)].*)/, '\1_id'],
]

I tried putting it in spec/support/factory_girl.rb , and that worked fine if I'm running RSpec tests, but it doesn't get run if I'm running cucumber tests instead.

I'm considering putting it in config/environments/test.rb but it's not configuring Rails itself.

Cucumber's setup isn't very well documented, but it loads a features/support/env.rb file first and then all other Ruby files in features/support . So you could add a require statement in features/support/env.rb to load spec/support/factory_girl.rb , or have a similar initialiser in features/support . And, given that it's shared code that sets up the test environment, I don't think it would be terrible to put it in config/environments/test.rb either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM