everydayrails / rails-4-1-rspec-3-0

Code samples for Everyday Rails Testing with RSpec, Rails 4.1/RSpec 3.0 edition
272 stars 229 forks source link

Where to place `gem "factory_girl_rails"` in Gemfile #64

Closed tenzan closed 9 years ago

tenzan commented 9 years ago

Hello!

gem "factory_girl_rails" placed within group:development,:test.

Why it's not in the group:test?

Thanks.

ruralocity commented 9 years ago

Hi, it's so when you've set FactoryGirl to replace fixtures (in config/application.rb), you can run it from the command line in your default development environment. If you'd prefer to create those files manually (and not include g.fixture_replacement ... in config/application.rb), you might be able to only include it in :test, but I'm not certain. If you try it, let me know what you find out!

tenzan commented 9 years ago

Thanks for quick reply, Aaron!

I brought up this question because I'm also reading Rails 4 in Action these days. In that book, they placed this gem in the group:test, this is why I wondered.

What's the general practice? I'm just starting reading your book, will we run factory_girls from the command line at some point?

ruralocity commented 9 years ago

I haven't seen the Rails 4 version of that book ... do they have g.fixture_replacement :factory_girl set in config/application.rb? That's how I've always done it ... not sure if there's a set general practice for this.

tenzan commented 9 years ago

The book is http://www.manning.com/bigg2/ Repo https://github.com/rubysherpas/r4ia_examples/tree/master/ticketee

Nothing mentioned about factory_girl in their config/application.rb.

ruralocity commented 9 years ago

Ryan may be creating factories by hand instead of using a Rails generator to create them. Both ways are perfectly fine. If you do want to have Rails generate starter factory files for you, though, you'll have to include factory_girl_rails in the development group of your Gemfile.

tenzan commented 9 years ago

Thanks, I understood now. :)