samhuri.net/test/coverage_test.rb
Sami Samhuri fc68fc58af Extract bake logic into lib/pressa and fold tasks back into one bake.rb
Pull the pure, testable logic out of the bake tasks into Pressa modules:

- Pressa::Drafts — slugs, ordinal dates, draft paths, and the new-draft template
- Pressa::Coverage — the coverage measurement script, output parsing, and baseline-ref resolution
- Pressa::Publish — the rsync command builder

Each gets its own tests, so this logic now sits under the lib/ coverage gate
instead of being untested glue inside the task files.

With the logic extracted, the namespaced bake/ split no longer earns its keep —
those files were mostly thin task declarations. Collapse build/draft/publish/quality
back into a single bake.rb with the original flat task names (new_draft, coverage,
publish_beta, and so on) and update CI and AGENTS.md to match.
2026-06-07 17:57:01 -07:00

41 lines
1.6 KiB
Ruby

require "test_helper"
class Pressa::CoverageTest < Minitest::Test
def test_parse_percent_extracts_the_lib_coverage_figure
output = "Coverage (lib): 98.89% (1597 / 1615 lines)\nLowest covered files:\n"
assert_in_delta(98.89, Pressa::Coverage.parse_percent(output), 0.0001)
end
def test_parse_percent_raises_when_the_marker_is_missing
error = assert_raises(Pressa::Coverage::Error) { Pressa::Coverage.parse_percent("nothing useful here") }
assert_match(/unable to parse/, error.message)
end
def test_script_filters_to_lib_and_reports_the_lib_marker
script = Pressa::Coverage.script(lowest_count: 10)
assert_match(/lib_root/, script)
assert_match(/Coverage \(lib\):/, script)
end
def test_script_interpolates_the_lowest_count
assert_match(/unless 0\.zero\?/, Pressa::Coverage.script(lowest_count: 0))
assert_match(/unless 5\.zero\?/, Pressa::Coverage.script(lowest_count: 5))
end
def test_resolve_baseline_ref_returns_explicit_ref_without_yielding
yielded = false
ref = Pressa::Coverage.resolve_baseline_ref("v1.2.3") { yielded = true }
assert_equal("v1.2.3", ref)
refute(yielded, "merge-base block should not run for an explicit ref")
end
def test_resolve_baseline_ref_yields_for_merge_base
ref = Pressa::Coverage.resolve_baseline_ref("merge-base") { "abc1234" }
assert_equal("abc1234", ref)
end
def test_resolve_baseline_ref_rejects_blank_baselines
error = assert_raises(Pressa::Coverage::Error) { Pressa::Coverage.resolve_baseline_ref(" ") {} }
assert_match(/cannot be empty/, error.message)
end
end