我正在尝试使用 Circleci 进行持续集成并遇到问题。我正在使用 ruby 2.2.2 和 rspec 部署一个 rails 4 应用程序。
当我尝试通过 circleci 推送我的第一个构建时,当它尝试在我的"spec_helper"中的代码行上运行我的测试套件时,我会收到错误,我需要条纹宝石。我在应用程序中使用条纹并使用"条纹模拟"对其进行测试
错误如下。所以失败是我在spec_helper require "stripe"
的路线。需要明确的是,rspec 在本地运行和传递,但我在 circleci 上收到此错误。我仔细检查了一下,我把我所有的环境变量都设置在了 circleci 上。我听说有时 gem 需要在 circleci 上设置二进制文件才能工作。这也许是问题所在吗?我该怎么做?
rspec
/home/ubuntu/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- stripe (LoadError)
from /home/ubuntu/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/propel/spec/spec_helper.rb:20:in `block in <top (required)>'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core.rb:97:in `configure'
from /home/ubuntu/propel/spec/spec_helper.rb:18:in `<top (required)>'
from /home/ubuntu/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `block in requires='
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `each'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `requires='
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `each'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:21:in `configure'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:101:in `setup'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/bin/rspec:23:in `load'
from /home/ubuntu/.rvm/gems/ruby-2.2.2@global/bin/rspec:23:in `<main>' rspec returned exit code 1
我还应该注意,我的 gemfile 中确实有条纹,您可以在此处看到:
gem 'stripe'
你可以在这里看到我的 rspec spec_helper中需要条纹的地方:
RSpec.configure do |config|
require 'stripe'
require 'stripe_mock'
require 'thin'
尽管我的 gemfile 中有条纹,但我决定尝试将sudo gem install stripe
添加到我的 circle.yml
文件中,以确保它包含在测试中,但出现以下错误:
sudo gem install stripe
ERROR: Error installing stripe:
sudo gem install stripe returned exit code 1
mime-types requires Ruby version >= 1.9.2. Action failed: sudo gem install stripe
即使我在 circle.yml 文件中将 ruby 版本指定为 2.2.2 也是如此
与其将sudo gem install stripe
添加到circle.yml
文件中,不如将gem stripe
添加到Gemfile
中。
CircleCI文档说:
你很可能会有一个应用所需的库和依赖项列表。CircleCI自动检测Ruby的Gemfile,...然后运行相应的命令来安装依赖项。
如果您还没有Gemfile
,您可以:
- 运行
gem install bundler
. -
创建一个
Gemfile
,列出应用程序需要运行的 Rubygems,包括stripe
。它应该看起来像这样:source "https://rubygems.org" gem "stripe"
-
运行
bundle
命令。这应该会创建一个Gemfile.lock
文件,列出您使用的相互兼容的特定 Gem 版本。 - 将机器人
Gemfile
和Gemfile.lock
提交到版本控制系统。
Bundler 网站提供了更多关于 Gemfiles 的信息。