Skip to content

Commit

Permalink
Merge pull request #27 from alphagov/basic-testing
Browse files Browse the repository at this point in the history
Add basic testing scaffold
  • Loading branch information
csutter authored Nov 28, 2023
2 parents 3bcb709 + 104ec6c commit 2cd9722
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 1 deletion.
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,36 @@ jobs:
dependency-review:
name: Dependency Review scan
uses: alphagov/govuk-infrastructure/.github/workflows/dependency-review.yml@main

lint-ruby:
name: Lint Ruby
uses: alphagov/govuk-infrastructure/.github/workflows/rubocop.yml@main

test-ruby:
name: Test Rails
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Precompile assets
uses: alphagov/govuk-infrastructure/.github/actions/precompile-rails-assets@main

- name: Run unit tests
env:
RAILS_ENV: test
run: bin/rails test

- name: Run system tests
env:
RAILS_ENV: test
run: bin/rails test:system

security-analysis:
name: Security Analysis
uses: alphagov/govuk-infrastructure/.github/workflows/brakeman.yml@main
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ end
group :development do
gem "web-console"
end

group :test do
gem "capybara"
gem "selenium-webdriver"
end
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ GEM
bindex (0.8.1)
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)
connection_pool (2.4.1)
crass (1.0.6)
Expand Down Expand Up @@ -197,6 +206,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
matrix (0.4.2)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.1003)
Expand Down Expand Up @@ -523,6 +533,7 @@ GEM
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
Expand All @@ -531,6 +542,10 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (4.15.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-rails (5.14.0)
railties (>= 5.0)
sentry-ruby (~> 5.14.0)
Expand Down Expand Up @@ -564,9 +579,12 @@ GEM
bindex (>= 0.4.0)
railties (>= 6.0.0)
webrick (1.8.1)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.12)

PLATFORMS
Expand All @@ -575,6 +593,7 @@ PLATFORMS

DEPENDENCIES
brakeman
capybara
debug
gds-api-adapters
google-cloud-bigquery
Expand All @@ -584,6 +603,7 @@ DEPENDENCIES
rails (~> 7.1.2)
rubocop-govuk
sassc-rails
selenium-webdriver
sprockets-rails
web-console

Expand Down
5 changes: 5 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :chrome_headless
end
Empty file added test/fixtures/files/.keep
Empty file.
Empty file added test/integration/.keep
Empty file.
Empty file added test/system/.keep
Empty file.
20 changes: 20 additions & 0 deletions test/system/submitting_feedback_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "application_system_test_case"

class SubmittingFeedbackTest < ApplicationSystemTestCase
test "viewing the homepage" do
visit "/"
skip("Implement me")
end

test "making a search" do
skip("Implement me")
end

test "submitting valid feedback" do
skip("Implement me")
end

test "submitting feedback with invalid suggested URL" do
skip("Implement me")
end
end
23 changes: 23 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"

Capybara.register_driver :chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new

options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--window-size=1400,1400")

Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end

module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)

# Add more helper methods to be used by all tests here...
end
end

0 comments on commit 2cd9722

Please sign in to comment.