mocha 1.8.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +56 -31
- data/RELEASE.md +166 -0
- data/Rakefile +15 -7
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +11 -53
- data/lib/mocha/api.rb +119 -56
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +52 -34
- data/lib/mocha/class_methods.rb +17 -15
- data/lib/mocha/configuration.rb +351 -67
- data/lib/mocha/deprecation.rb +2 -1
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +120 -81
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +30 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +80 -39
- data/lib/mocha/mockery.rb +34 -80
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers/all_of.rb +1 -1
- data/lib/mocha/parameter_matchers/any_of.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
- data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
- data/lib/mocha/parameter_matchers/has_key.rb +2 -3
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -3
- data/lib/mocha/parameter_matchers/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/return_values.rb +3 -3
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -1
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/test_unit.rb +6 -1
- data/lib/mocha/thrower.rb +2 -1
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/lib/mocha.rb +8 -0
- data/mocha.gemspec +14 -10
- metadata +16 -233
- data/bin/build-matrix +0 -83
- data/docs/CNAME +0 -1
- data/docs/Mocha/API.html +0 -1056
- data/docs/Mocha/ClassMethods.html +0 -267
- data/docs/Mocha/Configuration.html +0 -626
- data/docs/Mocha/Expectation.html +0 -2709
- data/docs/Mocha/ExpectationError.html +0 -157
- data/docs/Mocha/ExpectationErrorFactory.html +0 -269
- data/docs/Mocha/Hooks.html +0 -385
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -165
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -165
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Mock.html +0 -1197
- data/docs/Mocha/ObjectMethods.html +0 -712
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -448
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -154
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -154
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -154
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/Not.html +0 -154
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -154
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -154
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -154
- data/docs/Mocha/ParameterMatchers.html +0 -3049
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine/State.html +0 -141
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -141
- data/docs/Mocha/StateMachine.html +0 -539
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/Mocha/UnexpectedInvocation.html +0 -140
- data/docs/Mocha.html +0 -127
- data/docs/_index.html +0 -537
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.COPYING.html +0 -81
- data/docs/file.MIT-LICENSE.html +0 -85
- data/docs/file.README.html +0 -418
- data/docs/file.RELEASE.html +0 -875
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -418
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -571
- data/docs/top-level-namespace.html +0 -118
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -113
- data/lib/mocha/mini_test.rb +0 -5
- data/lib/mocha/module_method.rb +0 -6
- data/lib/mocha/module_methods.rb +0 -10
- data/lib/mocha/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -24
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -35
- data/test/acceptance/bug_18914_test.rb +0 -38
- data/test/acceptance/bug_21465_test.rb +0 -32
- data/test/acceptance/bug_21563_test.rb +0 -23
- data/test/acceptance/exception_rescue_test.rb +0 -54
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -56
- data/test/acceptance/expected_invocation_count_test.rb +0 -230
- data/test/acceptance/failure_messages_test.rb +0 -62
- data/test/acceptance/issue_272_test.rb +0 -51
- data/test/acceptance/issue_65_test.rb +0 -65
- data/test/acceptance/issue_70_test.rb +0 -54
- data/test/acceptance/mocha_example_test.rb +0 -97
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -98
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -76
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -67
- data/test/acceptance/optional_parameters_test.rb +0 -68
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -45
- data/test/acceptance/prepend_test.rb +0 -87
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -77
- data/test/acceptance/raise_exception_test.rb +0 -37
- data/test/acceptance/return_value_test.rb +0 -50
- data/test/acceptance/sequence_test.rb +0 -190
- data/test/acceptance/states_test.rb +0 -72
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -65
- data/test/acceptance/stub_any_instance_method_test.rb +0 -282
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -79
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -74
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -145
- data/test/acceptance/stub_everything_test.rb +0 -54
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -92
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -137
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -77
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -71
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
- data/test/acceptance/stub_module_method_test.rb +0 -201
- data/test/acceptance/stub_test.rb +0 -50
- data/test/acceptance/stubba_example_test.rb +0 -94
- data/test/acceptance/stubba_test_result_test.rb +0 -72
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -89
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -53
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
- data/test/acceptance/stubbing_nil_test.rb +0 -60
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -141
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -34
- data/test/acceptance/throw_test.rb +0 -43
- data/test/acceptance/unexpected_invocation_test.rb +0 -24
- data/test/acceptance/unstubbing_test.rb +0 -195
- data/test/assertions.rb +0 -8
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -176
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -22
- data/test/mini_test_result.rb +0 -96
- data/test/minitest_result.rb +0 -48
- data/test/simple_counter.rb +0 -11
- data/test/test_helper.rb +0 -58
- data/test/test_runner.rb +0 -56
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -150
- data/test/unit/array_inspect_test.rb +0 -14
- data/test/unit/backtrace_filter_test.rb +0 -17
- data/test/unit/cardinality_test.rb +0 -54
- data/test/unit/central_test.rb +0 -99
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_method_test.rb +0 -254
- data/test/unit/class_methods_test.rb +0 -69
- data/test/unit/configuration_test.rb +0 -37
- data/test/unit/date_time_inspect_test.rb +0 -19
- data/test/unit/exception_raiser_test.rb +0 -40
- data/test/unit/expectation_list_test.rb +0 -80
- data/test/unit/expectation_test.rb +0 -492
- data/test/unit/hash_inspect_test.rb +0 -14
- data/test/unit/hooks_test.rb +0 -35
- data/test/unit/in_state_ordering_constraint_test.rb +0 -39
- data/test/unit/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -363
- data/test/unit/mockery_test.rb +0 -174
- data/test/unit/module_methods_test.rb +0 -17
- data/test/unit/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_test.rb +0 -16
- data/test/unit/object_inspect_test.rb +0 -58
- data/test/unit/object_methods_test.rb +0 -62
- data/test/unit/parameter_matchers/all_of_test.rb +0 -24
- data/test/unit/parameter_matchers/any_of_test.rb +0 -24
- data/test/unit/parameter_matchers/anything_test.rb +0 -19
- data/test/unit/parameter_matchers/equals_test.rb +0 -23
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -50
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
- data/test/unit/parameter_matchers/has_key_test.rb +0 -54
- data/test/unit/parameter_matchers/has_value_test.rb +0 -55
- data/test/unit/parameter_matchers/includes_test.rb +0 -106
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
- data/test/unit/parameter_matchers/is_a_test.rb +0 -23
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
- data/test/unit/parameter_matchers/not_test.rb +0 -24
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -119
- data/test/unit/receivers_test.rb +0 -96
- data/test/unit/return_values_test.rb +0 -61
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -12
- data/test/unit/single_yield_test.rb +0 -16
- data/test/unit/state_machine_test.rb +0 -96
- data/test/unit/string_inspect_test.rb +0 -9
- data/test/unit/thrower_test.rb +0 -18
- data/test/unit/yield_parameters_test.rb +0 -91
data/docs/Mocha/API.html
DELETED
@@ -1,1056 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Module: Mocha::API
|
8
|
-
|
9
|
-
— Mocha 1.8.0
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "Mocha::API";
|
19
|
-
relpath = '../';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="../_index.html">Index (A)</a> »
|
40
|
-
<span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
|
41
|
-
»
|
42
|
-
<span class="title">API</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="../class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Module: Mocha::API
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
<dl>
|
75
|
-
<dt>Includes:</dt>
|
76
|
-
<dd><span class='object_link'><a href="Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span>, <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></dd>
|
77
|
-
</dl>
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
<dl>
|
83
|
-
<dt>Included in:</dt>
|
84
|
-
<dd><span class='object_link'><a href="Integration/MiniTest/Adapter.html" title="Mocha::Integration::MiniTest::Adapter (module)">Integration::MiniTest::Adapter</a></span>, <span class='object_link'><a href="Integration/TestUnit/Adapter.html" title="Mocha::Integration::TestUnit::Adapter (module)">Integration::TestUnit::Adapter</a></span></dd>
|
85
|
-
</dl>
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
<dl>
|
90
|
-
<dt>Defined in:</dt>
|
91
|
-
<dd>lib/mocha/api.rb</dd>
|
92
|
-
</dl>
|
93
|
-
|
94
|
-
</div>
|
95
|
-
|
96
|
-
<h2>Overview</h2><div class="docstring">
|
97
|
-
<div class="discussion">
|
98
|
-
|
99
|
-
<p>Methods added to <code>Test::Unit::TestCase</code>,
|
100
|
-
<code>MiniTest::Unit::TestCase</code> or equivalent.</p>
|
101
|
-
|
102
|
-
|
103
|
-
</div>
|
104
|
-
</div>
|
105
|
-
<div class="tags">
|
106
|
-
|
107
|
-
|
108
|
-
</div>
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
<h2>
|
117
|
-
Instance Method Summary
|
118
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
119
|
-
</h2>
|
120
|
-
|
121
|
-
<ul class="summary">
|
122
|
-
|
123
|
-
<li class="public ">
|
124
|
-
<span class="summary_signature">
|
125
|
-
|
126
|
-
<a href="#mock-instance_method" title="#mock (instance method)">#<strong>mock</strong>(*arguments) { ... } ⇒ Mock </a>
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
</span>
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
<span class="summary_desc"><div class='inline'>
|
141
|
-
<p>Builds a new mock object.</p>
|
142
|
-
</div></span>
|
143
|
-
|
144
|
-
</li>
|
145
|
-
|
146
|
-
|
147
|
-
<li class="public ">
|
148
|
-
<span class="summary_signature">
|
149
|
-
|
150
|
-
<a href="#sequence-instance_method" title="#sequence (instance method)">#<strong>sequence</strong>(name) ⇒ Sequence </a>
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
</span>
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
<span class="summary_desc"><div class='inline'>
|
165
|
-
<p>Builds a new sequence which can be used to constrain the order in which
|
166
|
-
expectations can occur.</p>
|
167
|
-
</div></span>
|
168
|
-
|
169
|
-
</li>
|
170
|
-
|
171
|
-
|
172
|
-
<li class="public ">
|
173
|
-
<span class="summary_signature">
|
174
|
-
|
175
|
-
<a href="#states-instance_method" title="#states (instance method)">#<strong>states</strong>(name) ⇒ StateMachine </a>
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
</span>
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
<span class="summary_desc"><div class='inline'>
|
190
|
-
<p>Builds a new state machine which can be used to constrain the order in
|
191
|
-
which expectations can occur.</p>
|
192
|
-
</div></span>
|
193
|
-
|
194
|
-
</li>
|
195
|
-
|
196
|
-
|
197
|
-
<li class="public ">
|
198
|
-
<span class="summary_signature">
|
199
|
-
|
200
|
-
<a href="#stub-instance_method" title="#stub (instance method)">#<strong>stub</strong>(*arguments) { ... } ⇒ Mock </a>
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
</span>
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
<span class="summary_desc"><div class='inline'>
|
215
|
-
<p>Builds a new mock object.</p>
|
216
|
-
</div></span>
|
217
|
-
|
218
|
-
</li>
|
219
|
-
|
220
|
-
|
221
|
-
<li class="public ">
|
222
|
-
<span class="summary_signature">
|
223
|
-
|
224
|
-
<a href="#stub_everything-instance_method" title="#stub_everything (instance method)">#<strong>stub_everything</strong>(*arguments) { ... } ⇒ Mock </a>
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
</span>
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
<span class="summary_desc"><div class='inline'>
|
239
|
-
<p>Builds a mock object that accepts calls to any method.</p>
|
240
|
-
</div></span>
|
241
|
-
|
242
|
-
</li>
|
243
|
-
|
244
|
-
|
245
|
-
</ul>
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span></h3>
|
258
|
-
<p class="inherited"><span class='object_link'><a href="Hooks.html#mocha_setup-instance_method" title="Mocha::Hooks#mocha_setup (method)">#mocha_setup</a></span>, <span class='object_link'><a href="Hooks.html#mocha_teardown-instance_method" title="Mocha::Hooks#mocha_teardown (method)">#mocha_teardown</a></span>, <span class='object_link'><a href="Hooks.html#mocha_verify-instance_method" title="Mocha::Hooks#mocha_verify (method)">#mocha_verify</a></span></p>
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
|
269
|
-
<p class="inherited"><span class='object_link'><a href="ParameterMatchers.html#Not-instance_method" title="Mocha::ParameterMatchers#Not (method)">#Not</a></span>, <span class='object_link'><a href="ParameterMatchers.html#all_of-instance_method" title="Mocha::ParameterMatchers#all_of (method)">#all_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_of-instance_method" title="Mocha::ParameterMatchers#any_of (method)">#any_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_parameters-instance_method" title="Mocha::ParameterMatchers#any_parameters (method)">#any_parameters</a></span>, <span class='object_link'><a href="ParameterMatchers.html#anything-instance_method" title="Mocha::ParameterMatchers#anything (method)">#anything</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equals-instance_method" title="Mocha::ParameterMatchers#equals (method)">#equals</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equivalent_uri-instance_method" title="Mocha::ParameterMatchers#equivalent_uri (method)">#equivalent_uri</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entries-instance_method" title="Mocha::ParameterMatchers#has_entries (method)">#has_entries</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entry-instance_method" title="Mocha::ParameterMatchers#has_entry (method)">#has_entry</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_equivalent_query_string-instance_method" title="Mocha::ParameterMatchers#has_equivalent_query_string (method)">#has_equivalent_query_string</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_key-instance_method" title="Mocha::ParameterMatchers#has_key (method)">#has_key</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_value-instance_method" title="Mocha::ParameterMatchers#has_value (method)">#has_value</a></span>, <span class='object_link'><a href="ParameterMatchers.html#includes-instance_method" title="Mocha::ParameterMatchers#includes (method)">#includes</a></span>, <span class='object_link'><a href="ParameterMatchers.html#instance_of-instance_method" title="Mocha::ParameterMatchers#instance_of (method)">#instance_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#is_a-instance_method" title="Mocha::ParameterMatchers#is_a (method)">#is_a</a></span>, <span class='object_link'><a href="ParameterMatchers.html#kind_of-instance_method" title="Mocha::ParameterMatchers#kind_of (method)">#kind_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#optionally-instance_method" title="Mocha::ParameterMatchers#optionally (method)">#optionally</a></span>, <span class='object_link'><a href="ParameterMatchers.html#regexp_matches-instance_method" title="Mocha::ParameterMatchers#regexp_matches (method)">#regexp_matches</a></span>, <span class='object_link'><a href="ParameterMatchers.html#responds_with-instance_method" title="Mocha::ParameterMatchers#responds_with (method)">#responds_with</a></span>, <span class='object_link'><a href="ParameterMatchers.html#yaml_equivalent-instance_method" title="Mocha::ParameterMatchers#yaml_equivalent (method)">#yaml_equivalent</a></span></p>
|
270
|
-
|
271
|
-
|
272
|
-
<div id="instance_method_details" class="method_details_list">
|
273
|
-
<h2>Instance Method Details</h2>
|
274
|
-
|
275
|
-
|
276
|
-
<div class="method_details first">
|
277
|
-
<h3 class="signature first" id="mock-instance_method">
|
278
|
-
|
279
|
-
|
280
|
-
<span class="overload">#<strong>mock</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
281
|
-
|
282
|
-
<span class="overload">#<strong>mock</strong>(expected_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
283
|
-
|
284
|
-
<span class="overload">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
</h3><div class="docstring">
|
292
|
-
<div class="discussion">
|
293
|
-
|
294
|
-
<p>Builds a new mock object</p>
|
295
|
-
|
296
|
-
|
297
|
-
</div>
|
298
|
-
</div>
|
299
|
-
<div class="tags">
|
300
|
-
|
301
|
-
<div class="examples">
|
302
|
-
<p class="tag_title">Examples:</p>
|
303
|
-
|
304
|
-
|
305
|
-
<p class="example_title"><div class='inline'>
|
306
|
-
<p>Using expected_methods_vs_return_values Hash to setup expectations.</p>
|
307
|
-
</div></p>
|
308
|
-
|
309
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
310
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:start</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
311
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span>
|
312
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
313
|
-
<span class='comment'># an error will be raised unless both Motor#start and Motor#stop have been called
|
314
|
-
</span><span class='kw'>end</span></code></pre>
|
315
|
-
|
316
|
-
|
317
|
-
<p class="example_title"><div class='inline'>
|
318
|
-
<p>Using the optional block to setup expectations & stubbed methods
|
319
|
-
[deprecated].</p>
|
320
|
-
</div></p>
|
321
|
-
|
322
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
323
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
324
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
325
|
-
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
326
|
-
<span class='kw'>end</span>
|
327
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
328
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
329
|
-
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
330
|
-
</span><span class='kw'>end</span></code></pre>
|
331
|
-
|
332
|
-
</div>
|
333
|
-
<p class="tag_title">Parameters:</p>
|
334
|
-
<ul class="param">
|
335
|
-
|
336
|
-
<li>
|
337
|
-
|
338
|
-
<span class='name'>name</span>
|
339
|
-
|
340
|
-
|
341
|
-
<span class='type'>(<tt>String</tt>)</span>
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
—
|
346
|
-
<div class='inline'>
|
347
|
-
<p>identifies mock object in error messages.</p>
|
348
|
-
</div>
|
349
|
-
|
350
|
-
</li>
|
351
|
-
|
352
|
-
<li>
|
353
|
-
|
354
|
-
<span class='name'>expected_methods_vs_return_values</span>
|
355
|
-
|
356
|
-
|
357
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
—
|
362
|
-
<div class='inline'>
|
363
|
-
<p>expected method name symbols as keys and corresponding return values as
|
364
|
-
values - these expectations are setup as if <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span> were called
|
365
|
-
multiple times.</p>
|
366
|
-
</div>
|
367
|
-
|
368
|
-
</li>
|
369
|
-
|
370
|
-
</ul>
|
371
|
-
|
372
|
-
<p class="tag_title">Yields:</p>
|
373
|
-
<ul class="yield">
|
374
|
-
|
375
|
-
<li>
|
376
|
-
|
377
|
-
|
378
|
-
<span class='type'></span>
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
<div class='inline'>
|
384
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
385
|
-
giving an alternative way to setup stubbed methods.</p>
|
386
|
-
</div>
|
387
|
-
|
388
|
-
</li>
|
389
|
-
|
390
|
-
<li>
|
391
|
-
|
392
|
-
|
393
|
-
<span class='type'></span>
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
<div class='inline'>
|
399
|
-
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
400
|
-
things like instance variables declared in the test will not be available
|
401
|
-
within the block.</p>
|
402
|
-
</div>
|
403
|
-
|
404
|
-
</li>
|
405
|
-
|
406
|
-
<li>
|
407
|
-
|
408
|
-
|
409
|
-
<span class='type'></span>
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
<div class='inline'>
|
415
|
-
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
416
|
-
receiver instead.</p>
|
417
|
-
</div>
|
418
|
-
|
419
|
-
</li>
|
420
|
-
|
421
|
-
</ul>
|
422
|
-
<p class="tag_title">Returns:</p>
|
423
|
-
<ul class="return">
|
424
|
-
|
425
|
-
<li>
|
426
|
-
|
427
|
-
|
428
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
—
|
433
|
-
<div class='inline'>
|
434
|
-
<p>a new mock object</p>
|
435
|
-
</div>
|
436
|
-
|
437
|
-
</li>
|
438
|
-
|
439
|
-
</ul>
|
440
|
-
|
441
|
-
</div><table class="source_code">
|
442
|
-
<tr>
|
443
|
-
<td>
|
444
|
-
<pre class="lines">
|
445
|
-
|
446
|
-
|
447
|
-
52
|
448
|
-
53
|
449
|
-
54
|
450
|
-
55
|
451
|
-
56
|
452
|
-
57
|
453
|
-
58</pre>
|
454
|
-
</td>
|
455
|
-
<td>
|
456
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 52</span>
|
457
|
-
|
458
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
459
|
-
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
460
|
-
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
461
|
-
<span class='id identifier rubyid_mock'>mock</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
462
|
-
<span class='id identifier rubyid_mock'>mock</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
463
|
-
<span class='id identifier rubyid_mock'>mock</span>
|
464
|
-
<span class='kw'>end</span></pre>
|
465
|
-
</td>
|
466
|
-
</tr>
|
467
|
-
</table>
|
468
|
-
</div>
|
469
|
-
|
470
|
-
<div class="method_details ">
|
471
|
-
<h3 class="signature " id="sequence-instance_method">
|
472
|
-
|
473
|
-
#<strong>sequence</strong>(name) ⇒ <tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
</h3><div class="docstring">
|
480
|
-
<div class="discussion">
|
481
|
-
|
482
|
-
<p>Builds a new sequence which can be used to constrain the order in which
|
483
|
-
expectations can occur.</p>
|
484
|
-
|
485
|
-
<p>Specify that an expected invocation must occur within a named <span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span> by
|
486
|
-
using <span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span>.</p>
|
487
|
-
|
488
|
-
|
489
|
-
</div>
|
490
|
-
</div>
|
491
|
-
<div class="tags">
|
492
|
-
|
493
|
-
<div class="examples">
|
494
|
-
<p class="tag_title">Examples:</p>
|
495
|
-
|
496
|
-
|
497
|
-
<p class="example_title"><div class='inline'>
|
498
|
-
<p>Ensure methods on egg are invoked in correct order.</p>
|
499
|
-
</div></p>
|
500
|
-
|
501
|
-
<pre class="example code"><code><span class='id identifier rubyid_breakfast'>breakfast</span> <span class='op'>=</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>breakfast</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
502
|
-
|
503
|
-
<span class='id identifier rubyid_egg'>egg</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>egg</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
504
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:crack</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
505
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:fry</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
506
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:eat</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
507
|
-
<span class='kw'>end</span></code></pre>
|
508
|
-
|
509
|
-
</div>
|
510
|
-
|
511
|
-
<p class="tag_title">Returns:</p>
|
512
|
-
<ul class="return">
|
513
|
-
|
514
|
-
<li>
|
515
|
-
|
516
|
-
|
517
|
-
<span class='type'>(<tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>)</span>
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
—
|
522
|
-
<div class='inline'>
|
523
|
-
<p>a new sequence</p>
|
524
|
-
</div>
|
525
|
-
|
526
|
-
</li>
|
527
|
-
|
528
|
-
</ul>
|
529
|
-
|
530
|
-
<p class="tag_title">See Also:</p>
|
531
|
-
<ul class="see">
|
532
|
-
|
533
|
-
<li><span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span></li>
|
534
|
-
|
535
|
-
</ul>
|
536
|
-
|
537
|
-
</div><table class="source_code">
|
538
|
-
<tr>
|
539
|
-
<td>
|
540
|
-
<pre class="lines">
|
541
|
-
|
542
|
-
|
543
|
-
144
|
544
|
-
145
|
545
|
-
146</pre>
|
546
|
-
</td>
|
547
|
-
<td>
|
548
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 144</span>
|
549
|
-
|
550
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
551
|
-
<span class='const'><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
552
|
-
<span class='kw'>end</span></pre>
|
553
|
-
</td>
|
554
|
-
</tr>
|
555
|
-
</table>
|
556
|
-
</div>
|
557
|
-
|
558
|
-
<div class="method_details ">
|
559
|
-
<h3 class="signature " id="states-instance_method">
|
560
|
-
|
561
|
-
#<strong>states</strong>(name) ⇒ <tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
</h3><div class="docstring">
|
568
|
-
<div class="discussion">
|
569
|
-
|
570
|
-
<p>Builds a new state machine which can be used to constrain the order in
|
571
|
-
which expectations can occur.</p>
|
572
|
-
|
573
|
-
<p>Specify the initial state of the state machine by using
|
574
|
-
<span class='object_link'><a href="StateMachine.html#starts_as-instance_method" title="Mocha::StateMachine#starts_as (method)">StateMachine#starts_as</a></span>.</p>
|
575
|
-
|
576
|
-
<p>Specify that an expected invocation should change the state of the state
|
577
|
-
machine by using <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span>.</p>
|
578
|
-
|
579
|
-
<p>Specify that an expected invocation should be constrained to occur within a
|
580
|
-
particular <code>state</code> by using <span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span>.</p>
|
581
|
-
|
582
|
-
<p>A test can contain multiple state machines.</p>
|
583
|
-
|
584
|
-
|
585
|
-
</div>
|
586
|
-
</div>
|
587
|
-
<div class="tags">
|
588
|
-
|
589
|
-
<div class="examples">
|
590
|
-
<p class="tag_title">Examples:</p>
|
591
|
-
|
592
|
-
|
593
|
-
<p class="example_title"><div class='inline'>
|
594
|
-
<p>Constrain expected invocations to occur in particular states.</p>
|
595
|
-
</div></p>
|
596
|
-
|
597
|
-
<pre class="example code"><code><span class='id identifier rubyid_power'>power</span> <span class='op'>=</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>power</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>off</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
598
|
-
|
599
|
-
<span class='id identifier rubyid_radio'>radio</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>radio</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
600
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_on</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
601
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BBC Radio 4</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
602
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>+5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
603
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BBC World Service</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
604
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>-</span><span class='int'>5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
605
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_off</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>off</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
606
|
-
<span class='kw'>end</span></code></pre>
|
607
|
-
|
608
|
-
</div>
|
609
|
-
|
610
|
-
<p class="tag_title">Returns:</p>
|
611
|
-
<ul class="return">
|
612
|
-
|
613
|
-
<li>
|
614
|
-
|
615
|
-
|
616
|
-
<span class='type'>(<tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>)</span>
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
—
|
621
|
-
<div class='inline'>
|
622
|
-
<p>a new state machine</p>
|
623
|
-
</div>
|
624
|
-
|
625
|
-
</li>
|
626
|
-
|
627
|
-
</ul>
|
628
|
-
|
629
|
-
<p class="tag_title">See Also:</p>
|
630
|
-
<ul class="see">
|
631
|
-
|
632
|
-
<li><span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span></li>
|
633
|
-
|
634
|
-
<li><span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span></li>
|
635
|
-
|
636
|
-
<li><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></li>
|
637
|
-
|
638
|
-
</ul>
|
639
|
-
|
640
|
-
</div><table class="source_code">
|
641
|
-
<tr>
|
642
|
-
<td>
|
643
|
-
<pre class="lines">
|
644
|
-
|
645
|
-
|
646
|
-
174
|
647
|
-
175
|
648
|
-
176</pre>
|
649
|
-
</td>
|
650
|
-
<td>
|
651
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 174</span>
|
652
|
-
|
653
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
654
|
-
<span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_new_state_machine'>new_state_machine</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
655
|
-
<span class='kw'>end</span></pre>
|
656
|
-
</td>
|
657
|
-
</tr>
|
658
|
-
</table>
|
659
|
-
</div>
|
660
|
-
|
661
|
-
<div class="method_details ">
|
662
|
-
<h3 class="signature " id="stub-instance_method">
|
663
|
-
|
664
|
-
|
665
|
-
<span class="overload">#<strong>stub</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
666
|
-
|
667
|
-
<span class="overload">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
668
|
-
|
669
|
-
<span class="overload">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
</h3><div class="docstring">
|
677
|
-
<div class="discussion">
|
678
|
-
|
679
|
-
<p>Builds a new mock object</p>
|
680
|
-
|
681
|
-
|
682
|
-
</div>
|
683
|
-
</div>
|
684
|
-
<div class="tags">
|
685
|
-
|
686
|
-
<div class="examples">
|
687
|
-
<p class="tag_title">Examples:</p>
|
688
|
-
|
689
|
-
|
690
|
-
<p class="example_title"><div class='inline'>
|
691
|
-
<p>Using stubbed_methods_vs_return_values Hash to setup stubbed methods.</p>
|
692
|
-
</div></p>
|
693
|
-
|
694
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
695
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:start</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
696
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span>
|
697
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
698
|
-
<span class='comment'># an error will not be raised even if either Motor#start or Motor#stop has not been called
|
699
|
-
</span><span class='kw'>end</span></code></pre>
|
700
|
-
|
701
|
-
|
702
|
-
<p class="example_title"><div class='inline'>
|
703
|
-
<p>Using the optional block to setup expectations & stubbed methods
|
704
|
-
[deprecated].</p>
|
705
|
-
</div></p>
|
706
|
-
|
707
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
708
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
709
|
-
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
710
|
-
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
711
|
-
<span class='kw'>end</span>
|
712
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
713
|
-
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
714
|
-
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
715
|
-
</span><span class='kw'>end</span></code></pre>
|
716
|
-
|
717
|
-
</div>
|
718
|
-
<p class="tag_title">Parameters:</p>
|
719
|
-
<ul class="param">
|
720
|
-
|
721
|
-
<li>
|
722
|
-
|
723
|
-
<span class='name'>name</span>
|
724
|
-
|
725
|
-
|
726
|
-
<span class='type'>(<tt>String</tt>)</span>
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
—
|
731
|
-
<div class='inline'>
|
732
|
-
<p>identifies mock object in error messages.</p>
|
733
|
-
</div>
|
734
|
-
|
735
|
-
</li>
|
736
|
-
|
737
|
-
<li>
|
738
|
-
|
739
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
740
|
-
|
741
|
-
|
742
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
—
|
747
|
-
<div class='inline'>
|
748
|
-
<p>stubbed method name symbols as keys and corresponding return values as
|
749
|
-
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
750
|
-
multiple times.</p>
|
751
|
-
</div>
|
752
|
-
|
753
|
-
</li>
|
754
|
-
|
755
|
-
</ul>
|
756
|
-
|
757
|
-
<p class="tag_title">Yields:</p>
|
758
|
-
<ul class="yield">
|
759
|
-
|
760
|
-
<li>
|
761
|
-
|
762
|
-
|
763
|
-
<span class='type'></span>
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
<div class='inline'>
|
769
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
770
|
-
giving an alternative way to setup stubbed methods.</p>
|
771
|
-
</div>
|
772
|
-
|
773
|
-
</li>
|
774
|
-
|
775
|
-
<li>
|
776
|
-
|
777
|
-
|
778
|
-
<span class='type'></span>
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
<div class='inline'>
|
784
|
-
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
785
|
-
things like instance variables declared in the test will not be available
|
786
|
-
within the block.</p>
|
787
|
-
</div>
|
788
|
-
|
789
|
-
</li>
|
790
|
-
|
791
|
-
<li>
|
792
|
-
|
793
|
-
|
794
|
-
<span class='type'></span>
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
<div class='inline'>
|
800
|
-
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
801
|
-
receiver instead.</p>
|
802
|
-
</div>
|
803
|
-
|
804
|
-
</li>
|
805
|
-
|
806
|
-
</ul>
|
807
|
-
<p class="tag_title">Returns:</p>
|
808
|
-
<ul class="return">
|
809
|
-
|
810
|
-
<li>
|
811
|
-
|
812
|
-
|
813
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
—
|
818
|
-
<div class='inline'>
|
819
|
-
<p>a new mock object</p>
|
820
|
-
</div>
|
821
|
-
|
822
|
-
</li>
|
823
|
-
|
824
|
-
</ul>
|
825
|
-
|
826
|
-
</div><table class="source_code">
|
827
|
-
<tr>
|
828
|
-
<td>
|
829
|
-
<pre class="lines">
|
830
|
-
|
831
|
-
|
832
|
-
91
|
833
|
-
92
|
834
|
-
93
|
835
|
-
94
|
836
|
-
95
|
837
|
-
96
|
838
|
-
97</pre>
|
839
|
-
</td>
|
840
|
-
<td>
|
841
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 91</span>
|
842
|
-
|
843
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
844
|
-
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
845
|
-
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
846
|
-
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
847
|
-
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
848
|
-
<span class='id identifier rubyid_stub'>stub</span>
|
849
|
-
<span class='kw'>end</span></pre>
|
850
|
-
</td>
|
851
|
-
</tr>
|
852
|
-
</table>
|
853
|
-
</div>
|
854
|
-
|
855
|
-
<div class="method_details ">
|
856
|
-
<h3 class="signature " id="stub_everything-instance_method">
|
857
|
-
|
858
|
-
|
859
|
-
<span class="overload">#<strong>stub_everything</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
860
|
-
|
861
|
-
<span class="overload">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
862
|
-
|
863
|
-
<span class="overload">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
</h3><div class="docstring">
|
871
|
-
<div class="discussion">
|
872
|
-
|
873
|
-
<p>Builds a mock object that accepts calls to any method. By default it will
|
874
|
-
return <code>nil</code> for any method call.</p>
|
875
|
-
|
876
|
-
|
877
|
-
</div>
|
878
|
-
</div>
|
879
|
-
<div class="tags">
|
880
|
-
|
881
|
-
<div class="examples">
|
882
|
-
<p class="tag_title">Examples:</p>
|
883
|
-
|
884
|
-
|
885
|
-
<p class="example_title"><div class='inline'>
|
886
|
-
<p>Ignore invocations of irrelevant methods.</p>
|
887
|
-
</div></p>
|
888
|
-
|
889
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_stops'>test_motor_stops</span>
|
890
|
-
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
891
|
-
<span class='id identifier rubyid_assert_nil'>assert_nil</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_irrelevant_method_1'>irrelevant_method_1</span> <span class='comment'># => no error raised
|
892
|
-
</span> <span class='id identifier rubyid_assert_nil'>assert_nil</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_irrelevant_method_2'>irrelevant_method_2</span> <span class='comment'># => no error raised
|
893
|
-
</span> <span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
894
|
-
<span class='kw'>end</span></code></pre>
|
895
|
-
|
896
|
-
</div>
|
897
|
-
<p class="tag_title">Parameters:</p>
|
898
|
-
<ul class="param">
|
899
|
-
|
900
|
-
<li>
|
901
|
-
|
902
|
-
<span class='name'>name</span>
|
903
|
-
|
904
|
-
|
905
|
-
<span class='type'>(<tt>String</tt>)</span>
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
—
|
910
|
-
<div class='inline'>
|
911
|
-
<p>identifies mock object in error messages.</p>
|
912
|
-
</div>
|
913
|
-
|
914
|
-
</li>
|
915
|
-
|
916
|
-
<li>
|
917
|
-
|
918
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
919
|
-
|
920
|
-
|
921
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
—
|
926
|
-
<div class='inline'>
|
927
|
-
<p>stubbed method name symbols as keys and corresponding return values as
|
928
|
-
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
929
|
-
multiple times.</p>
|
930
|
-
</div>
|
931
|
-
|
932
|
-
</li>
|
933
|
-
|
934
|
-
</ul>
|
935
|
-
|
936
|
-
<p class="tag_title">Yields:</p>
|
937
|
-
<ul class="yield">
|
938
|
-
|
939
|
-
<li>
|
940
|
-
|
941
|
-
|
942
|
-
<span class='type'></span>
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
<div class='inline'>
|
948
|
-
<p>optional block to be evaluated in the context of the mock object instance,
|
949
|
-
giving an alternative way to setup stubbed methods.</p>
|
950
|
-
</div>
|
951
|
-
|
952
|
-
</li>
|
953
|
-
|
954
|
-
<li>
|
955
|
-
|
956
|
-
|
957
|
-
<span class='type'></span>
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
<div class='inline'>
|
963
|
-
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
964
|
-
things like instance variables declared in the test will not be available
|
965
|
-
within the block.</p>
|
966
|
-
</div>
|
967
|
-
|
968
|
-
</li>
|
969
|
-
|
970
|
-
<li>
|
971
|
-
|
972
|
-
|
973
|
-
<span class='type'></span>
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
<div class='inline'>
|
979
|
-
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
980
|
-
receiver instead.</p>
|
981
|
-
</div>
|
982
|
-
|
983
|
-
</li>
|
984
|
-
|
985
|
-
</ul>
|
986
|
-
<p class="tag_title">Returns:</p>
|
987
|
-
<ul class="return">
|
988
|
-
|
989
|
-
<li>
|
990
|
-
|
991
|
-
|
992
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
—
|
997
|
-
<div class='inline'>
|
998
|
-
<p>a new mock object</p>
|
999
|
-
</div>
|
1000
|
-
|
1001
|
-
</li>
|
1002
|
-
|
1003
|
-
</ul>
|
1004
|
-
|
1005
|
-
</div><table class="source_code">
|
1006
|
-
<tr>
|
1007
|
-
<td>
|
1008
|
-
<pre class="lines">
|
1009
|
-
|
1010
|
-
|
1011
|
-
119
|
1012
|
-
120
|
1013
|
-
121
|
1014
|
-
122
|
1015
|
-
123
|
1016
|
-
124
|
1017
|
-
125
|
1018
|
-
126</pre>
|
1019
|
-
</td>
|
1020
|
-
<td>
|
1021
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 119</span>
|
1022
|
-
|
1023
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1024
|
-
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
1025
|
-
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1026
|
-
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1027
|
-
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stub_everything'>stub_everything</span>
|
1028
|
-
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
1029
|
-
<span class='id identifier rubyid_stub'>stub</span>
|
1030
|
-
<span class='kw'>end</span></pre>
|
1031
|
-
</td>
|
1032
|
-
</tr>
|
1033
|
-
</table>
|
1034
|
-
</div>
|
1035
|
-
|
1036
|
-
</div>
|
1037
|
-
|
1038
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
1039
|
-
<script>
|
1040
|
-
window.dataLayer = window.dataLayer || [];
|
1041
|
-
function gtag(){dataLayer.push(arguments);}
|
1042
|
-
gtag('js', new Date());
|
1043
|
-
|
1044
|
-
gtag('config', 'UA-625523-7');
|
1045
|
-
</script>
|
1046
|
-
</div>
|
1047
|
-
|
1048
|
-
<div id="footer">
|
1049
|
-
Generated on Tue Jan 15 17:13:05 2019 by
|
1050
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1051
|
-
0.9.16 (ruby-2.5.3).
|
1052
|
-
</div>
|
1053
|
-
|
1054
|
-
</div>
|
1055
|
-
</body>
|
1056
|
-
</html>
|