我正在尝试在ruby文件上运行rake,我应该收到错误,所以我可以调试它作为练习。然而,我得到的错误不是我应该收到的错误。我收到以下内容,我有时间解释我需要解决的问题。
~Desktop/learn_ruby-master/00_hello$ rake
(in /~Desktop/learn_ruby-master)
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- hello (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ~Desktop/learn_ruby-master/00_hello/hello_spec.rb:117:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
rake aborted!
/usr/bin/ruby1.9.1 -S rspec ~Desktop/learn_ruby-master/00_hello/hello_spec.rb - I/~Desktop/learn_ruby-master/00_hello -I/~Desktop/learn_ruby-master/00_hello/solution -f documentation -r ./rspec_config failed
Tasks: TOP => default => spec
( See full trace by running task with --trace)
这是我正在运行的代码
require "hello"
describe "the hello function" do
it "says hello" do
hello.should == "Hello!"
end
end
describe "the greet function" do
it "says hello to someone" do
greet("Alice").should == "Hello, Alice!"
end
it "says hello to someone else" do
greet("Bob").should == "Hello, Bob!"
end
end
答案 0 :(得分:2)
我遇到了同样的问题(通过完全相同的教程)。我只花了三天时间试图解决这个问题。问题是我的'hello.rb'路径中的一个文件夹在两个单词之间有一个空格。说真的,就是这样。无论我做了什么(除了改变空间),红宝石路径都无法捡起它。 Uggh。经验教训,不要在任何地方命名任何东西,从这里开始有空间。
答案 1 :(得分:1)
Ruby说的一切:“在库加载路径上找不到文件名hello.rb”。你缺少hello.rb文件或Ruby无法找到它。你真的把它放在你运行rake的目录中的光盘上吗?如果它在其他地方你需要提供相对路径。
同样从第一行删除空格,我怀疑你有一些gargabe。错误消息中的 - 和hello之间应该只有一个空格。