遇到“访问”问题在 Rails 教程中的集成测试中
我是 Rails 新手,正在阅读 rails 3 教程。我在运行集成测试时遇到问题。看来“访问”方法(Webrat?)总是会失败。这是我从 rspec 收到的错误消息:
Failure/Error: visit signup_path
Unknown Webrat mode: nil
Please ensure you have a Webrat configuration block that specifies a mode
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
This configure block supercedes the need to require "webrat/<framework>".
For example:
Webrat.configure do |config|
config.mode = :rails
end
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
我尝试将上面的 Webrat 配置块添加到 spec/spec_helpers.rb,并且收到此错误:
Failure/Error: visit signup_path
no such file to load -- action_controller/integration
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
我已阅读有关此问题的其他主题,他们建议使用 'config.mode = :rack',如果我这样做,则会收到此错误:
Failure/Error: visit signup_path
undefined method `last_response' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1::Nested_2:0xa4b8aac>
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
我想可能需要注意的是,我在 win7x64 上开始了本教程,但我尝试在 ubuntu 上克隆存储库,但出现了相同的错误。如果有人想看的话,这是存储库:
git://github.com/ender4/sample_app2.git 请注意其中的 2^
我已经阅读了很多类似的主题,但大多数解决方案适用于旧版本的rails/rspec/webrat 或其他测试框架(如cucumber),所以我不知道它们是否/如何应用。
任何帮助将不胜感激。
I am new to rails and am running through the rails 3 tutorial. I have a problem running integration tests. It seems that the method 'visit' (Webrat?) will always fail. This is the kind of error message I get from rspec:
Failure/Error: visit signup_path
Unknown Webrat mode: nil
Please ensure you have a Webrat configuration block that specifies a mode
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
This configure block supercedes the need to require "webrat/<framework>".
For example:
Webrat.configure do |config|
config.mode = :rails
end
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
I tried adding the Webrat configure block above to spec/spec_helpers.rb, and I get this error:
Failure/Error: visit signup_path
no such file to load -- action_controller/integration
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
I have read other topics about this problem and they suggested using 'config.mode = :rack', if I do so then I get this error:
Failure/Error: visit signup_path
undefined method `last_response' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_1::Nested_2:0xa4b8aac>
# ./spec/requests/users_spec.rb:27:in `block (5 levels) in <top (required)>'
# ./spec/requests/users_spec.rb:26:in `block (4 levels) in <top (required)>'
I guess it might be important to note that I started the tutorial on win7x64, but I tried cloning the repository on ubuntu with the same errors. Here is the repository if anyone wants a look:
git://github.com/ender4/sample_app2.git
note the 2 there^
I have read a lot of similar topics but most solutions are for older versions of rails/rspec/webrat or for other testing frameworks (like cucumber) and so I do not know if/how they would apply.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您看到失败:
失败/错误:访问signup_path
名称错误:
#RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1:0x0000000272d5b0 的未定义局部变量或方法“signup_path”
...确保将测试放置在正确的文件中:
它属于:
/spec/requests/users_spec.rb
不在:
/spec/model/user_spec.rb
通过实践来学习! :0>>
...更容易看到另一个人撞到墙上,然后避开那条路! :)
If you see failures:
Failure/Error: visit signup_path
NameError:
undefined local variable or method `signup_path' for #RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1:0x0000000272d5b0
... Make sure you are placing the test(s) in the correct file:
it belongs in:
/spec/requests/users_spec.rb
not in:
/spec/model/user_spec.rb
Learn by doing and all that! :0 <>
... much easier to watch the other guy slam into a wall and then avoid that path! :)
将宝石更新为:
有效!
updated gems to :
works!
我想我找到了罪魁祸首,rspec 2.2.0。使用 rspec 2.1.0 似乎可以解决该问题。
I think I found the culprit, rspec 2.2.0. Using rspec 2.1.0 seems to fix the problem.