2015-04-06 83 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