[英]inconsistent Rspec/Capybara tests
I have commented out [get "pages/home"] in my routes.rb file, restarted my entire test environment and the following test STILL passes: 我已经在我的routes.rb文件中注释了[获取“页面/主页”],重新启动了整个测试环境,并且以下测试仍通过:
it "should contain 'This is a test'" do
get 'home'
response.body.should have_selector("p")
end
From my understanding, capybara runs the rspec tests from a 'browser' in memory. 据我了解,capybara从内存中的“浏览器”运行rspec测试。 If this is the case the rails routes MUST exist!
在这种情况下,必须存在铁轨路线! After commenting out my routes, it is still able to load the pages - I know this because if I remove the
<p>
selector the test fails. 在注释掉我的路由后,它仍然能够加载页面-我知道这是因为如果删除
<p>
选择器,则测试将失败。 After modifying the routes.rb file I have restarted my testing suite but it doesn't make a difference. 修改routes.rb文件后,我重新启动了测试套件,但这没有什么不同。
This makes me lose trust in the testing process because I have tests passing that shouldn't pass!! 这使我对测试过程失去了信任,因为我有不应该通过的测试!
It looks like this fragment is in a controller spec, which hits your controller directly. 看来此片段在控制器规格中,直接打到您的控制器上。 In the latest version of rspec, 2.9.0, a bad route won't make this example fail.
在最新版本的rspec 2.9.0中,错误的路由不会使此示例失败。 Routes are outside the purview of a controller spec.
路由超出了控制器规范的范围。
It seems like you intended to write a request spec, which should use capybara's visit
method: 似乎您打算编写一个请求规范,该规范应使用capybara的
visit
方法:
# spec/requests/something_spec.rb
require 'spec_helper'
describe 'home page' do
it "should contain 'This is a test'" do
visit '/pages/home'
page.should have_content 'This is a test'
end
end
See the capybara docs for more examples. 有关更多示例,请参见capybara文档 。 Rspec also supports routing specs , but I usually only use those for unusual routing.
Rspec还支持路由规范 ,但我通常仅将其用于异常路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.