.vbw-planning/milestones/07-rails-audit-and-refactoring/06-test-infrastructure/04-PLAN.md
1. Mocking Approach (T7)
.stub for all mocking needsObject.stub(:method, return_value) { block } -- method stubs on existing objects/classes2. Test Naming (T14)
3. Job Testing (T12)
:test -- jobs are enqueued but not performedassert_enqueued_with(job: JobClass) to verify enqueueingwith_inline_jobs { } when you need jobs to execute (integration/system tests)with_queue_adapter(:async) only for specific async behavior tests:test, system/integration tests use with_inline_jobs4. WebMock Stub Patterns (T8)
file_fixture for response bodies (not inline strings)stub_feed_request(url:, fixture:, status: 200)5. Time Travel
travel_to(time) { ... } (auto travel_back)ensure travel_back to the test method6. Test Isolation
SourceMonitor.reset_configuration! is handled automatically in setupKeep it concise (under 150 lines). Reference test/support/ modules and test_helper.rb for implementation details. </action> <verify> test -f test/TEST_CONVENTIONS.md (file exists) wc -l test/TEST_CONVENTIONS.md reports under 200 lines </verify> <done> TEST_CONVENTIONS.md exists with sections on mocking, naming, job testing, WebMock stubs, time travel, and isolation </done> </task> <task type="auto"> <name>Refactor advisory_lock_test mocking</name> <files> test/lib/source_monitor/fetching/advisory_lock_test.rb </files> <action> Read the advisory_lock_test.rb file. Refactor Class.new anonymous mocking patterns to use Minitest .stub where feasible:
fake_connection = Class.new { def exec_query(sql)... end }.new with a stub approachGoal: demonstrate the preferred mocking pattern, not rewrite every mock in the codebase. </action> <verify> PARALLEL_WORKERS=1 bin/rails test test/lib/source_monitor/fetching/advisory_lock_test.rb -- all tests pass </verify> <done> advisory_lock_test.rb uses consistent mocking patterns with comments explaining the approach </done> </task> <task type="auto"> <name>Consolidate feed_fetcher_test_helper stubs</name> <files> test/lib/source_monitor/fetching/feed_fetcher_test_helper.rb </files> <action> Read test/lib/source_monitor/fetching/feed_fetcher_test_helper.rb.
stub_feed_request(url:, fixture: "feeds/rss_sample.xml", status: 200, headers: {}) -- if not already presentstub_feed_timeout(url:) -- stubs request to raise Faraday::TimeoutErrorstub_feed_not_found(url:) -- stubs 404 responseThis file is already a shared helper -- the goal is to improve it, not create a new one. </action> <verify> PARALLEL_WORKERS=1 bin/rails test test/lib/source_monitor/fetching/ -- all fetching tests pass </verify> <done> feed_fetcher_test_helper.rb has documented, reusable WebMock stub helpers following conventions </done> </task> </tasks> <verification>
<success_criteria>
04-SUMMARY.md </output>