test: Switch to Minitest Test Doubles#2146
Draft
arielvalentin wants to merge 4 commits intoopen-telemetry:mainfrom
Draft
test: Switch to Minitest Test Doubles#2146arielvalentin wants to merge 4 commits intoopen-telemetry:mainfrom
arielvalentin wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 addingrspec-mocks, this PR uses the officialminitest-mockgem — the extracted version of Minitest's built-in mock/stub functionality.cc: #1908
Changes
rspec-mocks ~> 3.13.7withminitest-mock ~> 5.0in 30 Gemfilestest_helper.rbfiles torequire 'minitest/mock'instead ofrspec/mocks/minitest_integrationallow/expectRSpec Mocks patterns to Miniteststubblocks across 25 test filesConversion 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 }) { ... }expect(X).to receive(:m).exactly(N).timesassert_equal N, countand_wrap_original.method(:name)+ lambda stuband_call_originalTrade-offs vs #2011 (RSpec Mocks)
Pros:
minitest-mockis the official extraction maintained by the Minitest teamCons:
and_wrap_originalequivalent — requires capturing.method(:name)manuallyFor 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