mocha 1.10.2 → 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/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +28 -30
- data/RELEASE.md +87 -0
- data/Rakefile +7 -5
- data/lib/mocha/api.rb +2 -3
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/configuration.rb +2 -2
- data/lib/mocha/expectation.rb +71 -30
- data/lib/mocha/inspect.rb +6 -4
- data/lib/mocha/invocation.rb +9 -5
- data/lib/mocha/mock.rb +41 -15
- data/lib/mocha/mockery.rb +17 -27
- data/lib/mocha/parameter_matchers.rb +1 -0
- 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/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +4 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/mocha.gemspec +13 -7
- metadata +8 -210
- data/bin/build-matrix +0 -82
- data/docs/CNAME +0 -1
- data/docs/Mocha.html +0 -254
- data/docs/Mocha/API.html +0 -1287
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2654
- data/docs/Mocha/ExpectationError.html +0 -152
- data/docs/Mocha/ExpectationErrorFactory.html +0 -260
- data/docs/Mocha/Hooks.html +0 -370
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
- data/docs/Mocha/Mock.html +0 -1237
- data/docs/Mocha/ObjectMethods.html +0 -765
- data/docs/Mocha/ParameterMatchers.html +0 -2961
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -441
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/Not.html +0 -153
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine.html +0 -527
- data/docs/Mocha/StateMachine/State.html +0 -140
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/_index.html +0 -519
- 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 -448
- data/docs/file.RELEASE.html +0 -974
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -448
- data/docs/js/app.js +0 -303
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -635
- 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.minitest.5.11.3 +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/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/bug_18914_test.rb +0 -37
- data/test/acceptance/bug_21465_test.rb +0 -31
- data/test/acceptance/bug_21563_test.rb +0 -22
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
- data/test/acceptance/exception_rescue_test.rb +0 -53
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -229
- data/test/acceptance/failure_messages_test.rb +0 -61
- data/test/acceptance/issue_272_test.rb +0 -50
- data/test/acceptance/issue_65_test.rb +0 -64
- data/test/acceptance/issue_70_test.rb +0 -53
- data/test/acceptance/mocha_example_test.rb +0 -96
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -99
- data/test/acceptance/mock_test.rb +0 -139
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- data/test/acceptance/optional_parameters_test.rb +0 -67
- data/test/acceptance/parameter_matcher_test.rb +0 -299
- data/test/acceptance/partial_mocks_test.rb +0 -44
- data/test/acceptance/prepend_test.rb +0 -86
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
- data/test/acceptance/raise_exception_test.rb +0 -36
- data/test/acceptance/return_value_test.rb +0 -49
- data/test/acceptance/sequence_test.rb +0 -189
- data/test/acceptance/states_test.rb +0 -71
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
- data/test/acceptance/stub_any_instance_method_test.rb +0 -301
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
- data/test/acceptance/stub_everything_test.rb +0 -53
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
- data/test/acceptance/stub_module_method_test.rb +0 -200
- data/test/acceptance/stub_test.rb +0 -49
- data/test/acceptance/stubba_example_test.rb +0 -93
- data/test/acceptance/stubba_test_result_test.rb +0 -71
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
- 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 -157
- 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 -33
- data/test/acceptance/throw_test.rb +0 -42
- data/test/acceptance/unexpected_invocation_test.rb +0 -23
- data/test/acceptance/unstubbing_test.rb +0 -194
- 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 -178
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -16
- 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 -58
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -175
- 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 -72
- data/test/unit/central_test.rb +0 -98
- data/test/unit/change_state_side_effect_test.rb +0 -37
- 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 -45
- data/test/unit/expectation_list_test.rb +0 -82
- 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/instance_method_test.rb +0 -282
- data/test/unit/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -372
- data/test/unit/mockery_test.rb +0 -171
- data/test/unit/module_methods_test.rb +0 -16
- 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 -60
- data/test/unit/object_methods_test.rb +0 -63
- 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 -41
- 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 -66
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -17
- 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 -23
- data/test/unit/yield_parameters_test.rb +0 -91
data/bin/build-matrix
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
require 'set'
|
5
|
-
require 'English'
|
6
|
-
|
7
|
-
def execute(*commands)
|
8
|
-
commands.each do |command|
|
9
|
-
system(command)
|
10
|
-
next if $CHILD_STATUS.success?
|
11
|
-
message = [
|
12
|
-
'Executing shell command failed.',
|
13
|
-
" Command: #{command}",
|
14
|
-
" Status: #{$CHILD_STATUS.exitstatus}"
|
15
|
-
].join("\n")
|
16
|
-
raise message
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def reset_bundle
|
21
|
-
execute(
|
22
|
-
'rm -rf .bundle/gems',
|
23
|
-
'rm -rf gemfiles/.bundle/gems',
|
24
|
-
'rm -f *.lock',
|
25
|
-
'rm -f gemfiles/*.lock'
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_rbenv(command)
|
30
|
-
%{export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; #{command}}
|
31
|
-
end
|
32
|
-
|
33
|
-
def run(ruby_version, gemfile, task = 'test')
|
34
|
-
ENV['RBENV_VERSION'] = ruby_version
|
35
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
36
|
-
ENV['MOCHA_OPTIONS'] = 'debug'
|
37
|
-
reset_bundle
|
38
|
-
execute(
|
39
|
-
with_rbenv("bundle install --gemfile=#{gemfile}"),
|
40
|
-
with_rbenv("bundle exec rake #{task}")
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
AVAILABLE_RUBY_VERSIONS = `rbenv versions --bare`.split("\n")
|
45
|
-
|
46
|
-
travis_config = YAML.safe_load(File.read('.travis.yml'))
|
47
|
-
build_configs = travis_config['matrix']['include']
|
48
|
-
travis_config['rvm'].each do |ruby_version|
|
49
|
-
travis_config['gemfile'].each do |gemfile|
|
50
|
-
travis_config['env'].each do |env|
|
51
|
-
build_configs << { 'rvm' => ruby_version, 'gemfile' => gemfile, 'env' => env }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
missing_ruby_versions = Set.new
|
57
|
-
|
58
|
-
build_configs.each do |config|
|
59
|
-
ruby_version = config['rvm']
|
60
|
-
gemfile = config['gemfile']
|
61
|
-
environment_variables = Hash[*config['env'].split.flat_map { |e| e.split('=') }]
|
62
|
-
original_environment_variables = {}
|
63
|
-
begin
|
64
|
-
environment_variables.each do |k, v|
|
65
|
-
original_environment_variables[k] = ENV[k]
|
66
|
-
ENV[k] = v
|
67
|
-
end
|
68
|
-
if AVAILABLE_RUBY_VERSIONS.include?(ruby_version)
|
69
|
-
puts
|
70
|
-
puts "Ruby v#{ruby_version}; Gemfile path: #{gemfile}; Environment: #{environment_variables}"
|
71
|
-
run(ruby_version, gemfile)
|
72
|
-
else
|
73
|
-
missing_ruby_versions << ruby_version
|
74
|
-
end
|
75
|
-
ensure
|
76
|
-
original_environment_variables.each do |k, v|
|
77
|
-
ENV[k] = v
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
puts "Missing Ruby versions: #{missing_ruby_versions.to_a.join(', ')}"
|
data/docs/CNAME
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
mocha.jamesmead.org
|
data/docs/Mocha.html
DELETED
@@ -1,254 +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
|
8
|
-
|
9
|
-
— Mocha 1.10.2
|
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";
|
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 (M)</a> »
|
40
|
-
|
41
|
-
|
42
|
-
<span class="title">Mocha</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
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<dl>
|
80
|
-
<dt>Defined in:</dt>
|
81
|
-
<dd>lib/mocha/api.rb<span class="defines">,<br />
|
82
|
-
lib/mocha/hooks.rb,<br /> lib/mocha/mock.rb,<br /> lib/mocha/expectation.rb,<br /> lib/mocha/object_methods.rb,<br /> lib/mocha/class_methods.rb,<br /> lib/mocha/parameter_matchers.rb,<br /> lib/mocha/parameter_matchers/not.rb,<br /> lib/mocha/parameter_matchers/base.rb,<br /> lib/mocha/parameter_matchers/is_a.rb,<br /> lib/mocha/parameter_matchers/all_of.rb,<br /> lib/mocha/parameter_matchers/any_of.rb,<br /> lib/mocha/parameter_matchers/equals.rb,<br /> lib/mocha/parameter_matchers/has_key.rb,<br /> lib/mocha/parameter_matchers/kind_of.rb,<br /> lib/mocha/parameter_matchers/anything.rb,<br /> lib/mocha/parameter_matchers/includes.rb,<br /> lib/mocha/parameter_matchers/has_entry.rb,<br /> lib/mocha/parameter_matchers/has_value.rb,<br /> lib/mocha/parameter_matchers/optionally.rb,<br /> lib/mocha/parameter_matchers/has_entries.rb,<br /> lib/mocha/parameter_matchers/instance_of.rb,<br /> lib/mocha/parameter_matchers/responds_with.rb,<br /> lib/mocha/parameter_matchers/any_parameters.rb,<br /> lib/mocha/parameter_matchers/equivalent_uri.rb,<br /> lib/mocha/parameter_matchers/regexp_matches.rb,<br /> lib/mocha/parameter_matchers/yaml_equivalent.rb,<br /> lib/mocha/parameter_matchers/instance_methods.rb,<br /> lib/mocha/state_machine.rb,<br /> lib/mocha/sequence.rb,<br /> lib/mocha/configuration.rb,<br /> lib/mocha/expectation_error_factory.rb,<br /> lib/mocha/expectation_error.rb,<br /> lib/mocha/stubbing_error.rb,<br /> lib/mocha/integration/test_unit/adapter.rb,<br /> lib/mocha/integration/mini_test/adapter.rb</span>
|
83
|
-
</dd>
|
84
|
-
</dl>
|
85
|
-
|
86
|
-
</div>
|
87
|
-
|
88
|
-
<h2>Defined Under Namespace</h2>
|
89
|
-
<p class="children">
|
90
|
-
|
91
|
-
|
92
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mocha/API.html" title="Mocha::API (module)">API</a></span>, <span class='object_link'><a href="Mocha/ClassMethods.html" title="Mocha::ClassMethods (module)">ClassMethods</a></span>, <span class='object_link'><a href="Mocha/Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span>, <span class='object_link'><a href="Mocha/Integration.html" title="Mocha::Integration (module)">Integration</a></span>, <span class='object_link'><a href="Mocha/ObjectMethods.html" title="Mocha::ObjectMethods (module)">ObjectMethods</a></span>, <span class='object_link'><a href="Mocha/ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span>
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Mocha/Configuration.html" title="Mocha::Configuration (class)">Configuration</a></span>, <span class='object_link'><a href="Mocha/Expectation.html" title="Mocha::Expectation (class)">Expectation</a></span>, <span class='object_link'><a href="Mocha/ExpectationError.html" title="Mocha::ExpectationError (class)">ExpectationError</a></span>, <span class='object_link'><a href="Mocha/ExpectationErrorFactory.html" title="Mocha::ExpectationErrorFactory (class)">ExpectationErrorFactory</a></span>, <span class='object_link'><a href="Mocha/Mock.html" title="Mocha::Mock (class)">Mock</a></span>, <span class='object_link'><a href="Mocha/Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span>, <span class='object_link'><a href="Mocha/StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span>, <span class='object_link'><a href="Mocha/StubbingError.html" title="Mocha::StubbingError (class)">StubbingError</a></span>
|
97
|
-
|
98
|
-
|
99
|
-
</p>
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
<h2>
|
109
|
-
Class Method Summary
|
110
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
111
|
-
</h2>
|
112
|
-
|
113
|
-
<ul class="summary">
|
114
|
-
|
115
|
-
<li class="public ">
|
116
|
-
<span class="summary_signature">
|
117
|
-
|
118
|
-
<a href="#configure-class_method" title="configure (class method)">.<strong>configure</strong> {|configuration| ... } ⇒ Object </a>
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
</span>
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
<span class="summary_desc"><div class='inline'>
|
133
|
-
<p>Allows setting of configuration options.</p>
|
134
|
-
</div></span>
|
135
|
-
|
136
|
-
</li>
|
137
|
-
|
138
|
-
|
139
|
-
</ul>
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
<div id="class_method_details" class="method_details_list">
|
145
|
-
<h2>Class Method Details</h2>
|
146
|
-
|
147
|
-
|
148
|
-
<div class="method_details first">
|
149
|
-
<h3 class="signature first" id="configure-class_method">
|
150
|
-
|
151
|
-
.<strong>configure</strong> {|configuration| ... } ⇒ <tt><span class='object_link'>Object</span></tt>
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
</h3><div class="docstring">
|
158
|
-
<div class="discussion">
|
159
|
-
|
160
|
-
<p>Allows setting of configuration options. See <span class='object_link'><a href="Mocha/Configuration.html" title="Mocha::Configuration (class)">Configuration</a></span> for the available options.</p>
|
161
|
-
|
162
|
-
<p>Typically the configuration is set globally in a <code>test_helper.rb</code> or <code>spec_helper.rb</code> file.</p>
|
163
|
-
|
164
|
-
|
165
|
-
</div>
|
166
|
-
</div>
|
167
|
-
<div class="tags">
|
168
|
-
|
169
|
-
<div class="examples">
|
170
|
-
<p class="tag_title">Examples:</p>
|
171
|
-
|
172
|
-
|
173
|
-
<p class="example_title"><div class='inline'>
|
174
|
-
<p>Setting multiple configuration options</p>
|
175
|
-
</div></p>
|
176
|
-
|
177
|
-
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configure'>configure</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_c'>c</span><span class='op'>|</span>
|
178
|
-
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_unnecessarily'>stubbing_method_unnecessarily</span> <span class='op'>=</span> <span class='symbol'>:prevent</span>
|
179
|
-
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_on_non_mock_object'>stubbing_method_on_non_mock_object</span> <span class='op'>=</span> <span class='symbol'>:warn</span>
|
180
|
-
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_stubbing_method_on_nil'>stubbing_method_on_nil</span> <span class='op'>=</span> <span class='symbol'>:allow</span>
|
181
|
-
<span class='kw'>end</span></code></pre>
|
182
|
-
|
183
|
-
</div>
|
184
|
-
|
185
|
-
<p class="tag_title">Yield Parameters:</p>
|
186
|
-
<ul class="yieldparam">
|
187
|
-
|
188
|
-
<li>
|
189
|
-
|
190
|
-
<span class='name'>configuration</span>
|
191
|
-
|
192
|
-
|
193
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mocha/Configuration.html" title="Mocha::Configuration (class)">Configuration</a></span></tt>)</span>
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
—
|
198
|
-
<div class='inline'>
|
199
|
-
<p>the configuration for modification</p>
|
200
|
-
</div>
|
201
|
-
|
202
|
-
</li>
|
203
|
-
|
204
|
-
</ul>
|
205
|
-
|
206
|
-
<p class="tag_title">See Also:</p>
|
207
|
-
<ul class="see">
|
208
|
-
|
209
|
-
<li><span class='object_link'><a href="Mocha/Configuration.html" title="Mocha::Configuration (class)">Configuration</a></span></li>
|
210
|
-
|
211
|
-
</ul>
|
212
|
-
|
213
|
-
</div><table class="source_code">
|
214
|
-
<tr>
|
215
|
-
<td>
|
216
|
-
<pre class="lines">
|
217
|
-
|
218
|
-
|
219
|
-
17
|
220
|
-
18
|
221
|
-
19</pre>
|
222
|
-
</td>
|
223
|
-
<td>
|
224
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/configuration.rb', line 17</span>
|
225
|
-
|
226
|
-
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_configure'>configure</span>
|
227
|
-
<span class='kw'>yield</span> <span class='id identifier rubyid_configuration'>configuration</span>
|
228
|
-
<span class='kw'>end</span></pre>
|
229
|
-
</td>
|
230
|
-
</tr>
|
231
|
-
</table>
|
232
|
-
</div>
|
233
|
-
|
234
|
-
</div>
|
235
|
-
|
236
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
237
|
-
<script>
|
238
|
-
window.dataLayer = window.dataLayer || [];
|
239
|
-
function gtag(){dataLayer.push(arguments);}
|
240
|
-
gtag('js', new Date());
|
241
|
-
|
242
|
-
gtag('config', 'UA-625523-7');
|
243
|
-
</script>
|
244
|
-
</div>
|
245
|
-
|
246
|
-
<div id="footer">
|
247
|
-
Generated on Thu Dec 12 10:57:46 2019 by
|
248
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
249
|
-
0.9.20 (ruby-2.6.5).
|
250
|
-
</div>
|
251
|
-
|
252
|
-
</div>
|
253
|
-
</body>
|
254
|
-
</html>
|
data/docs/Mocha/API.html
DELETED
@@ -1,1287 +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.10.2
|
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>, <code>MiniTest::Unit::TestCase</code> or equivalent. The mock creation methods are <span class='object_link'><a href="#mock-instance_method" title="Mocha::API#mock (method)">#mock</a></span>, <span class='object_link'><a href="#stub-instance_method" title="Mocha::API#stub (method)">#stub</a></span> and <span class='object_link'><a href="#stub_everything-instance_method" title="Mocha::API#stub_everything (method)">#stub_everything</a></span>, all of which return a #<span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span> which can be further modified by <span class='object_link'><a href="Mock.html#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">Mock#responds_like</a></span> and <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span> methods, both of which return a <span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span>, too, and can therefore, be chained to the original creation methods.</p>
|
100
|
-
|
101
|
-
<p><span class='object_link'><a href="Mock.html#responds_like-instance_method" title="Mocha::Mock#responds_like (method)">Mock#responds_like</a></span> and <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span> force the mock to indicate what it is supposed to be mocking, thus making it a safer verifying mock. They check that the underlying <code>responder</code> will actually respond to the methods being stubbed, throwing a <code>NoMethodError</code> upon invocation otherwise.</p>
|
102
|
-
|
103
|
-
|
104
|
-
</div>
|
105
|
-
</div>
|
106
|
-
<div class="tags">
|
107
|
-
|
108
|
-
<div class="examples">
|
109
|
-
<p class="tag_title">Examples:</p>
|
110
|
-
|
111
|
-
|
112
|
-
<p class="example_title"><div class='inline'>
|
113
|
-
<p>Verifying mock using <span class='object_link'><a href="Mock.html#responds_like_instance_of-instance_method" title="Mocha::Mock#responds_like_instance_of (method)">Mock#responds_like_instance_of</a></span></p>
|
114
|
-
</div></p>
|
115
|
-
|
116
|
-
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>Sheep</span>
|
117
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
|
118
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>some awkward code we don't want to call</span><span class='tstring_end'>"</span></span>
|
119
|
-
<span class='kw'>end</span>
|
120
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_chew'>chew</span><span class='lparen'>(</span><span class='id identifier rubyid_grass'>grass</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
121
|
-
<span class='kw'>end</span>
|
122
|
-
|
123
|
-
<span class='id identifier rubyid_sheep'>sheep</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'>sheep</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_responds_like_instance_of'>responds_like_instance_of</span><span class='lparen'>(</span><span class='const'>Sheep</span><span class='rparen'>)</span>
|
124
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:chew</span><span class='rparen'>)</span>
|
125
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span>
|
126
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:chew</span><span class='rparen'>)</span> <span class='comment'># => true
|
127
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:foo</span><span class='rparen'>)</span> <span class='comment'># => false
|
128
|
-
</span><span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_chew'>chew</span>
|
129
|
-
<span class='id identifier rubyid_sheep'>sheep</span><span class='period'>.</span><span class='id identifier rubyid_foo'>foo</span> <span class='comment'># => raises NoMethodError exception</span></code></pre>
|
130
|
-
|
131
|
-
</div>
|
132
|
-
|
133
|
-
|
134
|
-
</div>
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
<h2>
|
143
|
-
Instance Method Summary
|
144
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
145
|
-
</h2>
|
146
|
-
|
147
|
-
<ul class="summary">
|
148
|
-
|
149
|
-
<li class="public ">
|
150
|
-
<span class="summary_signature">
|
151
|
-
|
152
|
-
<a href="#mock-instance_method" title="#mock (instance method)">#<strong>mock</strong>(*arguments) ⇒ Mock </a>
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
</span>
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
<span class="summary_desc"><div class='inline'>
|
167
|
-
<p>Builds a new mock object.</p>
|
168
|
-
</div></span>
|
169
|
-
|
170
|
-
</li>
|
171
|
-
|
172
|
-
|
173
|
-
<li class="public ">
|
174
|
-
<span class="summary_signature">
|
175
|
-
|
176
|
-
<a href="#sequence-instance_method" title="#sequence (instance method)">#<strong>sequence</strong>(name) ⇒ Sequence </a>
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
</span>
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
<span class="summary_desc"><div class='inline'>
|
191
|
-
<p>Builds a new sequence which can be used to constrain the order in 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="#states-instance_method" title="#states (instance method)">#<strong>states</strong>(name) ⇒ StateMachine </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 state machine which can be used to constrain the order in which expectations can occur.</p>
|
216
|
-
</div></span>
|
217
|
-
|
218
|
-
</li>
|
219
|
-
|
220
|
-
|
221
|
-
<li class="public ">
|
222
|
-
<span class="summary_signature">
|
223
|
-
|
224
|
-
<a href="#stub-instance_method" title="#stub (instance method)">#<strong>stub</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 new mock object.</p>
|
240
|
-
</div></span>
|
241
|
-
|
242
|
-
</li>
|
243
|
-
|
244
|
-
|
245
|
-
<li class="public ">
|
246
|
-
<span class="summary_signature">
|
247
|
-
|
248
|
-
<a href="#stub_everything-instance_method" title="#stub_everything (instance method)">#<strong>stub_everything</strong>(*arguments) ⇒ Mock </a>
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
</span>
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
<span class="summary_desc"><div class='inline'>
|
263
|
-
<p>Builds a mock object that accepts calls to any method.</p>
|
264
|
-
</div></span>
|
265
|
-
|
266
|
-
</li>
|
267
|
-
|
268
|
-
|
269
|
-
</ul>
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span></h3>
|
282
|
-
<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>
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
<h3 class="inherited">Methods included from <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
|
293
|
-
<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_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>
|
294
|
-
|
295
|
-
|
296
|
-
<div id="instance_method_details" class="method_details_list">
|
297
|
-
<h2>Instance Method Details</h2>
|
298
|
-
|
299
|
-
|
300
|
-
<div class="method_details first">
|
301
|
-
<h3 class="signature first" id="mock-instance_method">
|
302
|
-
|
303
|
-
|
304
|
-
<span class="overload">#<strong>mock</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
305
|
-
|
306
|
-
<span class="overload">#<strong>mock</strong>(expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
307
|
-
|
308
|
-
<span class="overload">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
</h3><div class="docstring">
|
316
|
-
<div class="discussion">
|
317
|
-
|
318
|
-
<p>Builds a new mock object</p>
|
319
|
-
|
320
|
-
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
321
|
-
|
322
|
-
|
323
|
-
</div>
|
324
|
-
</div>
|
325
|
-
<div class="tags">
|
326
|
-
|
327
|
-
<div class="examples">
|
328
|
-
<p class="tag_title">Examples:</p>
|
329
|
-
|
330
|
-
|
331
|
-
<p class="example_title"><div class='inline'>
|
332
|
-
<p>Using expected_methods_vs_return_values Hash to setup expectations.</p>
|
333
|
-
</div></p>
|
334
|
-
|
335
|
-
<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>
|
336
|
-
<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>
|
337
|
-
<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>
|
338
|
-
<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>
|
339
|
-
<span class='comment'># an error will be raised unless both Motor#start and Motor#stop have been called
|
340
|
-
</span><span class='kw'>end</span></code></pre>
|
341
|
-
|
342
|
-
</div>
|
343
|
-
|
344
|
-
<p class="tag_title">Overloads:</p>
|
345
|
-
<ul class="overload">
|
346
|
-
|
347
|
-
|
348
|
-
<li class="overload_item">
|
349
|
-
<span class="signature">#<strong>mock</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
350
|
-
<div class="docstring">
|
351
|
-
<div class="discussion">
|
352
|
-
|
353
|
-
<div class="note notetag">
|
354
|
-
<strong>Note:</strong>
|
355
|
-
<div class='inline'>
|
356
|
-
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that expected the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
357
|
-
</div>
|
358
|
-
</div>
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
</div>
|
363
|
-
</div>
|
364
|
-
<div class="tags">
|
365
|
-
<p class="tag_title">Parameters:</p>
|
366
|
-
<ul class="param">
|
367
|
-
|
368
|
-
<li>
|
369
|
-
|
370
|
-
<span class='name'>name</span>
|
371
|
-
|
372
|
-
|
373
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
—
|
378
|
-
<div class='inline'>
|
379
|
-
<p>identifies mock object in error messages.</p>
|
380
|
-
</div>
|
381
|
-
|
382
|
-
</li>
|
383
|
-
|
384
|
-
</ul>
|
385
|
-
|
386
|
-
|
387
|
-
</div>
|
388
|
-
</li>
|
389
|
-
|
390
|
-
|
391
|
-
<li class="overload_item">
|
392
|
-
<span class="signature">#<strong>mock</strong>(expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
393
|
-
<div class="docstring">
|
394
|
-
<div class="discussion">
|
395
|
-
|
396
|
-
|
397
|
-
</div>
|
398
|
-
</div>
|
399
|
-
<div class="tags">
|
400
|
-
<p class="tag_title">Parameters:</p>
|
401
|
-
<ul class="param">
|
402
|
-
|
403
|
-
<li>
|
404
|
-
|
405
|
-
<span class='name'>expected_methods_vs_return_values</span>
|
406
|
-
|
407
|
-
|
408
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
409
|
-
|
410
|
-
|
411
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
412
|
-
|
413
|
-
|
414
|
-
—
|
415
|
-
<div class='inline'>
|
416
|
-
<p>expected method name symbols as keys and corresponding return values as 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 multiple times.</p>
|
417
|
-
</div>
|
418
|
-
|
419
|
-
</li>
|
420
|
-
|
421
|
-
</ul>
|
422
|
-
|
423
|
-
|
424
|
-
</div>
|
425
|
-
</li>
|
426
|
-
|
427
|
-
|
428
|
-
<li class="overload_item">
|
429
|
-
<span class="signature">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
430
|
-
<div class="docstring">
|
431
|
-
<div class="discussion">
|
432
|
-
|
433
|
-
|
434
|
-
</div>
|
435
|
-
</div>
|
436
|
-
<div class="tags">
|
437
|
-
<p class="tag_title">Parameters:</p>
|
438
|
-
<ul class="param">
|
439
|
-
|
440
|
-
<li>
|
441
|
-
|
442
|
-
<span class='name'>name</span>
|
443
|
-
|
444
|
-
|
445
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
—
|
450
|
-
<div class='inline'>
|
451
|
-
<p>identifies mock object in error messages.</p>
|
452
|
-
</div>
|
453
|
-
|
454
|
-
</li>
|
455
|
-
|
456
|
-
<li>
|
457
|
-
|
458
|
-
<span class='name'>expected_methods_vs_return_values</span>
|
459
|
-
|
460
|
-
|
461
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
462
|
-
|
463
|
-
|
464
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
465
|
-
|
466
|
-
|
467
|
-
—
|
468
|
-
<div class='inline'>
|
469
|
-
<p>expected method name symbols as keys and corresponding return values as 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 multiple times.</p>
|
470
|
-
</div>
|
471
|
-
|
472
|
-
</li>
|
473
|
-
|
474
|
-
</ul>
|
475
|
-
|
476
|
-
|
477
|
-
</div>
|
478
|
-
</li>
|
479
|
-
|
480
|
-
</ul>
|
481
|
-
|
482
|
-
<p class="tag_title">Returns:</p>
|
483
|
-
<ul class="return">
|
484
|
-
|
485
|
-
<li>
|
486
|
-
|
487
|
-
|
488
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
—
|
493
|
-
<div class='inline'>
|
494
|
-
<p>a new mock object</p>
|
495
|
-
</div>
|
496
|
-
|
497
|
-
</li>
|
498
|
-
|
499
|
-
</ul>
|
500
|
-
|
501
|
-
</div><table class="source_code">
|
502
|
-
<tr>
|
503
|
-
<td>
|
504
|
-
<pre class="lines">
|
505
|
-
|
506
|
-
|
507
|
-
69
|
508
|
-
70
|
509
|
-
71
|
510
|
-
72
|
511
|
-
73
|
512
|
-
74
|
513
|
-
75
|
514
|
-
76
|
515
|
-
77
|
516
|
-
78
|
517
|
-
79
|
518
|
-
80
|
519
|
-
81
|
520
|
-
82
|
521
|
-
83
|
522
|
-
84
|
523
|
-
85
|
524
|
-
86
|
525
|
-
87
|
526
|
-
88
|
527
|
-
89
|
528
|
-
90
|
529
|
-
91
|
530
|
-
92
|
531
|
-
93</pre>
|
532
|
-
</td>
|
533
|
-
<td>
|
534
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 69</span>
|
535
|
-
|
536
|
-
<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='rparen'>)</span>
|
537
|
-
<span class='kw'>if</span> <span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
538
|
-
<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'>Symbol</span><span class='rparen'>)</span>
|
539
|
-
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
540
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
541
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of expected methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
542
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `mock(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
543
|
-
<span class='rparen'>)</span>
|
544
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
545
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
546
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `mock(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
547
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of expected methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
548
|
-
<span class='rparen'>)</span>
|
549
|
-
<span class='kw'>end</span>
|
550
|
-
<span class='kw'>elsif</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>
|
551
|
-
<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>
|
552
|
-
<span class='kw'>end</span>
|
553
|
-
<span class='kw'>elsif</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> <span class='op'>||</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'>Symbol</span><span class='rparen'>)</span>
|
554
|
-
<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>
|
555
|
-
<span class='kw'>end</span>
|
556
|
-
<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>
|
557
|
-
<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='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>
|
558
|
-
<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>
|
559
|
-
<span class='id identifier rubyid_mock'>mock</span>
|
560
|
-
<span class='kw'>end</span></pre>
|
561
|
-
</td>
|
562
|
-
</tr>
|
563
|
-
</table>
|
564
|
-
</div>
|
565
|
-
|
566
|
-
<div class="method_details ">
|
567
|
-
<h3 class="signature " id="sequence-instance_method">
|
568
|
-
|
569
|
-
#<strong>sequence</strong>(name) ⇒ <tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
</h3><div class="docstring">
|
576
|
-
<div class="discussion">
|
577
|
-
|
578
|
-
<p>Builds a new sequence which can be used to constrain the order in which expectations can occur.</p>
|
579
|
-
|
580
|
-
<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 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>
|
581
|
-
|
582
|
-
|
583
|
-
</div>
|
584
|
-
</div>
|
585
|
-
<div class="tags">
|
586
|
-
|
587
|
-
<div class="examples">
|
588
|
-
<p class="tag_title">Examples:</p>
|
589
|
-
|
590
|
-
|
591
|
-
<p class="example_title"><div class='inline'>
|
592
|
-
<p>Ensure methods on egg are invoked in correct order.</p>
|
593
|
-
</div></p>
|
594
|
-
|
595
|
-
<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>
|
596
|
-
|
597
|
-
<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>
|
598
|
-
<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>
|
599
|
-
<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>
|
600
|
-
<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>
|
601
|
-
<span class='kw'>end</span></code></pre>
|
602
|
-
|
603
|
-
</div>
|
604
|
-
|
605
|
-
<p class="tag_title">Returns:</p>
|
606
|
-
<ul class="return">
|
607
|
-
|
608
|
-
<li>
|
609
|
-
|
610
|
-
|
611
|
-
<span class='type'>(<tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>)</span>
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
—
|
616
|
-
<div class='inline'>
|
617
|
-
<p>a new sequence</p>
|
618
|
-
</div>
|
619
|
-
|
620
|
-
</li>
|
621
|
-
|
622
|
-
</ul>
|
623
|
-
|
624
|
-
<p class="tag_title">See Also:</p>
|
625
|
-
<ul class="see">
|
626
|
-
|
627
|
-
<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>
|
628
|
-
|
629
|
-
</ul>
|
630
|
-
|
631
|
-
</div><table class="source_code">
|
632
|
-
<tr>
|
633
|
-
<td>
|
634
|
-
<pre class="lines">
|
635
|
-
|
636
|
-
|
637
|
-
208
|
638
|
-
209
|
639
|
-
210</pre>
|
640
|
-
</td>
|
641
|
-
<td>
|
642
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 208</span>
|
643
|
-
|
644
|
-
<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>
|
645
|
-
<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>
|
646
|
-
<span class='kw'>end</span></pre>
|
647
|
-
</td>
|
648
|
-
</tr>
|
649
|
-
</table>
|
650
|
-
</div>
|
651
|
-
|
652
|
-
<div class="method_details ">
|
653
|
-
<h3 class="signature " id="states-instance_method">
|
654
|
-
|
655
|
-
#<strong>states</strong>(name) ⇒ <tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
</h3><div class="docstring">
|
662
|
-
<div class="discussion">
|
663
|
-
|
664
|
-
<p>Builds a new state machine which can be used to constrain the order in which expectations can occur.</p>
|
665
|
-
|
666
|
-
<p>Specify the initial state of the state machine by using <span class='object_link'><a href="StateMachine.html#starts_as-instance_method" title="Mocha::StateMachine#starts_as (method)">StateMachine#starts_as</a></span>.</p>
|
667
|
-
|
668
|
-
<p>Specify that an expected invocation should change the state of the state machine by using <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span>.</p>
|
669
|
-
|
670
|
-
<p>Specify that an expected invocation should be constrained to occur within a 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>
|
671
|
-
|
672
|
-
<p>A test can contain multiple state machines.</p>
|
673
|
-
|
674
|
-
|
675
|
-
</div>
|
676
|
-
</div>
|
677
|
-
<div class="tags">
|
678
|
-
|
679
|
-
<div class="examples">
|
680
|
-
<p class="tag_title">Examples:</p>
|
681
|
-
|
682
|
-
|
683
|
-
<p class="example_title"><div class='inline'>
|
684
|
-
<p>Constrain expected invocations to occur in particular states.</p>
|
685
|
-
</div></p>
|
686
|
-
|
687
|
-
<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>
|
688
|
-
|
689
|
-
<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>
|
690
|
-
<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>
|
691
|
-
<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>
|
692
|
-
<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>
|
693
|
-
<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>
|
694
|
-
<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>
|
695
|
-
<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>
|
696
|
-
<span class='kw'>end</span></code></pre>
|
697
|
-
|
698
|
-
</div>
|
699
|
-
|
700
|
-
<p class="tag_title">Returns:</p>
|
701
|
-
<ul class="return">
|
702
|
-
|
703
|
-
<li>
|
704
|
-
|
705
|
-
|
706
|
-
<span class='type'>(<tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>)</span>
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
—
|
711
|
-
<div class='inline'>
|
712
|
-
<p>a new state machine</p>
|
713
|
-
</div>
|
714
|
-
|
715
|
-
</li>
|
716
|
-
|
717
|
-
</ul>
|
718
|
-
|
719
|
-
<p class="tag_title">See Also:</p>
|
720
|
-
<ul class="see">
|
721
|
-
|
722
|
-
<li><span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span></li>
|
723
|
-
|
724
|
-
<li><span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span></li>
|
725
|
-
|
726
|
-
<li><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></li>
|
727
|
-
|
728
|
-
</ul>
|
729
|
-
|
730
|
-
</div><table class="source_code">
|
731
|
-
<tr>
|
732
|
-
<td>
|
733
|
-
<pre class="lines">
|
734
|
-
|
735
|
-
|
736
|
-
238
|
737
|
-
239
|
738
|
-
240</pre>
|
739
|
-
</td>
|
740
|
-
<td>
|
741
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 238</span>
|
742
|
-
|
743
|
-
<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>
|
744
|
-
<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>
|
745
|
-
<span class='kw'>end</span></pre>
|
746
|
-
</td>
|
747
|
-
</tr>
|
748
|
-
</table>
|
749
|
-
</div>
|
750
|
-
|
751
|
-
<div class="method_details ">
|
752
|
-
<h3 class="signature " id="stub-instance_method">
|
753
|
-
|
754
|
-
|
755
|
-
<span class="overload">#<strong>stub</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
756
|
-
|
757
|
-
<span class="overload">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
758
|
-
|
759
|
-
<span class="overload">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
</h3><div class="docstring">
|
767
|
-
<div class="discussion">
|
768
|
-
|
769
|
-
<p>Builds a new mock object</p>
|
770
|
-
|
771
|
-
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
772
|
-
|
773
|
-
|
774
|
-
</div>
|
775
|
-
</div>
|
776
|
-
<div class="tags">
|
777
|
-
|
778
|
-
<div class="examples">
|
779
|
-
<p class="tag_title">Examples:</p>
|
780
|
-
|
781
|
-
|
782
|
-
<p class="example_title"><div class='inline'>
|
783
|
-
<p>Using stubbed_methods_vs_return_values Hash to setup stubbed methods.</p>
|
784
|
-
</div></p>
|
785
|
-
|
786
|
-
<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>
|
787
|
-
<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>
|
788
|
-
<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>
|
789
|
-
<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>
|
790
|
-
<span class='comment'># an error will not be raised even if either Motor#start or Motor#stop has not been called
|
791
|
-
</span><span class='kw'>end</span></code></pre>
|
792
|
-
|
793
|
-
</div>
|
794
|
-
|
795
|
-
<p class="tag_title">Overloads:</p>
|
796
|
-
<ul class="overload">
|
797
|
-
|
798
|
-
|
799
|
-
<li class="overload_item">
|
800
|
-
<span class="signature">#<strong>stub</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
801
|
-
<div class="docstring">
|
802
|
-
<div class="discussion">
|
803
|
-
|
804
|
-
<div class="note notetag">
|
805
|
-
<strong>Note:</strong>
|
806
|
-
<div class='inline'>
|
807
|
-
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that stubbed the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
808
|
-
</div>
|
809
|
-
</div>
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
</div>
|
814
|
-
</div>
|
815
|
-
<div class="tags">
|
816
|
-
<p class="tag_title">Parameters:</p>
|
817
|
-
<ul class="param">
|
818
|
-
|
819
|
-
<li>
|
820
|
-
|
821
|
-
<span class='name'>name</span>
|
822
|
-
|
823
|
-
|
824
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
—
|
829
|
-
<div class='inline'>
|
830
|
-
<p>identifies mock object in error messages.</p>
|
831
|
-
</div>
|
832
|
-
|
833
|
-
</li>
|
834
|
-
|
835
|
-
</ul>
|
836
|
-
|
837
|
-
|
838
|
-
</div>
|
839
|
-
</li>
|
840
|
-
|
841
|
-
|
842
|
-
<li class="overload_item">
|
843
|
-
<span class="signature">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
844
|
-
<div class="docstring">
|
845
|
-
<div class="discussion">
|
846
|
-
|
847
|
-
|
848
|
-
</div>
|
849
|
-
</div>
|
850
|
-
<div class="tags">
|
851
|
-
<p class="tag_title">Parameters:</p>
|
852
|
-
<ul class="param">
|
853
|
-
|
854
|
-
<li>
|
855
|
-
|
856
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
857
|
-
|
858
|
-
|
859
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
860
|
-
|
861
|
-
|
862
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
863
|
-
|
864
|
-
|
865
|
-
—
|
866
|
-
<div class='inline'>
|
867
|
-
<p>stubbed method name symbols as keys and corresponding return values as 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 multiple times.</p>
|
868
|
-
</div>
|
869
|
-
|
870
|
-
</li>
|
871
|
-
|
872
|
-
</ul>
|
873
|
-
|
874
|
-
|
875
|
-
</div>
|
876
|
-
</li>
|
877
|
-
|
878
|
-
|
879
|
-
<li class="overload_item">
|
880
|
-
<span class="signature">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
881
|
-
<div class="docstring">
|
882
|
-
<div class="discussion">
|
883
|
-
|
884
|
-
|
885
|
-
</div>
|
886
|
-
</div>
|
887
|
-
<div class="tags">
|
888
|
-
<p class="tag_title">Parameters:</p>
|
889
|
-
<ul class="param">
|
890
|
-
|
891
|
-
<li>
|
892
|
-
|
893
|
-
<span class='name'>name</span>
|
894
|
-
|
895
|
-
|
896
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
—
|
901
|
-
<div class='inline'>
|
902
|
-
<p>identifies mock object in error messages.</p>
|
903
|
-
</div>
|
904
|
-
|
905
|
-
</li>
|
906
|
-
|
907
|
-
</ul>
|
908
|
-
|
909
|
-
|
910
|
-
</div>
|
911
|
-
</li>
|
912
|
-
|
913
|
-
</ul>
|
914
|
-
|
915
|
-
<p class="tag_title">Returns:</p>
|
916
|
-
<ul class="return">
|
917
|
-
|
918
|
-
<li>
|
919
|
-
|
920
|
-
|
921
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
—
|
926
|
-
<div class='inline'>
|
927
|
-
<p>a new mock object</p>
|
928
|
-
</div>
|
929
|
-
|
930
|
-
</li>
|
931
|
-
|
932
|
-
</ul>
|
933
|
-
|
934
|
-
</div><table class="source_code">
|
935
|
-
<tr>
|
936
|
-
<td>
|
937
|
-
<pre class="lines">
|
938
|
-
|
939
|
-
|
940
|
-
116
|
941
|
-
117
|
942
|
-
118
|
943
|
-
119
|
944
|
-
120
|
945
|
-
121
|
946
|
-
122
|
947
|
-
123
|
948
|
-
124
|
949
|
-
125
|
950
|
-
126
|
951
|
-
127
|
952
|
-
128
|
953
|
-
129
|
954
|
-
130
|
955
|
-
131
|
956
|
-
132
|
957
|
-
133
|
958
|
-
134
|
959
|
-
135
|
960
|
-
136
|
961
|
-
137
|
962
|
-
138
|
963
|
-
139
|
964
|
-
140</pre>
|
965
|
-
</td>
|
966
|
-
<td>
|
967
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 116</span>
|
968
|
-
|
969
|
-
<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='rparen'>)</span>
|
970
|
-
<span class='kw'>if</span> <span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
971
|
-
<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'>Symbol</span><span class='rparen'>)</span>
|
972
|
-
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
973
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
974
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of stubbed methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
975
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `stub(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
976
|
-
<span class='rparen'>)</span>
|
977
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
978
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
979
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `stub(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
980
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of stubbed methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
981
|
-
<span class='rparen'>)</span>
|
982
|
-
<span class='kw'>end</span>
|
983
|
-
<span class='kw'>elsif</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>
|
984
|
-
<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>
|
985
|
-
<span class='kw'>end</span>
|
986
|
-
<span class='kw'>elsif</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> <span class='op'>||</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'>Symbol</span><span class='rparen'>)</span>
|
987
|
-
<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>
|
988
|
-
<span class='kw'>end</span>
|
989
|
-
<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>
|
990
|
-
<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='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>
|
991
|
-
<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>
|
992
|
-
<span class='id identifier rubyid_stub'>stub</span>
|
993
|
-
<span class='kw'>end</span></pre>
|
994
|
-
</td>
|
995
|
-
</tr>
|
996
|
-
</table>
|
997
|
-
</div>
|
998
|
-
|
999
|
-
<div class="method_details ">
|
1000
|
-
<h3 class="signature " id="stub_everything-instance_method">
|
1001
|
-
|
1002
|
-
|
1003
|
-
<span class="overload">#<strong>stub_everything</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1004
|
-
|
1005
|
-
<span class="overload">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1006
|
-
|
1007
|
-
<span class="overload">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
</h3><div class="docstring">
|
1015
|
-
<div class="discussion">
|
1016
|
-
|
1017
|
-
<p>Builds a mock object that accepts calls to any method. By default it will return <code>nil</code> for any method call.</p>
|
1018
|
-
|
1019
|
-
<p>rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity</p>
|
1020
|
-
|
1021
|
-
|
1022
|
-
</div>
|
1023
|
-
</div>
|
1024
|
-
<div class="tags">
|
1025
|
-
|
1026
|
-
<div class="examples">
|
1027
|
-
<p class="tag_title">Examples:</p>
|
1028
|
-
|
1029
|
-
|
1030
|
-
<p class="example_title"><div class='inline'>
|
1031
|
-
<p>Ignore invocations of irrelevant methods.</p>
|
1032
|
-
</div></p>
|
1033
|
-
|
1034
|
-
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_stops'>test_motor_stops</span>
|
1035
|
-
<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>
|
1036
|
-
<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
|
1037
|
-
</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
|
1038
|
-
</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>
|
1039
|
-
<span class='kw'>end</span></code></pre>
|
1040
|
-
|
1041
|
-
</div>
|
1042
|
-
|
1043
|
-
<p class="tag_title">Overloads:</p>
|
1044
|
-
<ul class="overload">
|
1045
|
-
|
1046
|
-
|
1047
|
-
<li class="overload_item">
|
1048
|
-
<span class="signature">#<strong>stub_everything</strong>(name) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1049
|
-
<div class="docstring">
|
1050
|
-
<div class="discussion">
|
1051
|
-
|
1052
|
-
<div class="note notetag">
|
1053
|
-
<strong>Note:</strong>
|
1054
|
-
<div class='inline'>
|
1055
|
-
<p>Prior to v1.10.0 when <code>name</code> was a <code>Symbol</code>, this method returned an unnamed <code>Mock</code> that stubbed the method identified by <code>name</code>. This was undocumented behaviour and it will be removed in the future, but for the moment it can be reinstated using <span class='object_link'><a href="Configuration.html#reinstate_undocumented_behaviour_from_v1_9=-instance_method" title="Mocha::Configuration#reinstate_undocumented_behaviour_from_v1_9= (method)">Configuration#reinstate_undocumented_behaviour_from_v1_9=</a></span>.</p>
|
1056
|
-
</div>
|
1057
|
-
</div>
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
</div>
|
1062
|
-
</div>
|
1063
|
-
<div class="tags">
|
1064
|
-
<p class="tag_title">Parameters:</p>
|
1065
|
-
<ul class="param">
|
1066
|
-
|
1067
|
-
<li>
|
1068
|
-
|
1069
|
-
<span class='name'>name</span>
|
1070
|
-
|
1071
|
-
|
1072
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
—
|
1077
|
-
<div class='inline'>
|
1078
|
-
<p>identifies mock object in error messages.</p>
|
1079
|
-
</div>
|
1080
|
-
|
1081
|
-
</li>
|
1082
|
-
|
1083
|
-
</ul>
|
1084
|
-
|
1085
|
-
|
1086
|
-
</div>
|
1087
|
-
</li>
|
1088
|
-
|
1089
|
-
|
1090
|
-
<li class="overload_item">
|
1091
|
-
<span class="signature">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1092
|
-
<div class="docstring">
|
1093
|
-
<div class="discussion">
|
1094
|
-
|
1095
|
-
|
1096
|
-
</div>
|
1097
|
-
</div>
|
1098
|
-
<div class="tags">
|
1099
|
-
<p class="tag_title">Parameters:</p>
|
1100
|
-
<ul class="param">
|
1101
|
-
|
1102
|
-
<li>
|
1103
|
-
|
1104
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
1105
|
-
|
1106
|
-
|
1107
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
1108
|
-
|
1109
|
-
|
1110
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
1111
|
-
|
1112
|
-
|
1113
|
-
—
|
1114
|
-
<div class='inline'>
|
1115
|
-
<p>stubbed method name symbols as keys and corresponding return values as 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 multiple times.</p>
|
1116
|
-
</div>
|
1117
|
-
|
1118
|
-
</li>
|
1119
|
-
|
1120
|
-
</ul>
|
1121
|
-
|
1122
|
-
|
1123
|
-
</div>
|
1124
|
-
</li>
|
1125
|
-
|
1126
|
-
|
1127
|
-
<li class="overload_item">
|
1128
|
-
<span class="signature">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
1129
|
-
<div class="docstring">
|
1130
|
-
<div class="discussion">
|
1131
|
-
|
1132
|
-
|
1133
|
-
</div>
|
1134
|
-
</div>
|
1135
|
-
<div class="tags">
|
1136
|
-
<p class="tag_title">Parameters:</p>
|
1137
|
-
<ul class="param">
|
1138
|
-
|
1139
|
-
<li>
|
1140
|
-
|
1141
|
-
<span class='name'>name</span>
|
1142
|
-
|
1143
|
-
|
1144
|
-
<span class='type'>(<tt>String</tt>, <tt>Symbol</tt>)</span>
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
—
|
1149
|
-
<div class='inline'>
|
1150
|
-
<p>identifies mock object in error messages.</p>
|
1151
|
-
</div>
|
1152
|
-
|
1153
|
-
</li>
|
1154
|
-
|
1155
|
-
<li>
|
1156
|
-
|
1157
|
-
<span class='name'>stubbed_methods_vs_return_values</span>
|
1158
|
-
|
1159
|
-
|
1160
|
-
<span class='type'>(<tt>Hash</tt>)</span>
|
1161
|
-
|
1162
|
-
|
1163
|
-
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
1164
|
-
|
1165
|
-
|
1166
|
-
—
|
1167
|
-
<div class='inline'>
|
1168
|
-
<p>stubbed method name symbols as keys and corresponding return values as 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 multiple times.</p>
|
1169
|
-
</div>
|
1170
|
-
|
1171
|
-
</li>
|
1172
|
-
|
1173
|
-
</ul>
|
1174
|
-
|
1175
|
-
|
1176
|
-
</div>
|
1177
|
-
</li>
|
1178
|
-
|
1179
|
-
</ul>
|
1180
|
-
|
1181
|
-
<p class="tag_title">Returns:</p>
|
1182
|
-
<ul class="return">
|
1183
|
-
|
1184
|
-
<li>
|
1185
|
-
|
1186
|
-
|
1187
|
-
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
—
|
1192
|
-
<div class='inline'>
|
1193
|
-
<p>a new mock object</p>
|
1194
|
-
</div>
|
1195
|
-
|
1196
|
-
</li>
|
1197
|
-
|
1198
|
-
</ul>
|
1199
|
-
|
1200
|
-
</div><table class="source_code">
|
1201
|
-
<tr>
|
1202
|
-
<td>
|
1203
|
-
<pre class="lines">
|
1204
|
-
|
1205
|
-
|
1206
|
-
164
|
1207
|
-
165
|
1208
|
-
166
|
1209
|
-
167
|
1210
|
-
168
|
1211
|
-
169
|
1212
|
-
170
|
1213
|
-
171
|
1214
|
-
172
|
1215
|
-
173
|
1216
|
-
174
|
1217
|
-
175
|
1218
|
-
176
|
1219
|
-
177
|
1220
|
-
178
|
1221
|
-
179
|
1222
|
-
180
|
1223
|
-
181
|
1224
|
-
182
|
1225
|
-
183
|
1226
|
-
184
|
1227
|
-
185
|
1228
|
-
186
|
1229
|
-
187
|
1230
|
-
188
|
1231
|
-
189</pre>
|
1232
|
-
</td>
|
1233
|
-
<td>
|
1234
|
-
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 164</span>
|
1235
|
-
|
1236
|
-
<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='rparen'>)</span>
|
1237
|
-
<span class='kw'>if</span> <span class='const'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span><span class='period'>.</span><span class='id identifier rubyid_configuration'>configuration</span><span class='period'>.</span><span class='id identifier rubyid_reinstate_undocumented_behaviour_from_v1_9?'>reinstate_undocumented_behaviour_from_v1_9?</span>
|
1238
|
-
<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'>Symbol</span><span class='rparen'>)</span>
|
1239
|
-
<span class='id identifier rubyid_method_name'>method_name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
1240
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
1241
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Explicitly include `</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>` in Hash of stubbed methods vs return values,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
1242
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> e.g. `stub_everything(:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'> => nil)`.</span><span class='tstring_end'>"</span></span>
|
1243
|
-
<span class='rparen'>)</span>
|
1244
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span>
|
1245
|
-
<span class='const'>Deprecation</span><span class='period'>.</span><span class='id identifier rubyid_warning'>warning</span><span class='lparen'>(</span>
|
1246
|
-
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>In this case the 2nd argument for `stub_everything(:#</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_method_name'>method_name</span><span class='embexpr_end'>}</span><span class='tstring_content'>, ...)` is ignored,</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
1247
|
-
<span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> but in the future a Hash of stubbed methods vs return values will be respected.</span><span class='tstring_end'>'</span></span>
|
1248
|
-
<span class='rparen'>)</span>
|
1249
|
-
<span class='kw'>end</span>
|
1250
|
-
<span class='kw'>elsif</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>
|
1251
|
-
<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>
|
1252
|
-
<span class='kw'>end</span>
|
1253
|
-
<span class='kw'>elsif</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> <span class='op'>||</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'>Symbol</span><span class='rparen'>)</span>
|
1254
|
-
<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>
|
1255
|
-
<span class='kw'>end</span>
|
1256
|
-
<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>
|
1257
|
-
<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='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>
|
1258
|
-
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stub_everything'>stub_everything</span>
|
1259
|
-
<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>
|
1260
|
-
<span class='id identifier rubyid_stub'>stub</span>
|
1261
|
-
<span class='kw'>end</span></pre>
|
1262
|
-
</td>
|
1263
|
-
</tr>
|
1264
|
-
</table>
|
1265
|
-
</div>
|
1266
|
-
|
1267
|
-
</div>
|
1268
|
-
|
1269
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
1270
|
-
<script>
|
1271
|
-
window.dataLayer = window.dataLayer || [];
|
1272
|
-
function gtag(){dataLayer.push(arguments);}
|
1273
|
-
gtag('js', new Date());
|
1274
|
-
|
1275
|
-
gtag('config', 'UA-625523-7');
|
1276
|
-
</script>
|
1277
|
-
</div>
|
1278
|
-
|
1279
|
-
<div id="footer">
|
1280
|
-
Generated on Thu Dec 12 10:57:47 2019 by
|
1281
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1282
|
-
0.9.20 (ruby-2.6.5).
|
1283
|
-
</div>
|
1284
|
-
|
1285
|
-
</div>
|
1286
|
-
</body>
|
1287
|
-
</html>
|