Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use development vs testing group in gemfile for testing gems?

For some reason this hasn't hit home, and I'm wondering if someone could help explain..

I noticed when installing 'guard' gem, that they recommend placing a lot of the gems in the 'development group' in the gemfile, such as 'growl' and 'rb-notifu': https://github.com/guard/guard..

Also Ryan Bates seems in one screen cast seems to put many of these in 'development' & 'testing': http://railscasts.com/episodes/264-guard?view=asciicast

But in another puts it all in 'testing': http://railscasts.com/episodes/275-how-i-test

It'd be nice to understand this so I don't have to reference tutorials all the time. Thanks!

like image 890
Inc1982 Avatar asked Jan 30 '12 12:01

Inc1982


People also ask

What are groups in gem file?

We see there are two groups (:development and :test) added to our Gemfile. This helps us in installing gems only for specific environments. Gems installed in the development group will only be available in the development environment and the same goes for the rest.

How do I set gem version in Gemfile?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

What is require false in Gemfile?

You use :require => false when you want the gem to be installed but not "required". So in the example you gave: gem 'whenever', :require => false when someone runs bundle install the whenever gem would be installed as with gem install whenever .

What is RubyGems How does it work?

The RubyGems software allows you to easily download, install, and use ruby software packages on your system. The software package is called a “gem” which contains a packaged Ruby application or library. Gems can be used to extend or modify functionality in Ruby applications.


1 Answers

Gems that you run from the development environment should be present in both the development and test groups. You run things like rspec cucumber and guard from development and they run in the test environment, you need them in development to run the rake tasks and the executables.

Gems that only run while in test mode, such as capybara email_spec and launchy can exist only in the test group and still function correctly.

I hope this helps clear things up.

As a general rule, gems that are executable need to be in both. Also, if you are unsure, put it in both groups too.

Edit

If the gem you are using has generators (rails generate), it needs to be present in both test and development.

like image 172
Gazler Avatar answered Nov 15 '22 16:11

Gazler