ruby-on-rails – 运行RSpec时Zeus抛出错误

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 运行RSpec时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 app的根源.当我运行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文档中可以看出,它是一种方便的方法,可以为您运行测试.奇怪的是,当我注释掉开始/救援宙斯的’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上抛出一个问题犹豫不决,因为我完全不确定哪个库导致了哪些问题.

任何帮助都将非常感激.

解决方法

根据 this,您应该在执行视图规范时遵循specs文件命名约定.尝试重命名
spec/views/messages/show.html.erb

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

它可能会有所帮助.

原文链接:https://www.f2er.com/ruby/269590.html

猜你在找的Ruby相关文章