Skip to content

Running Specs and Linting

Peter Goldstein edited this page Jan 22, 2023 · 4 revisions

Running Specs

To ensure correctness Asimov includes a comprehensive test suite that is intended to test both "happy path" and error behavior.

This gem aims for ~100% spec coverage, so please make sure to add specs for any new functionality.

The Asimov specs can be run in two modes:

  1. Local - No OpenAI API calls will be made
  2. Live - Calls the OpenAI API and processes the responses as part of the run

Local Mode

To run specs in local mode, do the following:

  1. Run bin/setup (you will only need to do this once)
  2. Run bundle exec rake

This mode for specs uses VCR cassettes to replay previous responses from the OpenAI API.

When submitting a PR, please run specs in local mode on your machine or on your fork to ensure that they run green.

Live Mode

To run specs in local mode, do the following:

  1. Run bin/setup (you will only need to do this once)
  2. Set RUN_LIVE=true in the environment
  3. Set OPENAI_API_KEY to a valid OpenAI API key.
  4. Run bundle exec rake

This mode for specs will make live calls to the OpenAI API. The cost for these calls should be a few cents per full spec run.

You can do this all in one call by running:

RUN_LIVE=true OPENAI_API_KEY=<Your API key here> bundle exec rake

Only feature specs (those in the spec/features directory) will make OpenAI API calls. Rather than running the full suite, you can run individual feature spec files or specs by using bundle exec rspec ... with the appropriate argument.

Running feature specs in this mode will refresh existing cassettes.

Linting

To help ensure a consistent style across the gem, Asimov includes a linter in its CI pipeline. Use of a linter not only enforces consistent styling, but also helps ensure against certain classes of error.

Asimov uses Rubocop for linting, and by default uses the default configuration for all Cops. New Cops are automatically included.

To run Rubocop, do the following:

  1. Run bin/setup (you will only need to do this once)
  2. Run bundle update rubocop to ensure you are bundling with the latest Rubocop
  3. Run bundle exec rubocop

When submitting a PR, please run Rubocop beforehand to make sure there are no outstanding lints that need to be addressed. If you'd like to make a change to Rubocop behavior - either by updating the .rubocop.yml or by adding an inline disable/enable, please note that in the PR description.