From 104ec6c8bc6501002d1b6a9da2b6265b33a9f17b Mon Sep 17 00:00:00 2001 From: Christian Sutter Date: Tue, 28 Nov 2023 12:19:53 +0000 Subject: [PATCH] Add basic testing scaffold --- .github/workflows/ci.yml | 27 ++++++++++++++++++++++++- Gemfile | 5 +++++ Gemfile.lock | 20 ++++++++++++++++++ test/application_system_test_case.rb | 5 +++++ test/fixtures/files/.keep | 0 test/integration/.keep | 0 test/system/.keep | 0 test/system/submitting_feedback_test.rb | 20 ++++++++++++++++++ test/test_helper.rb | 23 +++++++++++++++++++++ 9 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 test/application_system_test_case.rb create mode 100644 test/fixtures/files/.keep create mode 100644 test/integration/.keep create mode 100644 test/system/.keep create mode 100644 test/system/submitting_feedback_test.rb create mode 100644 test/test_helper.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c50783b..29ace22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Gemfile b/Gemfile index c14d9d8..952d32e 100644 --- a/Gemfile +++ b/Gemfile @@ -23,3 +23,8 @@ end group :development do gem "web-console" end + +group :test do + gem "capybara" + gem "selenium-webdriver" +end diff --git a/Gemfile.lock b/Gemfile.lock index e243720..fadcbe5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -575,6 +593,7 @@ PLATFORMS DEPENDENCIES brakeman + capybara debug gds-api-adapters google-cloud-bigquery @@ -584,6 +603,7 @@ DEPENDENCIES rails (~> 7.1.2) rubocop-govuk sassc-rails + selenium-webdriver sprockets-rails web-console diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..53ef83e --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :chrome_headless +end diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/system/submitting_feedback_test.rb b/test/system/submitting_feedback_test.rb new file mode 100644 index 0000000..324c7a7 --- /dev/null +++ b/test/system/submitting_feedback_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..87bf894 --- /dev/null +++ b/test/test_helper.rb @@ -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