如何创建一个 Gemfile?

我对露比很陌生。

我跟随一篇博客文章说,为了安装所需的依赖项,我需要创建一个 Gemfile。

如何创建一个 Gemfile 与 rspec作为一个依赖?

65220 次浏览

当您启动一个新的 Rails 应用程序时,将自动创建一个 gemfile。

键入 rails new appName,然后它将自动生成。它也将填充一些 gems。

要安装 gem,请运行 bundle install或者简单地运行 bundle

确保你需要的宝石你需要。特别是 rspecjruby

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

更多信息请访问这个网站

Http://bundler.io/

Gemfile 只是项目中的一个文本文件,其中包含了一系列在应用程序中使用的 gems。

如果应用程序中没有,可以使用自己选择的编辑器创建文件,将其保存为 Gemfile(没有扩展名) ,并在示例中包含:

source 'https://rubygems.org'


gem 'rspec'

Bundle init 在当前工作目录中生成一个 Gemfile。

$ 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"