ExiRe ExiRe - 5 months ago 35
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


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.