diff options
| author | Teddy Wing | 2015-12-08 01:49:50 -0500 | 
|---|---|---|
| committer | Teddy Wing | 2015-12-08 01:49:50 -0500 | 
| commit | 29aaafedef9f34c4ba62fb481fc5e6ba711c7eb7 (patch) | |
| tree | a87a4268b16e0fe3e0d077c969d4ad8ce2bf0e52 /test | |
| parent | d0e7441545f66aba4e0ba1af870978b675f5fa09 (diff) | |
| parent | 968b1b131972738e82cd4a099bf3d75f3dc67969 (diff) | |
| download | Ruby-Web-Sessions-Exercise-29aaafedef9f34c4ba62fb481fc5e6ba711c7eb7.tar.bz2 | |
Merge branch 'cleaned-for-exercise'
Diffstat (limited to 'test')
| -rw-r--r-- | test/integration/auth_test.rb | 43 | ||||
| -rw-r--r-- | test/integration_test_helper.rb | 18 | 
2 files changed, 61 insertions, 0 deletions
| diff --git a/test/integration/auth_test.rb b/test/integration/auth_test.rb new file mode 100644 index 0000000..7fa2950 --- /dev/null +++ b/test/integration/auth_test.rb @@ -0,0 +1,43 @@ +require 'integration_test_helper' + + +class TestAuth < CapybaraTestCase +  def login(username, password) +    visit '/' +    fill_in 'username', :with => username +    fill_in 'password', :with => password +    click_button 'Login' +  end + +  def login_with_correct_credentials +    login('hubertfarnsworth', 'secret') +  end + + +  def test_index_has_login_form +    visit '/' +    assert_text 'Login' +    assert has_selector?('//form') +  end + +  def test_unrecognised_user_login +    login('unregistered', 'password') + +    assert_text 'Unrecognized user' +  end + +  def test_login +    login_with_correct_credentials + +    assert_equal 200, page.status_code +    assert_text "You're logged in!" +  end + +  def test_logout +    login_with_correct_credentials +    visit '/logout' + +    assert_text 'Login' +    assert_equal '/', current_path +  end +end diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb new file mode 100644 index 0000000..609c08b --- /dev/null +++ b/test/integration_test_helper.rb @@ -0,0 +1,18 @@ +ENV['RACK_ENV'] = 'test' + +require 'minitest/autorun' +require 'capybara' + +require 'app' + + +class CapybaraTestCase < Minitest::Unit::TestCase +  include Capybara::DSL + +  def teardown +    Capybara.reset_sessions! +    Capybara.use_default_driver +  end +end + +Capybara.app = Sinatra::Application.new | 
