Comments (2)
Minitest has never had a plural stubs
method. Nor has it ever had a returns
method. So upgrading must have gotten rid of some dependency you were using.
Minitest documentation is here: https://docs.seattlerb.org/minitest/README_rdoc.html#label-Stubs which says:
Minitest’s stub method overrides a single method for the duration of the block.
and is kinda the whole point. If you need to stub that much out of the gate to test something, that should be considered a smell. You're probably testing at the wrong level or your code isn't designed to be easily testable.
from minitest.
As this is an integration test, I am not convinced that it's a code smell, since there are a bunch of external services that need to be stubbed.
As for the Minitest docs, I'm not sure if there's more to the docs regarding stubs - the only thing I see is a single statement and example, which suggests that the only way to stub is indeed with a block.
# Minitest’s stub method overrides a single method for the duration of the block
Time.stub :now, Time.at(0) do # stub goes away once the block is done
assert obj_under_test.stale?
end
I appreciate your response nonetheless, as you saying "upgrading must have gotten rid of some dependency you were using" got me thinking, and I realized that no, upgrading did not do that. I looked harder, and ended up figuring out what the plural stubs
is - it's Mocha's stubs
. I realize that I misled you by saying that "I upgraded and now there's an error" - and I am sorry for that (in retrospect, I didn't realize exactly what was happening).
The problem was that when I was running this single test on its own, it was failing with undefined method 'stubs'
because there was no require 'mocha/minitest'
in that file (I guess the test wasn't failing when the entire test suite was run because mocha/minitest
was require
'd elsewhere in the test suite). Anyway, I added require 'mocha/minitest'
and now the test is passing when run on its own, and it looks much nicer than the nested way:
Users::ContactBuilderJob.stubs(:call).returns(true)
AnotherModel::JobOne.stubs(:call).returns(true)
AnotherModel::JobTwo.stubs(:call).returns(true)
AnotherModel::JobThree.stubs(:call).returns(true)
# assertions
Note that until I figured this out I had temporarily used the nested stubbing way of native Minitest, and indeed it worked just the same. The only difference is aesthetic.
I appreciate that stub goes away once the block is done. This is a noteworthy feature.
from minitest.
Related Issues (20)
- test
- MFA is required on your rubygems.org account HOT 3
- Duplicate class names cause issues HOT 3
- How to ignore extra kwargs in expect? HOT 1
- Mock#expect unexpected behavior with Hash argument HOT 1
- MiniTest::Mock and the debug gem HOT 1
- Why "Use assert_nil if expecting nil"? HOT 2
- Create setup array equivalent to `TEARDOWN_METHODS`? HOT 5
- wrong number of arguments (given 2, expected 1) (ArgumentError) using Mock with delegator HOT 3
- Unable to stub the aliased module method (to catch its call) HOT 1
- TypeError (no implicit conversion of nil into Integer) HOT 2
- A reporter added to the end of a CompositeReporter doesn't appear to be getting called HOT 10
- Minitest with JRuby HOT 7
- Minitest stub implementation changes a method's lookup to be on metaclass always
- #assert_all support HOT 4
- How to run skipped test? if I don't want to comment "skip" HOT 5
- `-n /reg exp/` not working for me HOT 7
- JUnitReporter seems to silence seed HOT 2
- Make Minitest::Result extendable HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minitest.