Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller test with rspec/capybara fails with: @controller is nil #178

Open
nagyt234 opened this issue Apr 15, 2013 · 0 comments
Open

Controller test with rspec/capybara fails with: @controller is nil #178

nagyt234 opened this issue Apr 15, 2013 · 0 comments

Comments

@nagyt234
Copy link

I am using rspec/capybara for testing. Model testing goes well with with_user, but I can not run controller test with get_with. The following simple test gives the error message:

Failures:

  1) Revision pages Index Authorisations Authorisation error 
     Failure/Error: get_with @admin1, revisions_path
     RuntimeError:
       @controller is nil: make sure you set it in your test's setup method.
     # ./spec/controllers/revisions_controller_spec.rb:23:in `block (5 levels) in <top (required)>'

The test script:

require 'spec_helper'
require 'shared/user_helper'

describe "Revision pages" do

  include SpecUserHelpers

  subject { page }

  describe "Index" do

    describe "Authorisations" do
      let(:auth_error_text) { "Sorry, you are not allowed to access that page." }

      before do
        without_access_control do
          create_users_with_roles               # see shared/user_helper
        end
      end

      describe "Authorisation error" do
        before do
          get_with @admin1, revisions_path
        end
        it { should have_selector('div.alert.alert-error', text: auth_error_text) }
      end
    end
  end
end

Do I something wrong? In the place of get_with the standard capybara visit revisions_path works, but I must set the user to test authorizations. I tried also

  before do
    with_user @admin1
      visit revisions_path
    end
  end

but then I se in the log that the Anonymous user is used. But with_user is for model testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant