Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
     NoMethodError:
       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"
  end

  describe "Admin panel" do
    it "should have correct links" do
      click_link "User"
      response.should be_success
    end
  end
end
like image 945
ExiRe Avatar asked Nov 27 '22 09:11

ExiRe


1 Answers

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.

like image 107
apneadiving Avatar answered Dec 08 '22 01:12

apneadiving