【问题标题】:Problems running rake with rspec and ruby使用 rspec 和 ruby​​ 运行 rake 时出现问题
【发布时间】:2013-03-15 14:26:38
【问题描述】:

我正在尝试在我应该收到错误的 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 中止!

/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)

这是我运行 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 rubygems rake


    【解决方案1】:

    我遇到了同样的问题(通过完全相同的教程)。我花了三天的时间试图弄清楚。问题是我的“hello.rb”路径中的一个文件夹在两个单词之间有一个空格。说真的,就是这样。无论我做什么,红宝石路径都无法拾取它(除了改变空间)。哎呀。吸取的教训,不要命名任何东西,从现在开始有空格的任何地方。

    【讨论】:

      【解决方案2】:

      Ruby 说明了一切:“在库加载路径上找不到文件名 hello.rb”。您缺少 hello.rb 文件或 Ruby 找不到它。你真的有它在你运行 rake 的目录中的光盘上吗?如果它在其他地方你需要提供相对路径。

      还要从第一行删除空格,我怀疑你那里有一些 gargabe。错误信息中 -- 和 hello 之间应该只有一个空格。

      【讨论】:

      • 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': wrong number of arguments (0 for 1) (ArgumentError) &lt;br/&gt; And then I get the exact same error message as above starting with &lt;br/&gt; from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require'
      • 必须在字符串中,像这样:require "./xyz"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      相关资源
      最近更新 更多