Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created December 22, 2010 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorturk/751452 to your computer and use it in GitHub Desktop.
Save trevorturk/751452 to your computer and use it in GitHub Desktop.
# test/integration/example_test.rb
require "test_helper"
class ExampleTest < ActionController::IntegrationTest
setup do
Admin.create(:email => 'admin@example.com', :password => 'password')
end
test "admin sign in" do
visit admin_root_path
assert_equal current_path, new_admin_session_path
fill_in 'admin_email', :with => 'admin@example.com'
fill_in 'admin_password', :with => 'invalid'
click_button 'admin_submit'
assert page.has_content?('Invalid email or password')
assert_equal current_path, new_admin_session_path
fill_in 'admin_email', :with => 'admin@example.com'
fill_in 'admin_password', :with => 'password'
click_button 'admin_submit'
assert page.has_content?('Signed in successfully')
assert_equal current_path, admin_root_path
end
end
# Gemfile
source 'http://rubygems.org'
gem 'rails'
group :test do
gem 'capybara'
gem 'launchy'
end
# test/test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
class ActiveSupport::TestCase
setup do
Capybara.reset_sessions!
end
end
class ActionController::IntegrationTest
include Capybara
end
@tkrotoff
Copy link

This is interesting.

You write:

click_button 'admin_submit'
assert page.has_content?('Invalid email or password')
assert_equal current_path, new_admin_session_path

current_path matches new_admin_session_path, no problem here.

Instead if you write:

click_button 'admin_submit'
assert_equal current_path, new_admin_session_path
assert page.has_content?('Invalid email or password')

Then current_path does not match new_admin_session_path
I think it is because the page is not loaded fast enough for Capybara.
Too bad as the latter style is more logical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment