summaryrefslogtreecommitdiff
path: root/test/support/browser_integration_test.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-04-08 09:12:37 +0200
committerAzul <azul@leap.se>2014-04-08 09:12:37 +0200
commit53808b073f539ba2b442738b6abf97228488e311 (patch)
tree67e344defee90e4d0c5f91f6136f6619e97c4ace /test/support/browser_integration_test.rb
parentcb6442c344d6bdaf52c3878b2de2fcf4d85f2648 (diff)
moving all of core into toplevel, tests fail.
Diffstat (limited to 'test/support/browser_integration_test.rb')
-rw-r--r--test/support/browser_integration_test.rb81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
new file mode 100644
index 0000000..2885c3a
--- /dev/null
+++ b/test/support/browser_integration_test.rb
@@ -0,0 +1,81 @@
+#
+# BrowserIntegrationTest
+#
+# Use this class for capybara based integration tests for the ui.
+#
+
+class BrowserIntegrationTest < ActionDispatch::IntegrationTest
+
+ CONFIG_RU = (Rails.root + 'config.ru').to_s
+ OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first
+
+ require 'capybara/poltergeist'
+
+ Capybara.register_driver :rack_test do |app|
+ Capybara::RackTest::Driver.new(app)
+ end
+
+ Capybara.register_driver :poltergeist do |app|
+ Capybara::Poltergeist::Driver.new(app)
+ end
+
+ # 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
+ Capybara.default_wait_time = 5
+
+
+ # Make the Capybara DSL available
+ include Capybara::DSL
+
+ 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
+
+ def submit_signup(username = nil, password = nil)
+ username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
+ password ||= SecureRandom.base64
+ visit '/users/new'
+ fill_in 'Username', with: username
+ fill_in 'Password', with: password
+ fill_in 'Password confirmation', with: password
+ click_on 'Sign Up'
+ return username, password
+ 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
+
+end