ExiRe ExiRe - 1 year ago 162
Ruby Question

Ruby on Rails 3 + Rspec + Capybara: check response status

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

But Capybara shows that:

Failure/Error: response.should be_success
undefined method `success?' for nil:NilClass

Is there any method that provides such function?

UPD: My spec:

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"

describe "Admin panel" do
it "should have correct links" do
click_link "User"
response.should be_success

Answer Source

You're mixing controller and request specs.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download