Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Add smoke_test environment
Browse files Browse the repository at this point in the history
This new environment will be used for smoke testing only.
E.g. RAILS_ENV=smoke_test TEST_URL=... bundle exec rake spec:features

A new environment is required since RSpec requires a DB to be running
and connected to in order to run the tests. We could delete the constant
ActiveRecord e.g. Object.send(:remove_const, :ActiveRecord), but I decided
to use a new env that doesn't load it instead.

Alternative approaches:
- We could use https://github.com/nulldb/nulldb rather than not requiring
  ActiveRecord
- There might be a way to use rspec/rspec-rails#2266
  but I don't think it helps our situations, since we do need ActiveRecord.
  • Loading branch information
Bill Franklin committed Apr 14, 2020
1 parent f334af7 commit 7d5925c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 15 deletions.
4 changes: 2 additions & 2 deletions concourse/pipeline.yml
Expand Up @@ -17,7 +17,7 @@ resources:
icon: github-circle
source:
uri: https://github.com/alphagov/govuk-coronavirus-business-volunteer-form
branch: master
branch: bilbof/fix-smoke-test-2

- name: govuk-coronavirus-business-volunteer-form-travis-build
type: travis
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
- task: run-smoke-tests
file: govuk-coronavirus-business-volunteer-form/concourse/tasks/run-smoke-tests.yml
params:
TEST_URL: 'https://coronavirus-business-volunteers.service.gov.uk/medical-equipment'
TEST_URL: 'https://coronavirus-business-volunteers.service.gov.uk'

- name: export-form-responses-periodically
plan:
Expand Down
3 changes: 2 additions & 1 deletion concourse/tasks/run-smoke-tests.yml
Expand Up @@ -6,9 +6,10 @@ image_resource:
tag: govuk-coronavirus-business-volunteer-form-feature-tests
params:
TEST_URL:
RAILS_ENV: smoke_test
inputs:
- name: govuk-coronavirus-business-volunteer-form
run:
path: bundle
dir: govuk-coronavirus-business-volunteer-form
args: ['exec', 'rake', 'spec:features']
args: ['exec', 'rspec', 'spec/features']
4 changes: 3 additions & 1 deletion config/application.rb
Expand Up @@ -6,7 +6,9 @@
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# Disables ActiveRecord for smoke tests:
# https://github.com/rspec/rspec-rails/blob/a769a4d37a65bb911c6774450e23568b5cf78f08/lib/rspec/rails/feature_check.rb#L11
require "active_record/railtie" unless ENV["RAILS_ENV"] == "smoke_test"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
Expand Down
38 changes: 38 additions & 0 deletions config/environments/smoke_test.rb
@@ -0,0 +1,38 @@
# frozen_string_literal: true

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!

Rails.application.configure do
# Settings specified here will take precedence over those in
# config/application.rb.

config.cache_classes = true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.to_i}",
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
end
10 changes: 7 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -15,7 +15,11 @@
Capybara.javascript_driver = :apparition

RSpec.configure do |config|
config.expose_dsl_globally = false
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = true
if ENV["RAILS_ENV"] == "smoke_test"
config.use_active_record = false
else
config.expose_dsl_globally = false
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = true
end
end
18 changes: 10 additions & 8 deletions spec/support/env.rb
Expand Up @@ -5,13 +5,6 @@

test_url = ENV["TEST_URL"]

if test_url
Capybara.app_host = test_url
Capybara.run_server = false
else
Capybara.server = :puma, { Silent: true }
end

Capybara.register_driver :apparition do |app|
options = { browser_options: {}, timeout: 10, skip_image_loading: true }
if ENV.key? "CHROME_NO_SANDBOX"
Expand All @@ -21,11 +14,20 @@
end

Capybara.javascript_driver = :apparition
Capybara.use_default_driver
Capybara.default_max_wait_time = 10
Capybara.exact = true
Capybara.match = :one

Capybara.configure do |config|
config.automatic_label_click = true
end

if test_url
Capybara.default_driver = Capybara.javascript_driver
Capybara.app_host = test_url
Capybara.run_server = false
else
Capybara.server = :puma, { Silent: true }
end

Capybara.use_default_driver

0 comments on commit 7d5925c

Please sign in to comment.