Skip to content

1. Testing

Armando Fox edited this page Sep 26, 2024 · 4 revisions

Running tests locally

There is a set of Cucumber+Capybara scenarios that test all major user-facing flows and most boxoffice-facing flows, and additional specs to fill gaps. The current configuration uses CodeClimate Test Reporter (CCTR) as part of the CI workflow which runs using GitHub Actions, and reports combined Cucumber + RSpec coverage to CodeClimate to serve the coverage badge.

Scenarios using JavaScript use Google Chrome For Testing and Chromedriver to drive a headless Chrome browser. The setup for this is in features/support/env.rb. This means the correct versions of Chrome For Testing and Chromedriver must be installed on the machine running the tests. Essentially what happens is this:

  • If GITHUB_ACTIONS_CHROME_FOR_TESTING_PATH and/or GITHUB_ACTIONS_CHROMEDRIVER_PATH are set, they are used as the paths to each of those binaries. The GitHub ci.yml workflow sets these variables.

  • Otherwise, it will expect to find these binaries in RAILS_ROOT/tmp/, with the names chromedriver and Google Chrome for Testing (the latter is an unfortunate MacOS-specific artifact). To install them, cd RAILS_ROOT/tmp/ and then run

npx @puppeteer/browsers install chrome@stable
npx @puppeteer/browsers install chromedriver@stable

Test database

The versioned file config/database.yml.test specifies a SQLite3 database for testing. Once you have created a proper config/application.yml as described on the main page, you should be able to successfully run all scenarios and all specs. A local run takes 12-15 minutes to run all tests.

Do not version config/application.yml but instead use gpg or pgp to symmetrically encrypt it to config/application.yml.asc, and version the encrypted file. You will use the encryption key below in the CI setup.

Time

Many features depend on the current time (to test things like reservation cutoffs, etc.) All Cucumber scenarios fix the current date and time as Jan 1, 2010, 00:00:00 in the application timezone in features/support/env.rb. To suppress this for certain scenarios, tag them with @time.

Stubbing credit card payments

Most scenarios that test payments do stubbing (in env.rb) at the level of the Store methods that wrap calls to Stripe. A few scenarios use the FakeStripe gem.

GitHub Actions setup

The GitHub Actions CI workflow (.github/workflows/ci.yml), which normally runs on push, does the following: install libxslt (needed for XML parsing by various gems); install Ruby; create database.yml by using the contents of database.yml.test; decrypt the file config/application.yml.asc using the decryption key GPG_SYMMETRIC_KEY; run all features & specs while capturing test coverage; report test coverage to CodeClimate using the CC_TEST_REPORTER_ID key.

The things in bold are GitHub Secrets you have to set up in the repo's Settings > Secrets and variables > Actions > Repository secrets.

The value of GPG_SYMMETRIC_KEY should be the keyphrase you used to symmetrically encrypt your application.yml into application.yml.asc.

The value of CC_TEST_REPORTER_ID should be the key assigned to you when you setup CodeClimate and link your development repo to it for test reporting. The CodeClimate website has a section explaining how to generate this key. (Note: CodeClimate now has two products, "CodeClimate Quality" and "CodeClimate Velocity". Test coverage info is collected in Quality, so create an account there---it should be free for open source projects---and link your development repo to that account.)