使用rspec和ruby运行rake时出现问题

使用rspec和ruby运行rake时出现问题,ruby,rubygems,rake,Ruby,Rubygems,Rake,我试图在一个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

我试图在一个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的代码

    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
Ruby一语道破:“在库加载路径上找不到文件名hello.rb”。您缺少hello.rb文件,或者Ruby找不到它。你真的在你运行rake的目录中的光盘上有吗?如果是在其他地方,您需要提供相对路径


同时删除第一行的空白,我怀疑你有一些垃圾。错误消息中--和hello之间应该只有一个空格。

我也遇到了同样的问题(正在学习完全相同的教程)。我花了三天的时间想弄明白。问题是我的一个文件夹在“hello.rb”路径中的两个单词之间有一个空格。说真的,就是这样。无论我做了什么,ruby路径都无法拾取它(除了更改空间)。啊。从中学到的经验教训是,不要说出任何东西,从这里开始,任何有空间的地方。

lzap,谢谢。您提到的错误是我应该处理的,我已经完成了练习中提到的步骤,但错误消息与引用的错误消息不同。此外,当我创建Ruby想要的hello.rb文件时(在同一目录中),错误消息不会改变。此外,即使我删除“require“Hello”语句,我仍然会收到此错误消息。如果它正是您所说的,那么我如何将rake指向它的路径,因为它似乎没有在同一目录中找到hello.rb?再次感谢。Ruby 1.8会尝试在当前目录中查找,Ruby 1.9+不会。尝试在那里添加require“/hello”。当我完全按照您所说的那样做时,错误消息保持不变。在我得到的字符串前面添加./usr/lib/ruby/1.9.1/rubygems/custom_require.rb:34:in
require”:参数数量错误(0代表1)(ArgumentError)
然后我从/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
require'中得到了与上面完全相同的错误消息,以
开头,它必须在字符串中,如:require“/xyz”
    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