我正在尝试在 Jenkinsfile 中运行 ruby 规范测试。
但是我在执行这段代码时遇到了问题:
sh 'rspec spec/unit/test_spec.rb'
这是错误:
/home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in 'find_spec_for_exe': can't find gem rake (>= 0.a) (Gem::GemNotFoundException) from /home/user/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in 'activate_bin_path' from /home/user/.rvm/gems/ruby-2.4.0@global/bin/rake:23:in '' from /home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in eval' from /home/user/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in ''
我在 EC2 实例上运行 Jenkins。肯定安装了 gem rspec-core,因为我在运行规范测试之前进行了捆绑安装。我还运行了与实例本身而不是 Jenkins 上的测试完全相同的测试并且它有效。
当我在 Jenkins 上运行 gem which rspec
时,它给了我这个错误:
ERROR: Can't find ruby library file or shared library rspec
但是当我在实例上运行它时,它返回
/home/user/.rvm/gems/ruby-2.4.0@global/gems/rspec-3.6.0/lib/rspec.rb
两者都在使用全局 gemset。 可能是什么问题?
最佳答案
我设法通过使用
运行规范测试sh 'bundle exec rake spec:unit'
它使用 rake 文件而不是运行单独的测试本身,这样更加清晰明了。
这是 rakefile 的样子:
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |t|`
t.pattern = 'spec/unit/**/*_spec.rb'
end
end
task default: ['spec:unit']
它运行所有单元测试。
关于ruby - 在 Jenkins 上运行时找不到 gem rspec-core (>= 0.a) (Gem::GemNotFoundException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673087/