Module: AutoVerify
- Included in:
- Test::Unit::TestCase
- Defined in:
- lib/mocha/auto_verify.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_mock_with_expectations(expectation_type = :expects, expectations = {}) ⇒ Object
- #mock(expectations = {}) ⇒ Object
- #mocks ⇒ Object
- #reset_mocks ⇒ Object
- #stub(expectations = {}) ⇒ Object
- #stub_everything(expectations = {}) ⇒ Object
- #teardown_mocks ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/mocha/auto_verify.rb', line 5 def self.included(base) base.add_teardown_method(:teardown_mocks) end |
Instance Method Details
#build_mock_with_expectations(expectation_type = :expects, expectations = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mocha/auto_verify.rb', line 34 def build_mock_with_expectations(expectation_type = :expects, expectations = {}) stub_everything = (expectation_type == :stub_everything) expectation_type = :stubs if expectation_type == :stub_everything mock = Mocha::Mock.new(stub_everything) expectations.each do |method, result| mock.send(expectation_type, method).returns(result) end mocks << mock mock end |
#mock(expectations = {}) ⇒ Object
17 18 19 |
# File 'lib/mocha/auto_verify.rb', line 17 def mock(expectations = {}) build_mock_with_expectations(:expects, expectations) end |
#mocks ⇒ Object
9 10 11 |
# File 'lib/mocha/auto_verify.rb', line 9 def mocks @mocks ||= [] end |
#reset_mocks ⇒ Object
13 14 15 |
# File 'lib/mocha/auto_verify.rb', line 13 def reset_mocks @mocks = nil end |
#stub(expectations = {}) ⇒ Object
21 22 23 |
# File 'lib/mocha/auto_verify.rb', line 21 def stub(expectations = {}) build_mock_with_expectations(:stubs, expectations) end |
#stub_everything(expectations = {}) ⇒ Object
25 26 27 |
# File 'lib/mocha/auto_verify.rb', line 25 def stub_everything(expectations = {}) build_mock_with_expectations(:stub_everything, expectations) end |
#teardown_mocks ⇒ Object
29 30 31 32 |
# File 'lib/mocha/auto_verify.rb', line 29 def teardown_mocks mocks.each { |mock| mock.verify { add_assertion } } reset_mocks end |