Zeus在运行RSpec时抛出错误

jam*_*ant 8 rspec ruby-on-rails zeus rspec-rails

我遇到了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
Run Code Online (Sandbox Code Playgroud)

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

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

Hello world!
Run Code Online (Sandbox Code Playgroud)

我的pwd是rails app的根源.当我跑步时,rspec我收到以下回复:

user@host $ rspec
.

Finished in 0.06264 seconds
1 example, 0 failures

Randomized with seed 9609
Run Code Online (Sandbox Code Playgroud)

一切都很好看.但是,如果我运行测试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
Run Code Online (Sandbox Code Playgroud)

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

使用Rspec进行测试时Zeus失败了

zeus rspec失败包括必需的文件,但单独的rspec就可以了

Zeus + FactoryGirl ::语法::方法.未定义的方法`create'

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

require 'rspec/autorun'
require 'rspec/autotest'
Run Code Online (Sandbox Code Playgroud)

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

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

我目前正在使用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
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

任何帮助都将非常感激.

paw*_*urb 1

据此您在查看规格时应遵循规格文件命名约定。尝试重命名:

spec/views/messages/show.html.erb
Run Code Online (Sandbox Code Playgroud)

spec/views/messages/show.html.erb_spec.rb
Run Code Online (Sandbox Code Playgroud)

这可能会有所帮助。