Skip to content

Commit

Permalink
Set up RSpec for testing with GOV.UK conventions
Browse files Browse the repository at this point in the history
 - Add `rspec-rails` and `govuk_test` gems
 - Set up RSpec configuration with sensible initial defaults and GOV.UK
   conventions from Developer Docs
  • Loading branch information
csutter committed Aug 25, 2023
1 parent 8bd0a54 commit 2eedb9c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# RSpec run persistence (for e.g. --only-failures)
spec/examples.txt

# Simplecov
/coverage/*
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ gem "activesupport", RAILS_GEMS_VERSION

gem "puma", "~> 5.0"

group :test do
gem "simplecov", require: false
end

group :development, :test do
gem "debug", platforms: %i[ mri mingw x64_mingw ]
gem "govuk_test"
gem "rspec-rails"
end
58 changes: 58 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,32 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
brakeman (6.0.1)
builder (3.2.4)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.2.2)
crass (1.0.6)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
govuk_test (3.0.1)
brakeman (>= 5.0.2)
capybara (>= 3.36)
puma
selenium-webdriver (>= 4.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
Expand All @@ -36,11 +55,14 @@ GEM
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.19.0)
nio4r (2.5.9)
nokogiri (1.15.4-aarch64-linux)
racc (~> 1.4)
public_suffix (5.0.3)
puma (5.6.7)
nio4r (~> 2.0)
racc (1.7.1)
Expand All @@ -62,11 +84,44 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
regexp_parser (2.8.1)
reline (0.3.8)
io-console (~> 0.5)
rexml (3.2.6)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.3)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubyzip (2.3.2)
selenium-webdriver (4.11.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
thor (1.2.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
websocket (1.2.9)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.11)

PLATFORMS
Expand All @@ -77,8 +132,11 @@ DEPENDENCIES
activemodel (= 7.0.7.2)
activesupport (= 7.0.7.2)
debug
govuk_test
puma (~> 5.0)
railties (= 7.0.7.2)
rspec-rails
simplecov

RUBY VERSION
ruby 3.2.2p53
Expand Down
32 changes: 32 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ENV["RAILS_ENV"] ||= "test"

require "simplecov"
SimpleCov.start "rails"

require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
GovukTest.configure

# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.default_formatter = "doc" if config.files_to_run.one?
config.disable_monkey_patching!
config.example_status_persistence_file_path = "spec/examples.txt"
config.expose_dsl_globally = false
config.infer_spec_type_from_file_location!
config.profile_examples = 10
config.shared_context_metadata_behavior = :apply_to_host_groups # Preempting v4 default

config.order = :random
Kernel.srand config.seed

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true # Preempting v4 default
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true # Preempting v4 default
end
end

0 comments on commit 2eedb9c

Please sign in to comment.