summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/integration/os_detection_test.rb8
-rw-r--r--test/test_helper.rb40
2 files changed, 42 insertions, 6 deletions
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