Module: Mocha::API
- Includes:
- ParameterMatchers
- Defined in:
- lib/mocha/api.rb
Overview
Methods added to Test::Unit::TestCase or equivalent.
Instance Method Summary (collapse)
-
- (Mock) mock(*arguments) { ... }
Builds a new mock object.
-
- (Sequence) sequence(name)
Builds a new sequence which can be used to constrain the order in which expectations can occur.
-
- (StateMachine) states(name)
Builds a new state machine which can be used to constrain the order in which expectations can occur.
-
- (Mock) stub(*arguments) { ... }
Builds a new mock object.
-
- (Mock) stub_everything(*arguments) { ... }
Builds a mock object that accepts calls to any method.
Methods included from ParameterMatchers
#Not, #all_of, #any_of, #any_parameters, #anything, #equals, #has_entries, #has_entry, #has_equivalent_query_string, #has_key, #has_value, #includes, #instance_of, #is_a, #kind_of, #optionally, #regexp_matches, #responds_with, #yaml_equivalent
Instance Method Details
- (Mock) mock(name, &block) - (Mock) mock(expected_methods_vs_return_values = {}, &block) - (Mock) mock(name, expected_methods_vs_return_values = {}, &block)
Builds a new mock object
40 41 42 43 44 45 46 |
# File 'lib/mocha/api.rb', line 40 def mock(*arguments, &block) name = arguments.shift if arguments.first.is_a?(String) expectations = arguments.shift || {} mock = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) mock.expects(expectations) mock end |
- (Sequence) sequence(name)
Builds a new sequence which can be used to constrain the order in which expectations can occur.
Specify that an expected invocation must occur within a named Sequence by using Expectation#in_sequence.
128 129 130 |
# File 'lib/mocha/api.rb', line 128 def sequence(name) Sequence.new(name) end |
- (StateMachine) states(name)
Builds a new state machine which can be used to constrain the order in which expectations can occur.
Specify the initial state of the state machine by using StateMachine#starts_as.
Specify that an expected invocation should change the state of the state machine by using Expectation#then.
Specify that an expected invocation should be constrained to occur within a particular state by using Expectation#when.
A test can contain multiple state machines.
158 159 160 |
# File 'lib/mocha/api.rb', line 158 def states(name) Mockery.instance.new_state_machine(name) end |
- (Mock) stub(name, &block) - (Mock) stub(stubbed_methods_vs_return_values = {}, &block) - (Mock) stub(name, stubbed_methods_vs_return_values = {}, &block)
Builds a new mock object
77 78 79 80 81 82 83 |
# File 'lib/mocha/api.rb', line 77 def stub(*arguments, &block) name = arguments.shift if arguments.first.is_a?(String) expectations = arguments.shift || {} stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) stub.stubs(expectations) stub end |
- (Mock) stub_everything(name, &block) - (Mock) stub_everything(stubbed_methods_vs_return_values = {}, &block) - (Mock) stub_everything(name, stubbed_methods_vs_return_values = {}, &block)
Builds a mock object that accepts calls to any method. By default it will return nil for any method call.
103 104 105 106 107 108 109 110 |
# File 'lib/mocha/api.rb', line 103 def stub_everything(*arguments, &block) name = arguments.shift if arguments.first.is_a?(String) expectations = arguments.shift || {} stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) stub.stub_everything stub.stubs(expectations) stub end |