2014-07-26 51 views
0

我試圖運行鍼對包含的Hello文件中的hello方法測試:`要求:不能加載這樣的文件 - 你好(LoadError)

ruby hello_spec.rb 

返回:

/usr/local/Cellar/ruby/2.1.2_2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- hello (LoadError) 
from /usr/local/Cellar/ruby/2.1.2_2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
from hello_spec.rb:116:in `<main>' 

這些文件包含在同一個目錄中。我已經安裝了RSpec和(我相信)必要的寶石。其他人似乎也有類似的問題,但沒有解決方案爲我工作。

我正在運行Ruby 2.1.2 我是Ruby的新手,我正在努力(顯然)正確配置環境。任何幫助深表感謝。

注:我沒有寫任何測試代碼。我真的只做了hello.rb文件。

+0

嘗試「加載」命令而不是「要求」? 加載'hello_spec.rb' 需要加載文件只有一次在紅寶石。 包含在「加載」ruby源文件中。 –

+0

從REPL內部?我得到同樣的東西。 – smth

+0

tr load'./hello_spec.rb' –

回答

0

在您的hello_spec.rb中將require 'hello'更改爲require_relative 'hello'。默認情況下,當前目錄不包含在默認的ruby加載路徑中。

,或者,增加當前目錄,紅寶石負載路徑:

$:.unshift File.dirname(__FILE__) 

希望它能幫助。

+0

Huzzah,作品。謝謝。 – smth

相關問題