0

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?

Alter Lagos
  • 12,090
  • 1
  • 70
  • 92

2 Answers2

1

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
Anidhya Ahuja
  • 883
  • 7
  • 22
0

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

  • But '/login' is not a valid route on my application, is a route of the authentication system (rubycas-sever) that is located in another application and address. For example, if I enter to my app (http://localhost:3000) and I don't have a session, it redirects me instantly to the auth server (http://www.authserver.com/login?...) so here is the login page and after log me in it redirects me again to localhost. Why should add '/login' as a valid route on my application? – Alter Lagos Dec 19 '11 at 22:24
  • onething you make sure is that, capybara dont fillin the fields not part of it eg, you are visting a remote page facebook and type in fill in then it wont work. you must run test cases on local host instead of other websites. – Malik Arsalan Tahir Dec 21 '11 at 07:22