如何创建 Gemfile?

How to create a Gemfile?

我对 Ruby 很陌生。

我正在关注一个博客 post,该博客说为了安装所需的依赖项,我需要创建一个 Gemfile。

我如何创建一个 Gemfile 以 rspec 作为依赖项?

启动新的 rails 应用程序时会自动创建一个 gemfile。

输入rails new appName然后会自动生成。它还会填充一些宝石。

安装 gem 运行 bundle install 或简单地 bundle

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

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

查看此网站了解更多信息

http://bundler.io/

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

如果您的应用程序中没有,您可以使用您选择的编辑器创建该文件,将其另存为 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"