Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groups in a Gemfile in Rails 3?

In my Gemfile in Rails I have these groups:

group :development, :test do   gem "capybara"   gem "database_cleaner"   gem "spork"   gem "launchy" end  group :bdd do   gem "cucumber-rails"   gem "rspec-rails" end 

What does this mean?

like image 642
never_had_a_name Avatar asked Sep 05 '10 12:09

never_had_a_name


People also ask

What are groups in Gemfile?

Since version 0.9, Bundler has had a feature called "groups". The purpose of this feature is to allow you to specify groups of dependencies which may be used in certain situations, but not in others. Specifying groups allows you to do two things. First, you can install the gems in your Gemfile, minus specific groups.

What is require in Gemfile?

Whenever you specify a Gem in your Gemfile and run bundle install , bundler will go and install specified gem and load code for that Gem in you app by putting require 'whenever' this way bundler will load code for all of your Gems in your Rails app, and you can call any method from any Gem without any pain, like you do ...

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

What is Gemfile in Ruby on Rails?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


2 Answers

From http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/:

Specifying groups allows you to do two things. First, you can install the gems in your Gemfile, minus specific groups. For instance, Rails puts mysql and pg in a database group so that if you’re just working on ActionPack, you can bundle install --without db and run the ActionPack tests without having to worry about getting the gems installed.

Second, you can list specific groups to autorequire using Bundler.require. By default, Bundler.require requires all the gems in the default group (which is all the gems that have no explicit group). You can also say Bundler.require(:default, :another_group) to require specific groups.

like image 79
David Lyod Avatar answered Oct 05 '22 23:10

David Lyod


Grouping your dependencies allows you to perform operations on the entire group. See: http://gembundler.com/v1.3/groups.html

like image 26
Ben Flynn Avatar answered Oct 05 '22 22:10

Ben Flynn