Skip to content

test: Switch to Minitest Test Doubles#2146

Draft
arielvalentin wants to merge 4 commits intoopen-telemetry:mainfrom
arielvalentin:fix/minitest-6-minitest-mock
Draft

test: Switch to Minitest Test Doubles#2146
arielvalentin wants to merge 4 commits intoopen-telemetry:mainfrom
arielvalentin:fix/minitest-6-minitest-mock

Conversation

@arielvalentin
Copy link
Copy Markdown
Contributor

@arielvalentin arielvalentin commented Mar 30, 2026

⚠️ This PR was generated using copilot

The tests are currently failing with System Stack errors. This PR is a placeholder for what it would look like if we chose minitest mocks over rspec.

AI Generated comments below

Minitest 6 extracted test doubles into its own gem (minitest-mock).

This is an alternative approach to #2011 (which used rspec-mocks) for comparison purposes. Instead of adding rspec-mocks, this PR uses the official minitest-mock gem — the extracted version of Minitest's built-in mock/stub functionality.

cc: #1908

Changes

  • Replace rspec-mocks ~> 3.13.7 with minitest-mock ~> 5.0 in 30 Gemfiles
  • Update 29 test_helper.rb files to require 'minitest/mock' instead of rspec/mocks/minitest_integration
  • Convert all allow/expect RSpec Mocks patterns to Minitest stub blocks across 25 test files

Conversion Patterns

RSpec Mocks minitest-mock
allow(X).to receive(:m).and_return(v) X.stub(:m, v) { ... }
allow(X).to receive(:m) { block } X.stub(:m, ->() { block }) { ... }
expect(X).not_to receive(:m) X.stub(:m, ->(*) { flunk }) { ... }
expect(X).to receive(:m).exactly(N).times Counter variable + assert_equal N, count
and_wrap_original Capture .method(:name) + lambda stub
and_call_original Implicit via stub block scope

Trade-offs vs #2011 (RSpec Mocks)

Pros:

  • Stays within the Minitest ecosystem — no RSpec dependency
  • minitest-mock is the official extraction maintained by the Minitest team
  • Same API as Minitest 5's built-in stubs (familiar to existing contributors)

Cons:

  • Block-scoped stubs increase nesting (each stub wraps remaining test code)
  • No built-in spy/verification — requires manual tracking variables
  • No and_wrap_original equivalent — requires capturing .method(:name) manually

For Reviewers

The main structural difference is block-scoped stubs. I recommend reviewing with Hide whitespace changes:

https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/new/fix/minitest-6-minitest-mock?w=1

arielvalentin and others added 3 commits March 28, 2026 21:54
…lpers

Swap gem dependency from rspec-mocks ~> 3.13.7 to minitest-mock ~> 1.0
in all 30 affected Gemfiles. Update 29 test_helper.rb files to require
minitest/mock instead of rspec/mocks/minitest_integration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… and sidekiq tests

Replace allow/expect RSpec mock patterns with Minitest::Mock stub blocks:
- allow(...).to receive(...).and_return(...) → .stub(:method, value) { ... }
- expect(...).not_to receive(...) → .stub(:method, ->(*) { flunk ... }) { ... }
- expect(...).to receive(...).exactly(N).times → counter + assert_equal
- expect(...).to receive(...).with(...) → lambda with assertions
- allow(...).to receive(...).and_raise(...) → .stub(:method, -> { raise }) { ... }

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace all allow/expect RSpec Mocks usage with Minitest's block-scoped
stub API from the minitest-mock gem across 25 test files in 21 gems.

Key conversion patterns:
- allow(X).to receive(:m).and_return(v) → X.stub(:m, v) { ... }
- allow(X).to receive(:m) { block } → X.stub(:m, ->() { block }) { ... }
- expect(X).not_to receive(:m) → X.stub(:m, ->(*) { flunk }) { ... }
- and_wrap_original → capture original method, stub with lambda
- and_call_original → implicit via stub block scope

Also fixes minitest-mock version constraint to ~> 5.0 (matching
minitest's version scheme for the extracted gem).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants