2015-04-06 86 views
4

我正在尝试设置Travis CI,但是ruby并不按我期望的方式工作。为什么红宝石(在特拉维斯CI)找到我的宝石安装宝石?

它看起来像特拉维斯CI正确运行我的软件包安装,但红宝石宝石之后不能立即发现红宝石。这里的特拉维斯日志:

$ ruby --version 
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-darwin13.1.0] 
$ rvm --version 
rvm 1.25.33 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/] 
$ bundle --version 
Bundler version 1.7.4 

[... snip ...] 


$ bundle install --jobs=3 --retry=3 --deployment 
Fetching gem metadata from https://rubygems.org/......... 
Fetching additional metadata from https://rubygems.org/.. 
Installing colorize 0.7.2 
Installing json 1.8.1 
Using bundler 1.7.4 
Installing dnssd 2.0 
Your bundle is complete! 
It was installed into ./vendor/bundle 
$ cat Gemfile.lock 
GEM 
    remote: https://rubygems.org/ 
    specs: 
    colorize (0.7.2) 
    dnssd (2.0) 
    json (1.8.1) 
PLATFORMS 
    ruby 
DEPENDENCIES 
    colorize 
    dnssd 
    json 
The command "cat Gemfile.lock" exited with 0. 
$ ruby -e "require 'colorize'" 
/Users/travis/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- colorize (LoadError) 
    from /Users/travis/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from -e:1:in `<main>' 
The command "ruby -e "require 'colorize'"" exited with 1. 
Done. Your build exited with 1. 

.travis.yml文件很简单,现在:

language: objective-c 
script: 
    - cat Gemfile.lock 
    - bundle env 
    - ruby -e "require 'colorize'" 

我认为我做一个简单的错误(可能是一个纯Ruby的错误),但我不能看见。我在这里做错了什么?

+0

Bundler不会让东西神奇地可用;你需要在你的脚本中需要'bundler/setup'来让Bundler设置你的加载路径。 –

+0

这是有道理的,但现在我想知道我的本地机器上发生了什么,使它在那里工作。难道是'gem install'与'bundle install'不同吗? – Ian

+0

'gem install'与'bundle install'不同,是的。 –

回答

5

Bundler不会让东西神奇地可用;您需要在脚本中使用require 'bundler/setup'以使Bundler设置您的加载路径。

Bundler会将你的宝石安装到你想要的任何路径,但这些宝石不一定会在你的Ruby加载路径中,所以require不一定会找到它们。在使用任何其他宝石之前,您可以让Bundler通过require 'bundler/setup'更改加载路径以指向已安装的软件包的宝石。这确实要求捆绑器已经在您的载入路径中可用,这通常通过gem install bundler完成。特拉维斯预装了它,所以你不需要做任何特殊的事情来使用它。

+0

您的编辑预计评论我即将离开:)谢谢 – Ian

+0

这工作! 'sudo gem update --system'和本地运行'bundle install --deployment'也有帮助。 – Ian