diff options
-rw-r--r-- | config/environments/test.rb | 7 | ||||
-rw-r--r-- | test/integration/key_discovery_test.rb | 23 | ||||
-rw-r--r-- | test/support/browser_integration_test.rb | 21 | ||||
-rw-r--r-- | test/support/rack_stack_test.rb | 32 |
4 files changed, 61 insertions, 22 deletions
diff --git a/config/environments/test.rb b/config/environments/test.rb index 0ba4fbd..ecbbedc 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,12 +18,11 @@ Rails.application.configure do config.serve_static_files = true config.static_cache_control = 'public, max-age=3600' - # Show full error reports and disable caching. - config.consider_all_requests_local = true + # Disable caching. config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + # Render the exception templates so we can test them as well. + config.action_dispatch.show_exceptions = true # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false diff --git a/test/integration/key_discovery_test.rb b/test/integration/key_discovery_test.rb new file mode 100644 index 0000000..2a38a78 --- /dev/null +++ b/test/integration/key_discovery_test.rb @@ -0,0 +1,23 @@ +require 'test_helper' + +# This is not really a browser test - key discovery is used from bitmask. +# However we need to make sure to test the full rack stack to replicate +# exception handling. +class KeyDiscoveryTest < RackStackTest + include Capybara::DSL + + setup do + # make sure we test the whole stack... + Capybara.current_driver = Capybara.javascript_driver + end + + teardown do + # Revert Capybara.current_driver to Capybara.default_driver + Capybara.use_default_driver + end + + def test_404_on_non_existing_user + visit '/key/asjkholifweatg' + assert_equal 404, status_code + end +end diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb index 1f5e3d2..c0fef0a 100644 --- a/test/support/browser_integration_test.rb +++ b/test/support/browser_integration_test.rb @@ -1,33 +1,18 @@ +require_relative 'rack_stack_test' + # # BrowserIntegrationTest # # Use this class for capybara based integration tests for the ui. # -require 'capybara/rails' -class BrowserIntegrationTest < ActionDispatch::IntegrationTest +class BrowserIntegrationTest < RackStackTest # let's use dom_id inorder to identify sections include ActionView::RecordIdentifier 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_max_wait_time = 5 diff --git a/test/support/rack_stack_test.rb b/test/support/rack_stack_test.rb new file mode 100644 index 0000000..eb49d1e --- /dev/null +++ b/test/support/rack_stack_test.rb @@ -0,0 +1,32 @@ +require 'capybara/rails' +# +# RackStackTest +# +# Tests that will use the entire rack stack from capybara. +# +class RackStackTest < ActionDispatch::IntegrationTest + + CONFIG_RU = (Rails.root + 'config.ru').to_s + OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first + + # 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 + + # WARNING: this creates an error in the test as soon as there + # is an error in rails. Use the javascript driver for testing + # error rendering + Capybara.register_driver :rack_test do |app| + Capybara::RackTest::Driver.new(app) + end + + require 'capybara/poltergeist' + + Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(app) + end + +end |