本文介绍了Ruby on Rails 3 + Rspec + Capybara:检查响应状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Webrat迁移到Capybara,现在遇到很多错误。例如在webrat中,我可以在集成测试中使用它:
I migrated from Webrat to Capybara and now i get a lot of errors. For example in webrat i could use that in integration test:
response.should be_success
但是Capybara显示:
But Capybara shows that:
Failure/Error: response.should be_success
NoMethodError:
undefined method `success?' for nil:NilClass
有没有提供这种功能的方法?
Is there any method that provides such function?
UPD :我的规范:
require 'spec_helper'
describe "Admins" do
before(:each) do
@admin = FactoryGirl.create(:admin)
visit '/'
click_link "Login"
fill_in "Email", :with => @admin.email
fill_in "Password", :with => 'qwerty'
click_button "Sign in"
end
describe "Admin panel" do
it "should have correct links" do
click_link "User"
response.should be_success
end
end
end
推荐答案
您正在混合控制器并索取规格。
You're mixing controller and request specs.
在控制器规范中,您检查响应
;在请求规范中,您检查页面
内容,因为您只能访问html。
In a controller spec you check the response
, in a request spec, you check the page
content, since you have only access to the html.
这篇关于Ruby on Rails 3 + Rspec + Capybara:检查响应状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!