From e96d21ed7d2fce1d07fc381200d31919a2d93299 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Feb 2014 12:08:15 +0100 Subject: integration test with en-EN language Tests fail on machines that default to other available languages. Also move setting capybara driver to be javascript driver into the BrowserIntegrationTest. --- billing/test/integration/subscription_test.rb | 6 ++---- test/integration/os_detection_test.rb | 8 ++------ test/test_helper.rb | 5 +++++ users/test/integration/browser/account_test.rb | 4 ---- users/test/integration/browser/session_test.rb | 1 - 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index b95bfac..9d150e0 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 @@ -30,9 +28,9 @@ class SubscriptionTest < ActionDispatch::IntegrationTest @customer.stubs(:subscriptions).returns([@subscription]) @subscription.stubs(:balance).returns 0 visit user_subscriptions_path(@customer.user_id, :locale => nil) + page.save_screenshot('/tmp/subscriptions.png') 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/test/integration/os_detection_test.rb b/test/integration/os_detection_test.rb index cb254aa..6d9a648 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 3e301e7..1dff80a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,6 +43,11 @@ 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 diff --git a/users/test/integration/browser/account_test.rb b/users/test/integration/browser/account_test.rb index 3785b72..a5677ad 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 bb4e8c9..3a41b3a 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 -- cgit v1.2.3 From d8aa92f9d4911e28c95e9abb70e87ac282ef0601 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Feb 2014 19:03:40 +0100 Subject: make sure ticket get's cleared at end of tickets_by_admin test Also relax the requirement from tickets.count > 1 to > 0. There is only one ticket if there have not been any others in the database ahead of time. --- help/test/functional/tickets_controller_test.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 2b30f66..2530ba1 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 -- cgit v1.2.3 From f13cfd635f9d0d089da10c1a2c9f4af5ff87cda8 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Feb 2014 11:27:47 +0100 Subject: log failing integration tests with screenshot * store the last screenshot in tmp * store the html and the end of the server log in tmp Filenames are build from the test class name and the tests name. --- .travis.yml | 2 ++ test/test_helper.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/.travis.yml b/.travis.yml index 232467c..3bd8ba1 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/test/test_helper.rb b/test/test_helper.rb index 1dff80a..3fb2716 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -52,4 +52,39 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest 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 -- cgit v1.2.3 From 58a36ae079f9103f2aa18da48d5ea2a18aae938c Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Feb 2014 11:52:30 +0100 Subject: stop taking screenshot - will happen no failure autmatically now --- billing/test/integration/subscription_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb index 9d150e0..1473eb0 100644 --- a/billing/test/integration/subscription_test.rb +++ b/billing/test/integration/subscription_test.rb @@ -28,7 +28,6 @@ class SubscriptionTest < BrowserIntegrationTest @customer.stubs(:subscriptions).returns([@subscription]) @subscription.stubs(:balance).returns 0 visit user_subscriptions_path(@customer.user_id, :locale => nil) - page.save_screenshot('/tmp/subscriptions.png') assert page.has_content?("Subscriptions") assert page.has_content?("Status: Active") end -- cgit v1.2.3