0.0
No commit activity in last 3 years
No release in over 3 years
Moar Minitest Please!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 5.1
~> 10.0
 Project Readme

Minitest Moar

Build Status Dependency Status Code Climate

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

@dockyard

Licensed under the MIT license