From 374eb7bd3f369cba946d4b8002cd51a499aef32a Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Jul 2013 14:28:35 +0200 Subject: js integration test for signup, login, logout --- common_dependencies.rb | 7 +++++++ test/test_helper.rb | 25 +++++++++++++++++++++++++ users/test/integration/browser/account_test.rb | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 users/test/integration/browser/account_test.rb diff --git a/common_dependencies.rb b/common_dependencies.rb index 63c3710..085a898 100644 --- a/common_dependencies.rb +++ b/common_dependencies.rb @@ -1,7 +1,14 @@ source "http://rubygems.org" group :test do + # moching and stubing gem 'mocha', '~> 0.13.0', :require => false + # integration testing + gem 'capybara' + # headless js integration testing + gem 'poltergeist' + # required for save_and_open_page in integration tests + # gem 'launchy' end group :test, :development do diff --git a/test/test_helper.rb b/test/test_helper.rb index 0016771..c6794f4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,3 +10,28 @@ Dir["#{File.dirname(__FILE__)}/../*/test/support/**/*.rb"].each { |f| require f class ActiveSupport::TestCase # Add more helper methods to be used by all tests here... end + +require 'capybara/poltergeist' +Capybara.javascript_driver = :poltergeist + +CONFIG_RU = (Rails.root + 'config.ru').to_s +OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first + +Capybara.register_driver :rack_test do |app| + Capybara::RackTest::Driver.new(OUTER_APP) +end + +# Transactional fixtures do not work with Selenium tests, because Capybara +# uses a separate server thread, which the transactions would be hidden +# from. We hence use DatabaseCleaner to truncate our test database. +class BrowserIntegrationTest < ActionDispatch::IntegrationTest + # Make the Capybara DSL available + include Capybara::DSL + + Capybara.app_host = 'http://localhost:3000' + Capybara.server_port = 3000 + teardown do + Capybara.reset_sessions! # Forget the (simulated) browser state + Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver + end +end diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb new file mode 100644 index 0000000..a112430 --- /dev/null +++ b/users/test/integration/browser/account_test.rb @@ -0,0 +1,21 @@ +class AccountTest < BrowserIntegrationTest + + setup do + Capybara.current_driver = Capybara.javascript_driver # :selenium by default + end + + test "normal account workflow" do + username = "test_#{SecureRandom.urlsafe_base64}".downcase + password = SecureRandom.base64 + visit '/users/new' + fill_in 'Username', with: username + fill_in 'Password', with: password + fill_in 'Password confirmation', with: password + click_on 'Sign Up' + assert page.has_content?("Welcome #{username}"), + "failed to verify server. expected M2: #{page.evaluate_script("srp.session.getM2();")}" + click_on 'Logout' + assert_equal '/', current_path + end + +end -- cgit v1.2.3