blowmage / minitest-rails-capybara

Capybara integration for MiniTest::Rails
http://blowmage.com/minitest-rails-capybara
MIT License
131 stars 40 forks source link

Browser not resetting between scenarios #23

Closed jimsynz closed 8 years ago

jimsynz commented 10 years ago

I have been setting up a client's project to do their features with Capybara (they're an existing minitest user).

Everything seemed to go smoothly, except that the session wasn't being reset between scenarios.

My feature file looked like:

require 'test_helper'

feature "EducatorCanLogIn" do
  given(:centre)   { centres(:mp) }
  given(:educator) { users(:ed) }

  scenario "an educator can log in" do
    visit '/'
    click_link 'Login'
    assert_text 'Login to your ___ account'
    fill_in 'Email', with: educator.email
    fill_in 'Password', with: 'secret'
    click_button 'Submit'
    assert_text centre.name
  end

  scenario "an educator with an incorrect password can't log in" do
    visit '/'
    click_link 'Login'
    assert_text 'Login to your ___ account'
    fill_in 'Email', with: educator.email
    fill_in 'Password', with: 'Marty McFly'
    click_button 'Submit'
    refute_text centre.name
  end
end

I was able to verify that Capybara.reset_sessions! was being called by the after hook, however it didn't come right until I added

before do
  Capybara.current_driver = Capybara.javascript_driver
end

to my tests.

Now it works. Am I doing it wrong?

blowmage commented 10 years ago

So, are you saying it works correctly if you define the before hook, and it doesn't work if you don't define the before hook?

blowmage commented 10 years ago

Do you have any JavaScript on these pages that change the behavior?

blowmage commented 8 years ago

Closing as I've never heard back. I assume if this was a problem for more we would have more activity on this issue.