【问题标题】:app academy ruby-test-first spec errors应用学院 ruby​​-test-first 规范错误
【发布时间】:2014-12-13 04:20:14
【问题描述】:

我是编程新手,目前正在自学。我首先关注应用学院的 precourse。 我在尝试让第一个规范在第一个项目 00_hello 上运行时遇到了很多麻烦。

我正在使用 Windows 7 pc 64 位,在我不得不使用 rspec 之前,我在其上运行 Ruby 并没有遇到太多问题。

我也有一个运行 Mac OS X 的 VM,但我也遇到了类似的问题。

我在运行 00_hello_spec 时遇到的当前错误是

D:/1/spec/00_hello_spec.rb:105:in <main>': undefined method describe' for main :Object (NoMethodError)

这是我第一次使用 rspec,非常感谢任何帮助正确设置和运行它。

这里是00_hello_spec.rb的内容:

require "00_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

【问题讨论】:

  • rspec 似乎没有加载
  • 我已经安装了 rspec

标签: ruby rspec


【解决方案1】:

我在这些测试中遇到了类似的问题。

首先运行 rspec -v,它会告诉你 RSPEC 是否工作。 其次将文件中的'require'行更改为:

require "./hello" 

默认情况下实际上只是给你“你好”,有时它因此找不到其他文件。这两个文件需要在同一个文件夹中才能正常工作。

如果 RSPEC 正常工作并且您更改了该行,它应该可以工作。如果它没有卸载 RSPEC 并使用教程重新安装它。

最后,当您在终端中运行它时,请确保您使用

rspec hello_spec.rb

如果您使用 Ruby 命令,它将无法工作。

【讨论】:

  • 如果您对问题提出编辑建议,则应提供更具描述性的摘要来解释您进行编辑的原因,例如“添加 OP 放入 cmets 的代码”。我们在编辑审核中看不到 cmets,并且没有编辑说明,您似乎正在尝试通过编辑问题来回答或回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
  • 2017-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多