我遇到了一种情况,这似乎发生在许多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文档中可以看出,它是一种可以为您运行测试的方便方法。奇怪的是,当我注释掉begin/rescue的require 'rspec/autorun'部分时,zeus仍然有相同的行为(抛出错误),但是rspec不再以传统方式运行(只运行rspec命令)。根据本文档(https://www.relishapp.com/rspec/rspec-core/docs/command-line),您仍然可以运行它,只是稍微有点冗长而已。
在任何情况下,这都向我暗示,要么zeus依赖于rspec执行脚本以外的文件,要么问题与spec_helper.rb require语句( rspec 2.13.1没有添加到配置中)没有那么明确地相关。
有没有人遇到这种情况或走上同样的道路??
我很犹豫要不要在rspec-rails / rspec-core或zeus代码库上抛出一个问题,因为我根本不确定哪个库为哪个库带来了问题。
任何帮助都将不胜感激。
发布于 2013-07-12 21:05:19
根据this的说法,在做视图规范时,你应该遵循规范文件的命名约定。尝试重命名:
spec/views/messages/show.html.erb至
spec/views/messages/show.html.erb_spec.rb这可能会有帮助。
https://stackoverflow.com/questions/16989655
复制相似问题