2017-08-14 31 views
1

我試圖在Jenkinsfile中運行ruby spec測試。
但是執行此代碼時,我遇到了問題:在Jenkins上運行時找不到gem rspec-core(> = 0.a)(Gem :: GemNotFoundException)

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/[email protected]/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實例運行詹金斯。 gem rspec-core肯定是安裝的,因爲我在運行spec測試之前進行了bundle安裝。我也運行了與實例本身相同的測試,而不是詹金斯,它的工作原理。 當我在詹金斯運行gem which rspec,它給了我這個錯誤:

ERROR: Can't find ruby library file or shared library rspec

但是,當我在實例上運行它,它會返回
/home/user/.rvm/gems/[email protected]/gems/rspec-3.6.0/lib/rspec.rb

兩個正在使用的全球寶石。 可能是什麼問題?

回答

1

我設法用

sh 'bundle exec rake spec:unit'

它使用耙文件,而不是運行單獨的測試本身,這是更清潔和明確的運行規範測試。

這是Rake文件的樣子:

namespace :spec do 
    RSpec::Core::RakeTask.new(:unit) do |t|` 
     t.pattern = 'spec/unit/**/*_spec.rb' 
    end 
end 

task default: ['spec:unit'] 

其中運行所有的單元測試。

+0

儘管沒有使用Jenkins,但這對我很有用,因爲相關位是您的答案是使用「bundle exec''。 –

相關問題