diff --git a/.travis.yml b/.travis.yml index 232467cf46a279e6af5784894f5655646da50035..3bd8ba1fce35e74d70d8917df1b4ce744ad4757f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ before_script: - "bundle exec rake couchrest:migrate_with_proxies" - "bundle exec rake couchrest:migrate_with_proxies" # looks like this needs to run twice - "mv test/config/couchdb.yml.user config/couchdb.yml" +after_script: + - "cat tmp/*.test*.log" # printing logs from the failed integration tests diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index b95bfac96065c8ce701d9968dc28f07236af04ff..1473eb00af5754e9576cca986aa6340d85d405a7 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -2,9 +2,8 @@ require 'test_helper' require 'fake_braintree' require 'capybara/rails' -class SubscriptionTest < ActionDispatch::IntegrationTest +class SubscriptionTest < BrowserIntegrationTest include Warden::Test::Helpers - include Capybara::DSL include CustomerTestHelper include StubRecordHelper @@ -17,7 +16,6 @@ class SubscriptionTest < ActionDispatch::IntegrationTest payment_method_token: @braintree_customer.credit_cards.first.token, price: '10' @subscription = response.subscription - Capybara.current_driver = Capybara.javascript_driver end teardown do @@ -32,7 +30,6 @@ class SubscriptionTest < ActionDispatch::IntegrationTest visit user_subscriptions_path(@customer.user_id, :locale => nil) assert page.has_content?("Subscriptions") assert page.has_content?("Status: Active") - page.save_screenshot('/tmp/subscriptions.png') end # test "user cannot see all subscriptions for other user" do diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 2b30f66620aaa2c2dc66281d0b939f0362e2f06c..2530ba112a8bb981fbb3fd29e39844a6cf0f52b9 100644 --- a/help/test/functional/tickets_controller_test.rb +++ b/help/test/functional/tickets_controller_test.rb @@ -158,19 +158,23 @@ class TicketsControllerTest < ActionController::TestCase end test "tickets by admin" do - other_user = find_record :user - ticket = FactoryGirl.create :ticket, :created_by => other_user.id + begin + other_user = find_record :user + ticket = FactoryGirl.create :ticket, :created_by => other_user.id - login :is_admin? => true + login :is_admin? => true - get :index, {:admin_status => "all", :open_status => "open"} - assert assigns(:all_tickets).count > 1 - - # if we close one ticket, the admin should have 1 less open ticket - assert_difference('assigns[:all_tickets].count', -1) do - assigns(:tickets).first.close - assigns(:tickets).first.save get :index, {:admin_status => "all", :open_status => "open"} + assert assigns(:all_tickets).count > 0 + + # if we close one ticket, the admin should have 1 less open ticket + assert_difference('assigns[:all_tickets].count', -1) do + assigns(:tickets).first.close + assigns(:tickets).first.save + get :index, {:admin_status => "all", :open_status => "open"} + end + ensure + ticket.reload.destroy if ticket end end diff --git a/test/integration/os_detection_test.rb b/test/integration/os_detection_test.rb index cb254aa00e715e25e7742501542f6ca3e862e9da..6d9a648d8fcacbe094baba725981b8bbbb275076 100644 --- a/test/integration/os_detection_test.rb +++ b/test/integration/os_detection_test.rb @@ -2,19 +2,15 @@ require 'test_helper' class OsDetectionTest < BrowserIntegrationTest - setup do - Capybara.current_driver = Capybara.javascript_driver - end - test "old windows shows deactivated download" do - page.driver.headers = { "User-Agent" => "Win98" } + page.driver.add_headers "User-Agent" => "Win98" visit '/' assert_selector "html.oldwin" assert has_text? "not available" end test "android shows android download" do - page.driver.headers = { "User-Agent" => "Android" } + page.driver.add_headers "User-Agent" => "Android" visit '/' assert_selector "html.android" assert has_no_text? "not available" diff --git a/test/test_helper.rb b/test/test_helper.rb index 3e301e7634d1b1005ab3d494b861efd50a2642a9..3fb271618f38b07d3ee6d17210c1d8d2f729a076 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,8 +43,48 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest include Capybara::DSL include IntegrationTestHelper + setup do + Capybara.current_driver = Capybara.javascript_driver + page.driver.add_headers 'ACCEPT-LANGUAGE' => 'en-EN' + end + teardown do Capybara.reset_sessions! # Forget the (simulated) browser state Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver end + + add_teardown_hook do |testcase| + unless testcase.passed? + testcase.save_state + end + end + + def save_state + page.save_screenshot screenshot_path + File.open(logfile_path, 'w') do |test_log| + test_log.puts self.class.name + test_log.puts "=========================" + test_log.puts __name__ + test_log.puts Time.now + test_log.puts current_path + test_log.puts page.status_code + test_log.puts page.response_headers + test_log.puts "page.html" + test_log.puts "------------------------" + test_log.puts page.html + test_log.puts "server log" + test_log.puts "------------------------" + test_log.puts `tail log/test.log -n 200` + end + end + + protected + + def logfile_path + Rails.root + 'tmp' + "#{self.class.name.underscore}.#{__name__}.log" + end + + def screenshot_path + Rails.root + 'tmp' + "#{self.class.name.underscore}.#{__name__}.png" + end end diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index 3785b72f761bb83fcbfa3e0f9b4f01290000e01f..a5677ad388e78f20dfb0807880051f852eeae5f2 100644 --- a/users/test/integration/browser/account_test.rb +++ b/users/test/integration/browser/account_test.rb @@ -2,10 +2,6 @@ require 'test_helper' class AccountTest < BrowserIntegrationTest - setup do - Capybara.current_driver = Capybara.javascript_driver - end - teardown do Identity.destroy_all_disabled end diff --git a/users/test/integration/browser/session_test.rb b/users/test/integration/browser/session_test.rb index bb4e8c9b0044b961e2b4eb795c2ef6d9c6e44e8a..3a41b3a349dd07170eaa1bac2962847c5aec3615 100644 --- a/users/test/integration/browser/session_test.rb +++ b/users/test/integration/browser/session_test.rb @@ -3,7 +3,6 @@ require 'test_helper' class SessionTest < BrowserIntegrationTest setup do - Capybara.current_driver = Capybara.javascript_driver @username, password = submit_signup end