RoutingError on capybara with rubycas

478 views Asked by At

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?

2

There are 2 answers

0
Anidhya Ahuja On BEST ANSWER

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.

  • Check your test log
2
Malik Arsalan Tahir On

Make sure you have added the proper matching routes. it seems that you are missing routes.

I hope this helps you.

For writing routes you can get help from http://railscasts.com/episodes/79-generate-named-routes