I am trying to run ruby spec tests in a Jenkinsfile.
However I have run into problems when executing this code:
sh 'rspec spec/unit/test_spec.rb'
This is the error:
/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 ''
I am running Jenkins on an EC2 instance. The gem rspec-core is definitely installed, as I do a bundle install before running the spec test. I have also run the exact same test as the one on the instance itself instead of Jenkins and it works.
When I run gem which rspec
on Jenkins, it gives me this error:
ERROR: Can't find ruby library file or shared library rspec
But when I run it on the instance, it returns
/home/user/.rvm/gems/ruby-2.4.0@global/gems/rspec-3.6.0/lib/rspec.rb
Both are using the global gemset. What could be the problem?