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 --- test/test_helper.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/test_helper.rb') 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 -- cgit v1.2.3 From 8b79988c4c6cedd77664e14f16b149a669965eff Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 14 Jul 2013 19:52:54 +0200 Subject: make sure capybara runs the whole rack app We use port 3003 for the integration test server. This test takes a few seconds (~8) now. Most of this is startup time of the server. A second run still takes 2 seconds like before. --- test/test_helper.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index c6794f4..a409b58 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,24 +12,30 @@ class ActiveSupport::TestCase 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) + Capybara::RackTest::Driver.new(app) +end + +Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(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. +# this is integration testing. So let's make the whole +# rack stack available... +Capybara.app = OUTER_APP +Capybara.run_server = true +Capybara.app_host = 'http://lvh.me:3003' +Capybara.server_port = 3003 +Capybara.javascript_driver = :poltergeist + 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 -- cgit v1.2.3 From f40c09a8b750d5d317a22af7186bde5c940b6924 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 16 Jul 2013 13:06:48 +0200 Subject: ensure the page has been reloaded before testing current_path This test would fail sometimes on assert_equal '/', current_path I believe it was a timing issue. page.has_content? will wait for the content to show up. So afterwards the current_path should always be correct. --- test/test_helper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'test/test_helper.rb') diff --git a/test/test_helper.rb b/test/test_helper.rb index a409b58..26b99f4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -31,6 +31,7 @@ Capybara.run_server = true Capybara.app_host = 'http://lvh.me:3003' Capybara.server_port = 3003 Capybara.javascript_driver = :poltergeist +Capybara.default_wait_time = 5 class BrowserIntegrationTest < ActionDispatch::IntegrationTest # Make the Capybara DSL available -- cgit v1.2.3