Skip to content

#2 stub WTS HTTP calls with webmock#62

Open
kreinba wants to merge 1 commit into
zold-io:masterfrom
kreinba:2-unit-tests-webmock
Open

#2 stub WTS HTTP calls with webmock#62
kreinba wants to merge 1 commit into
zold-io:masterfrom
kreinba:2-unit-tests-webmock

Conversation

@kreinba

@kreinba kreinba commented Jun 9, 2026

Copy link
Copy Markdown

Issue #2 asks for webmock-based unit tests because the existing suite reaches the live WTS at https://wts.zold.io for every test. The existing tests call WebMock.allow_net_connect!, so any failure or latency on the third-party host produces a red CI run, and the suite cannot be relied on as a unit-level signal for the code in lib/zold/wts.rb.

This change replaces the live calls in test/zold/test_wts.rb with webmock stubs covering /pull, /job?id=..., /balance, /id, /find?..., and /usd_rate, and moves WebMock.disable_net_connect! into a setup hook so no test can leak to the network. The eight existing tests still cover the same code paths in Zold::WTS and Zold::WTS::Fake, but each one now finishes in milliseconds and never depends on wts.zold.io being reachable.

Locally on Ruby 3.3.6: bundle exec rake test runs all 8 tests in under one second with 0 failures and 86.67% line coverage; the previous run on master took roughly 24 seconds against the live host. The rake rubocop step exhibits the same rubocop-rspec_rails inject_defaults! failure as master, so this branch does not introduce a new lint failure.

Closes #2

Replace the live calls to https://wts.zold.io with webmock stubs so the
test suite no longer depends on the network or on the live WTS service.
The previous tests called WebMock.allow_net_connect! and reached the
real endpoint for every assertion, turning the suite into an integration
test against a third-party host and lengthening every run to roughly 24
seconds; with the stubs the same eight tests now finish in well under a
second and exercise the same code paths.

Closes zold-io#2

@edmoffo edmoffo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Closes #2 cleanly. Each of the eight existing tests in test/zold/test_wts.rb now runs against a webmock stub for the WTS endpoint it touches, and setup pins WebMock.disable_net_connect! at the class level so no test can leak to wts.zold.io. Local bundle exec rake test runs all 8 tests in 0.03s with 0 failures and 86.67% line coverage, matching the numbers in the PR body. The four red CI checks on this branch (rubocop-rspec_rails inject_defaults, markdown-lint on README.md, criterias typo, yamllint) are also red on master at 7c79029, so this diff does not introduce them. No inline comments.

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.

unit tests

3 participants