How to create a Gemfile?

RubyRspec

Ruby Problem Overview


I'm very new to Ruby.

I was following a blog post that says that in order to install a required dependencies I need to create a Gemfile.

How do I create a Gemfile with rspec as a dependency?

Ruby Solutions


Solution 1 - Ruby

bundle init generates a Gemfile into the current working directory.

$ bundle init
Writing new Gemfile to /app/Gemfile

$ cat Gemfile 
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"

Solution 2 - Ruby

The Gemfile is just a text file within your project which contains a list of gems for use in your application.

If you do not have one in your application, you can create the file using an editor of your choice, saving it as Gemfile (with no extension), and in your example, containing:

source 'https://rubygems.org'
    
gem 'rspec'

Solution 3 - Ruby

A gemfile is automatically created when you start a new rails application.

type rails new appName and then it will be generated automatically. It will also be populated with some gems.

To install the gems run bundle install or simply bundle

Make sure you are requiring the gems you need. specifically rspec and jruby

group :development, :test do
  gem 'rspec-rails', '~> 3.0'
end

Look at this website for more information

http://bundler.io/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaurabh JunejaView Question on Stackoverflow
Solution 1 - RubyAndy WaiteView Answer on Stackoverflow
Solution 2 - RubyCDubView Answer on Stackoverflow
Solution 3 - RubyRichard HamiltonView Answer on Stackoverflow