Skip to content

Add SimpleCov and expand test coverage - #19

Open
benrfairless wants to merge 1 commit into
chore/upgrade-rubyfrom
chore/increase-test-coverage
Open

Add SimpleCov and expand test coverage#19
benrfairless wants to merge 1 commit into
chore/upgrade-rubyfrom
chore/increase-test-coverage

Conversation

@benrfairless

@benrfairless benrfairless commented Aug 12, 2026

Copy link
Copy Markdown
Member

Description

Adds real test coverage to the gem, which previously only had smoke tests for two pure helper methods:

  • SimpleCov with branch coverage and a 90% minimum threshold (suite currently measures 97.5% line / 95.8% branch)
  • WebMock with all network access disabled in specs — HTTP behaviour is tested against stubs, never the real morph.io
  • The Thor CLI class is extracted from bin/morph into MorphCLI::CLI (lib/morph-cli/cli.rb) so it can be loaded and tested; bin/morph becomes a thin wrapper with identical behaviour
  • New specs cover: MorphCLI.execute (streaming run output, multipart upload of API key + code, 401 handling, missing-scraper exit), the CLI (version, --dev config selection, API key prompt/save/retry, connection/server/client error exits), log stream routing, config save/load round-trip and 0600 permissions, tar creation and read-back, directory sizing, and in_directory restoration
  • Spec files excluded from Metrics/BlockLength (standard RuboCop practice)

Motivation and Context

The CLI commands and all API interaction were completely untested, which makes upgrades like #18 risky. This locks in behaviour before further changes, without hitting the network in tests.

How Has This Been Tested?

  • Checked affected area manually on my own / staging system
  • Ran automated tests on my own system
  • Confirmed it passed the GitHub actions tests

On Ruby 3.2.2: bundle exec rspec — 29 examples, 0 failures; bundle exec rubocop — no offenses; manual smoke test of bin/morph version.

Screenshots (if appropriate):

N/A

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation

Test/refactor only; no behaviour change to the shipped CLI.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Part 3 of the 5-PR modernisation series. Stacked on #18 (base branch chore/upgrade-ruby); GitHub will retarget as the stack merges.

Assisted-by: opencode/anthropic.claude-fable-5

@benrfairless benrfairless self-assigned this Aug 12, 2026
@benrfairless
benrfairless marked this pull request as ready for review August 12, 2026 01:56
@benrfairless
benrfairless force-pushed the chore/increase-test-coverage branch from 1af7e36 to c0d19a1 Compare August 12, 2026 03:00
@benrfairless
benrfairless requested a review from a team as a code owner August 12, 2026 03:00

@ianheggie-oaf ianheggie-oaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved - LGTM at a glance

@benrfairless
benrfairless force-pushed the chore/increase-test-coverage branch from c0d19a1 to d8e22a4 Compare August 12, 2026 03:51
Adds meaningful coverage for the parts of the gem that previously had
none: the HTTP interaction with the Morph server and the Thor command
line interface.

- Add SimpleCov with branch coverage and a 90% minimum; the suite
  currently measures 97.5% line / 95.8% branch coverage
- Add WebMock and disable all network access in specs
- Extract the Thor CLI class from bin/morph into MorphCLI::CLI in
  lib/morph-cli/cli.rb so it is loadable (and therefore testable);
  bin/morph is now a thin wrapper with unchanged behaviour
- Spec MorphCLI.execute against stubbed HTTP: streams run output,
  posts the API key and code as multipart form data, raises on 401,
  exits when no scraper file is present
- Spec the CLI: version command, --dev config selection, API key
  prompting/saving, retry on rejected key, and exit paths for
  connection, server and client errors
- Spec log stream routing, config save/load round-trip and
  permissions, tar creation/read-back, directory sizing and
  in_directory restoration
- Exclude spec files from Metrics/BlockLength (standard practice)

29 examples, 0 failures on Ruby 3.4.10; RuboCop clean.

Assisted-by: opencode/anthropic.claude-fable-5
Signed-off-by: Ben Fairless <ben@oaf.org.au>
@benrfairless
benrfairless force-pushed the chore/increase-test-coverage branch from d8e22a4 to 87ae319 Compare August 13, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants