【发布时间】:2013-06-04 02:07:28
【问题描述】:
我遇到了许多 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!
我的密码是 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 文档中可以看出,它是一种方便的方法,可以为您运行测试。奇怪的是,当我注释掉 begin/rescue zeus 的 require 'rspec/autorun' 部分时,zeus 仍然具有相同的行为(抛出错误),但 rspec 不再以传统方式运行(仅运行 rspec 命令)。根据本文档 (https://www.relishapp.com/rspec/rspec-core/docs/command-line),您仍然可以运行它,只是以稍微冗长的方式。
无论如何,这向我暗示,要么 zeus 依赖于 rspec exec 脚本以外的文件,要么问题与 spec_helper.rb 要求语句(其中 rspec 2.13 .1 不会添加到配置中)。
有没有人遇到过这种情况或走同样的路?
我很犹豫是否要在 rspec-rails / rspec-core 或 zeus 存储库上提出问题,因为我完全不确定哪个库会导致哪个库出现问题。
非常感谢任何帮助。
【问题讨论】:
-
我遇到了类似的问题,只有在 zeus 下运行某个辅助规范才会失败,并且只有在运行该规范文件时才会失败(不是所有辅助规范)。错误是帮助程序找不到 ApplicationHelper 中定义的方法。我终于在帮助规范的顶部添加了一个“需要'application_helper'”,这似乎已经修复了它。 spork 和 zeus 也有同样的问题,所以我不相信这是 zeus 特有的。
标签: ruby-on-rails rspec rspec-rails zeus