ruby-on-rails-3rspec2capybararubycas

RoutingError on capybara with rubycas


I'm integrating capybara to a project. At first instance, I just wanted to check what is displaying the login page, so I made this code:

require 'acceptance/acceptance_helper'
feature 'Login' do
  scenario 'sign in with right credentials' do
    visit '/'
    save_and_open_page
  end
end

But when I run the test, it shows me:

 Failure/Error: visit '/'
 ActionController::RoutingError:
   No route matches "/login"
 # ./spec/acceptance/login_spec.rb:6

If I enter to the application without a valid session, it redirects me (code 302) to a rubycas server to log me in (which has the /login context at start) and after that it redirects me again to my server. What should I do to just view the login page or how to maintain the redirection references in capybara?


Solution

  • I usually do this:

    Inside my test.rb :

        require 'casclient'
      require 'casclient/frameworks/rails/filter'
    
      CASClient::Frameworks::Rails::Filter.configure(
          :cas_base_url => cas_base_url
      )
    

    Modify your spec like this:

    CASClient::Frameworks::Rails::Filter.fake(username)
      visit '/'
    

    Let me know if this works for you.

    ==================================================================================

    Without using "CASClient::Frameworks::Rails::Filter.fake(username)" I too get the same error. The reason is that cas redirects you to its base url with "/login?service=http%3A%2d%2Fwww.example.com%aF" a parameter like this. And hence it complaints about missing route.