summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2014-02-07 07:51:12 -0800
committerjessib <jessib@riseup.net>2014-02-07 07:51:12 -0800
commit393abdefeeed2e9653e22c85b5d1c617003e95a9 (patch)
tree8351cc3a82c7c030f07bd494c2c1998dc19d9462
parentcbcd4d388dec048be3d3f66c1b909515d3176ead (diff)
parent58a36ae079f9103f2aa18da48d5ea2a18aae938c (diff)
Merge pull request #137 from azul/test/fix-red-ci
Test/fix red ci
-rw-r--r--.travis.yml2
-rw-r--r--billing/test/integration/subscription_test.rb5
-rw-r--r--help/test/functional/tickets_controller_test.rb24
-rw-r--r--test/integration/os_detection_test.rb8
-rw-r--r--test/test_helper.rb40
-rw-r--r--users/test/integration/browser/account_test.rb4
-rw-r--r--users/test/integration/browser/session_test.rb1
7 files changed, 59 insertions, 25 deletions
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/billing/test/integration/subscription_test.rb b/billing/test/integration/subscription_test.rb
index b95bfac..1473eb0 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 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
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..3fb2716 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 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