Skip to content

1. Testing

Armando Fox edited this page Feb 17, 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.

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.)