Homan
Homan

Reputation: 26718

A simple DEVISE sign-up... Why doesn't this rspec/capybara test pass?

A typical DEVISE create account page should redirect to a welcome page for new users

describe ArtistsController do

  render_views

   ....

describe "Sign UP should redirect to welcome page" do
  it "should redirect to welcome page on valid sign up", :js => true do
    visit destroy_artist_session_path #just to be sure we're logged out
    visit new_artist_registration_path
    fill_in 'Email', :with => '[email protected]'
    fill_in 'Password', :with => 'password'
    fill_in 'Password confirmation', :with => 'password'
    click_link_or_button 'Sign up'
    #save_and_open_page <-- reveals we are still on the sign-up page
    page.should have_content("Welcome")

  end
end

I manually QA'd this scenario on my local machine and it works fine. But the test doesn't seem to work; it does NOT continue to the welcome page. The new user is NOT created in the DB. There is no complaint by capybara that it cannot find the button or anything.

What am I doing wrong?

Upvotes: 1

Views: 951

Answers (2)

Tatiana Tyu
Tatiana Tyu

Reputation: 353

I had the same issue, it was connected to subdomains.

The session key was "lvh.me", but tests were using "example.com" by default.

My test was submitting login form correctly, user was authenticated no problem, then Devise was redirecting to the home page in "example.com" domain, and the app was not able to find session data (which were under "lvh.me" key), and was redirecting back to login page w/o any flash messages or errors.

So if you are using subdomains, be sure to set up Capybara hosts before logging user in. Just for a case, here is what I do:

def go_to(subdomain)
  Capybara.app_host = "http://#{subdomain}.lvh.me"
  Capybara.server_port = 3000
  host! "#{subdomain}.lvh.me:3000"
end

Upvotes: 1

Andy Waite
Andy Waite

Reputation: 11076

It seems like you're being redirected back to the login page.

  • Does the output of save_and_open_page container any flash messages?
  • Have you checked the test.log for clues?
  • Try set the Capybara driver to mechanize and you'll be able to watch what happens - it may help in tracking down the problem.

Upvotes: 0

Related Questions