Module: Mockr::TestCaseHelpers
- Defined in:
- lib/mockr.rb
Overview
Include this module in your Test::Unit::TestCase in order to more conveniently use and verify mocks.
Instance Method Summary collapse
-
#new_mock ⇒ Object
(also: #mock)
Create a new mock and remember it so that it can be automatically verified when the test case completes.
-
#teardown ⇒ Object
:nodoc:.
-
#verify_all_mocks ⇒ Object
Verify all mocks that were created using #new_mock.
Instance Method Details
#new_mock ⇒ Object Also known as: mock
Create a new mock and remember it so that it can be automatically verified when the test case completes
196 197 198 199 200 |
# File 'lib/mockr.rb', line 196 def new_mock @mocks ||= [] @mocks << (mock = Mock.new) mock end |
#teardown ⇒ Object
:nodoc:
204 205 206 |
# File 'lib/mockr.rb', line 204 def teardown # :nodoc: verify_all_mocks end |
#verify_all_mocks ⇒ Object
Verify all mocks that were created using #new_mock.
Usually you will not need to call this method yourself – it is called automatically unless you override #teardown for your own purposes
213 214 215 216 217 218 |
# File 'lib/mockr.rb', line 213 def verify_all_mocks return unless instance_variables.include?("@mocks") @mocks.each do |mock| mock.verify end end |