Zeus在运行RSpec时抛出错误

时间:2013-06-07 17:19:51

标签: ruby-on-rails rspec rspec-rails zeus

我遇到了Zeus和RSpec的许多用户似乎遇到的情况。

假设我有以下规范:

# spec/views/messages/show.html.erb

require 'spec_helper'

describe "messages/show.html.erb" do
  it "displays the text attribute of the message" do
    render
    rendered.should contain("Hello world!")
  end
end

以及它测试的以下视图模板。

# app/views/messages/show.html.erb

Hello world!

我的pwd是rails应用程序的根目录。当我运行rspec时,我收到以下回复:

user@host $ rspec
.

Finished in 0.06264 seconds
1 example, 0 failures

Randomized with seed 9609

一切看起来都不错。但是,如果我使用zeus rspec spec运行测试(zeus rspec根本不起作用),我会得到以下输出。

user@host $ zeus rspec spec
.

Finished in 0.07292 seconds
1 example, 0 failures

Randomized with seed 0

F

Failures:

  1) messages/show.html.erb displays the text attribute of the message
     Failure/Error: render
     NameError:
       undefined local variable or method `render' for <RSpec::Core::ExampleGroup::Nested_2:0x936a0fc>
     # ./spec/views/show.html.erb_spec.rb:5:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'

Finished in 0.00041 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/views/show.html.erb_spec.rb:4 # messages/show.html.erb displays the text attribute of the message

我在SO上看到过类似的几个问题,例如:

Zeus fails when testing with Rspec

zeus rspec fails include required files, but rspec alone does fine

Zeus + FactoryGirl::Syntax::Methods. undefined method `create'

常见的解决方案是解决方案建议在spec_helper.rb中注释/删除以下行(如果存在)。

require 'rspec/autorun'
require 'rspec/autotest'

我的问题是这些行没有出现在我的spec_helper.rb文件中或应用程序中的任何其他位置。

经过一番挖掘后,我发现违规行实际上是在RSpec gem的rspec可执行脚本中。

我目前正在使用RSpec版本2.13.1,文件内容如下:

#!/usr/bin/env ruby

begin
  require 'rspec/autorun'
rescue LoadError
  $stderr.puts <<-EOS
#{'*'*50}
  Could not find 'rspec/autorun'

  This may happen if you're using rubygems as your package manager, but it is not
  being required through some mechanism before executing the rspec command.

  You may need to do one of the following in your shell:

    # for bash/zsh
    export RUBYOPT=rubygems

    # for csh, etc.
    set RUBYOPT=rubygems

  For background, please see http://gist.github.com/54177.
#{'*'*50}
  EOS
  exit(1)
end

从RSpec文档中可以看出,它是一种方便的方法,可以为您运行测试。奇怪的是,当我注释掉开始/救援宙斯的require 'rspec/autorun'部分仍然具有相同的行为(抛出错误),但rspec不再以传统方式运行(仅运行rspec命令)。根据这个文档(https://www.relishapp.com/rspec/rspec-core/docs/command-line),你仍然可以运行它,只是稍微冗长一点。

在任何情况下,这都告诉我,zeus要么依赖于rspec exec脚本以外的文件,要么问题与spec_helper.rb require语句不太明显相关( rspec 2.13.1没有添加到配置中。

有没有人遇到这种情况或者走同样的道路?

我对于在rspec-rails / rspec-core或zeus repos上抛出一个问题犹豫不决,因为我完全不确定哪个库导致了哪些问题。

任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:1)

根据this,您在执行视图规范时应遵循specs文件命名约定。尝试重命名:

spec/views/messages/show.html.erb

spec/views/messages/show.html.erb_spec.rb

它可能有所帮助。