Minitest Moar
Some changes to Minitest and additional features
Looking for help?
If it is a bug please open an issue on GitHub.
About
Stub
By default Minitest pollutes Object
with Object#stub
. This gem
removes Object#stub
and relaces with a method that is intended to be
used:
stub Book, :read, true do
# do your thing
end
No moar object pollution!
Instance stubbing
Minitest doesn't come with any way to stub the instance of a class. Minitest Moar does:
instance_stub Person, :say, "hello" do
person = Person.new
# this is the stubbed method
person.say
end
Test Spies
Note that test spies only work on stubbed methods.
A common pattern might be to confirm if an object calls a method. You can current do this with stubbing:
@called = 0
caller = Proc.new { @called += 1 }
stub Book, :read, caller do
Book.read
end
assert_equal 1, @called
With Minitest Moar you get test spies in the form of assert_called
:
stub Book, :read do
Book.read
end
assert_called Book, :read
You can assert the number of invocations with the optional 3rd argument
stub Book, :read do
Book.read
Book.read
end
assert_called Book, :read, 2
You can refute
stub Book, :read do
person = Person.new
person.say
end
refute_called Book, :read
And you can refute the number of invocations:
stub Book, :read do
Book.read
end
refute_called Book, :read, 2
Spying on instances
If you don't have access to the instance of the object in your test you
can spy on the instance of a class with assert_instance_called
and
refute_instance_called
instance_stub Person, :say, "hello" do
person = Person.new
person.say
end
assert_instance_called Person, :say
instance_stub Person, :say, "hello" do
Book.read
end
refute_instance_called Person, :say
Authors
We are very thankful for the many contributors
Versioning
This gem follows Semantic Versioning
Want to help?
Please do! We are always looking to improve this gem. Please see our Contribution Guidelines on how to properly submit issues and pull requests.
Legal
DockYard, Inc. © 2014