Module: IntegrationTestsRails::Capybara::Util
- Defined in:
- lib/integration_tests_rails/capybara/util.rb
Overview
Utilities for Capybara setup and configuration are found here.
Class Method Summary collapse
- .configure_routes ⇒ Object
- .configure_rspec ⇒ Object
- .configure_webmock ⇒ Object
- .ensure_server_ready(context) ⇒ Object
- .log(message) ⇒ Object
- .verbose? ⇒ Boolean
Class Method Details
.configure_routes ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 50 def configure_routes return unless IntegrationTestsRails.configuration.experimental_features app = Rails.application routes = app.routes # Use append and let Rails handle finalization automatically routes.append do get '/tests', to: 'tests#index', as: :tests end routes.instance_variable_set(:@finalized, false) routes.finalize! log 'Routes appended.' end |
.configure_rspec ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 37 def configure_rspec RSpec.configure do |config| config.before(:each, type: :feature) do ::.current_driver = ::.javascript_driver IntegrationTestsRails::::Util.ensure_server_ready(self) end if IntegrationTestsRails.configuration.experimental_features config.include(Helper, type: :feature, unit: true) end end end |
.configure_webmock ⇒ Object
11 12 13 14 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 11 def configure_webmock WebMock.disable_net_connect!(allow_localhost: true) log 'WebMock configured to allow localhost connections' end |
.ensure_server_ready(context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 16 def ensure_server_ready(context) return if @server_ready log "Waiting for server on #{::Capybara.app_host.presence || 'localhost'} to start..." configuration = IntegrationTestsRails.configuration server_retries = configuration.max_server_retries server_retries.times do |attempt| if configuration.experimental_features context.visit('/tests') else context.visit('/') end @server_ready = true log 'Server is ready!' break rescue StandardError log "Server not ready (attempt #{attempt + 1}/#{server_retries})." end log "Server did not start after #{server_retries} attempts..." unless @server_ready end |
.log(message) ⇒ Object
68 69 70 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 68 def log() puts "[CAPYBARA] #{message}" if verbose? end |
.verbose? ⇒ Boolean
64 65 66 |
# File 'lib/integration_tests_rails/capybara/util.rb', line 64 def verbose? IntegrationTestsRails.configuration.verbose end |