88

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?

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Saurabh Juneja
  • 1,187
  • 1
  • 8
  • 12

3 Answers3

177

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"
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Andy Waite
  • 10,785
  • 4
  • 33
  • 47
68

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'
Jigarius
  • 394
  • 3
  • 16
CDub
  • 13,146
  • 4
  • 51
  • 68
  • 1
    I took so long to realize that all I need was to create a file named "Gemfile" with no extension. I thought I was creating a gem at this point. – Machado May 22 '17 at 14:32
0

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/

Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87