mocha 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +4 -9
- data/README.md +17 -16
- data/RELEASE.md +10 -0
- data/Rakefile +6 -13
- data/bin/build-matrix +16 -2
- data/docs/CNAME +1 -0
- data/docs/Mocha.html +127 -0
- data/docs/Mocha/API.html +1056 -0
- data/docs/Mocha/ClassMethods.html +267 -0
- data/docs/Mocha/Configuration.html +626 -0
- data/docs/Mocha/Expectation.html +2709 -0
- data/docs/Mocha/ExpectationError.html +157 -0
- data/docs/Mocha/ExpectationErrorFactory.html +269 -0
- data/docs/Mocha/Hooks.html +385 -0
- data/docs/Mocha/Integration.html +125 -0
- data/docs/Mocha/Integration/MiniTest.html +123 -0
- data/docs/Mocha/Integration/MiniTest/Adapter.html +165 -0
- data/docs/Mocha/Integration/TestUnit.html +123 -0
- data/docs/Mocha/Integration/TestUnit/Adapter.html +165 -0
- data/docs/Mocha/Mock.html +1197 -0
- data/docs/Mocha/ObjectMethods.html +712 -0
- data/docs/Mocha/ParameterMatchers.html +3049 -0
- data/docs/Mocha/ParameterMatchers/AllOf.html +154 -0
- data/docs/Mocha/ParameterMatchers/AnyOf.html +154 -0
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
- data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
- data/docs/Mocha/ParameterMatchers/Base.html +448 -0
- data/docs/Mocha/ParameterMatchers/Equals.html +154 -0
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasEntries.html +154 -0
- data/docs/Mocha/ParameterMatchers/HasEntry.html +154 -0
- data/docs/Mocha/ParameterMatchers/HasKey.html +154 -0
- data/docs/Mocha/ParameterMatchers/HasValue.html +154 -0
- data/docs/Mocha/ParameterMatchers/Includes.html +154 -0
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +154 -0
- data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
- data/docs/Mocha/ParameterMatchers/KindOf.html +154 -0
- data/docs/Mocha/ParameterMatchers/Not.html +154 -0
- data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +154 -0
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +154 -0
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +154 -0
- data/docs/Mocha/Sequence.html +149 -0
- data/docs/Mocha/StateMachine.html +539 -0
- data/docs/Mocha/StateMachine/State.html +141 -0
- data/docs/Mocha/StateMachine/StatePredicate.html +141 -0
- data/docs/Mocha/StubbingError.html +150 -0
- data/docs/Mocha/UnexpectedInvocation.html +140 -0
- data/docs/_index.html +537 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.COPYING.html +81 -0
- data/docs/file.MIT-LICENSE.html +85 -0
- data/docs/file.README.html +418 -0
- data/docs/file.RELEASE.html +875 -0
- data/docs/file_list.html +71 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +418 -0
- data/docs/js/app.js +292 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +571 -0
- data/docs/top-level-namespace.html +118 -0
- data/lib/mocha/inspect.rb +1 -1
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +2 -3
- data/test/unit/object_inspect_test.rb +10 -0
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- metadata +68 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c0293e3246e6c08b3091803488531187ef47253ec22fbcd0b48921e401aa9e
|
4
|
+
data.tar.gz: 34c50006ebf871ed458dd97d2057caeeca9ae329a41da8d9abeb8e818a9f7042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3004d3ac125a41336d2138c35cf581cb05c51b96b7ecd895422715e84db62dca230ad96828c2a8c5f08b7ac0e00d0721aee20a8d17f6ef88b810c0b025bae3b
|
7
|
+
data.tar.gz: 3dab739556bbab55d0ded0fb0f81368a7b17f3cc5a635e65a9b5c5e6c9a5b2700f0b4f1d15db887fd8b477d89b28f8147382a4403589de265a6c6e7335adc724
|
data/CONTRIBUTING.md
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
* Pull requests are welcomed.
|
2
2
|
* Fork the repository.
|
3
3
|
* Make your changes in a branch.
|
4
|
-
* Add
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
* I use `rbenv-aliases` to alias the patch versions.
|
9
|
-
* Note that the build matrix takes quite a while to run.
|
10
|
-
* Send us a pull request from your fork/branch.
|
11
|
-
* Wait for your pull request to build on [Travis CI](https://travis-ci.org/freerange/mocha).
|
12
|
-
* I will not accept pull requests with failing tests.
|
4
|
+
* Add/modify/remove tests as appropriate.
|
5
|
+
* Open a pull request based on a branch on your fork.
|
6
|
+
* Wait for your pull request build to pass on [Travis CI](https://travis-ci.org/freerange/mocha/pull_requests).
|
7
|
+
* Pull requests with failing tests will not be accepted.
|
data/README.md
CHANGED
@@ -264,7 +264,7 @@ Stubs and expectations are basically the same thing. A stub is just an expectati
|
|
264
264
|
|
265
265
|
When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations.
|
266
266
|
|
267
|
-
See the [documentation](
|
267
|
+
See the [documentation](https://mocha.jamesmead.org/Mocha/Mock.html) for `Mocha::Mock` for further details.
|
268
268
|
|
269
269
|
### Configuration
|
270
270
|
|
@@ -275,11 +275,11 @@ If you want, Mocha can generate a warning or raise an exception when:
|
|
275
275
|
* stubbing a non-existent method
|
276
276
|
* stubbing a non-public method
|
277
277
|
|
278
|
-
See the [documentation](
|
278
|
+
See the [documentation](https://mocha.jamesmead.org/Mocha/Configuration.html) for `Mocha::Configuration` for further details.
|
279
279
|
|
280
280
|
### Useful Links
|
281
281
|
|
282
|
-
* [Official Documentation](
|
282
|
+
* [Official Documentation](https://mocha.jamesmead.org)
|
283
283
|
* [Source Code](http://github.com/freerange/mocha)
|
284
284
|
* [Mailing List](http://groups.google.com/group/mocha-developer)
|
285
285
|
* [James Mead's Blog](http://jamesmead.org/blog/)
|
@@ -293,37 +293,38 @@ See the [documentation](http://gofreerange.com/mocha/docs/Mocha/Configuration.ht
|
|
293
293
|
|
294
294
|
See this [list of contributors](https://github.com/freerange/mocha/graphs/contributors).
|
295
295
|
|
296
|
-
### Translations
|
297
|
-
|
298
|
-
* [Serbo-Croatian](http://science.webhostinggeeks.com/mocha) by [WHG Team](http://webhostinggeeks.com/). (may be out-of-date)
|
299
|
-
|
300
296
|
### Releasing a new version
|
301
297
|
|
302
298
|
* Update the RELEASE.md file with a summary of changes
|
303
299
|
* Bump the version in `lib/mocha/version.rb`
|
304
|
-
* Commit & push to
|
300
|
+
* Commit & push to GitHub
|
305
301
|
* Check Travis CI build is passing - https://travis-ci.org/freerange/mocha
|
306
302
|
|
303
|
+
* Sign in to Google Analytics - https://analytics.google.com/analytics/web/
|
304
|
+
* Find the web property ID for Go Free Range Ltd > Mocha Documentation (UA-45002715-2)
|
305
|
+
* Generate documentation:
|
306
|
+
|
307
|
+
```bash
|
308
|
+
$ MOCHA_GENERATE_DOCS=true bundle install
|
309
|
+
|
310
|
+
$ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-45002715-2 rake generate_docs
|
311
|
+
```
|
312
|
+
* Commit documentation & push to GitHub
|
307
313
|
* Sign in to rubygems.org and find API key - https://rubygems.org/profile/edit
|
308
314
|
|
309
315
|
```bash
|
310
316
|
$ curl -u james@floehopper.org https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials`
|
311
317
|
```
|
312
318
|
|
313
|
-
*
|
314
|
-
* Find the web property ID for Go Free Range Ltd > Mocha Documentation (UA-45002715-2)
|
319
|
+
* Release gem to Rubygems:
|
315
320
|
|
316
321
|
```bash
|
317
|
-
$
|
318
|
-
|
319
|
-
$ MOCHA_GENERATE_DOCS=true GOOGLE_ANALYTICS_WEB_PROPERTY_ID=UA-45002715-2 rake release
|
322
|
+
$ rake release
|
323
|
+
[runs tests]
|
320
324
|
mocha 1.2.0 built to pkg/mocha-1.2.0.gem.
|
321
325
|
Tagged v1.2.0.
|
322
326
|
Pushed git commits and tags.
|
323
327
|
Pushed mocha 1.2.0 to rubygems.org.
|
324
|
-
[runs tests]
|
325
|
-
[generates docs]
|
326
|
-
[deploys docs]
|
327
328
|
```
|
328
329
|
|
329
330
|
### History
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Release Notes
|
2
2
|
|
3
|
+
## 1.8.0
|
4
|
+
|
5
|
+
* Constrain rubocop version to avoid breaking Travis CI builds (05e507f5)
|
6
|
+
* Avoid calling Kernel#format from ObjectMethods#mocha_inspect - thanks to @hoffmanilya (#345)
|
7
|
+
* Fix build matrix script (#346)
|
8
|
+
* Avoid deprecation warning in gemspec (4976e0bc)
|
9
|
+
* Removed link to documentation translation (ef428ea2)
|
10
|
+
* Don't use the new bundler v2 in builds (683ded9b)
|
11
|
+
* Moved documentation from https://gofreerange.com/mocha/docs to https://mocha.jamesmead.org/ [683ded...a17fde](https://github.com/freerange/mocha/compare/683ded...a17fde)
|
12
|
+
|
3
13
|
## 1.7.0
|
4
14
|
|
5
15
|
* Update Ruby & JRuby versions in Travis CI config (9bf55631 & 3883af7e)
|
data/Rakefile
CHANGED
@@ -2,8 +2,6 @@ require 'bundler'
|
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
require 'bundler/setup'
|
4
4
|
|
5
|
-
MOCHA_DOCS_HOST = ENV['MOCHA_DOCS_HOST'] || 'gofreerange.com'
|
6
|
-
|
7
5
|
require 'rake/testtask'
|
8
6
|
|
9
7
|
desc 'Run all tests'
|
@@ -127,7 +125,7 @@ if ENV['MOCHA_GENERATE_DOCS']
|
|
127
125
|
|
128
126
|
desc 'Remove generated documentation'
|
129
127
|
task 'clobber_yardoc' do
|
130
|
-
`rm -rf ./
|
128
|
+
`rm -rf ./docs`
|
131
129
|
end
|
132
130
|
|
133
131
|
task 'docs_environment' do
|
@@ -138,19 +136,14 @@ if ENV['MOCHA_GENERATE_DOCS']
|
|
138
136
|
|
139
137
|
desc 'Generate documentation'
|
140
138
|
YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
|
141
|
-
task.options = [
|
139
|
+
task.options = [
|
140
|
+
'--title', "Mocha #{Mocha::VERSION}",
|
141
|
+
'--output-dir', 'docs'
|
142
|
+
]
|
142
143
|
end
|
143
144
|
|
144
145
|
desc 'Generate documentation'
|
145
146
|
task 'generate_docs' => %w[clobber_yardoc yardoc]
|
146
|
-
|
147
|
-
desc "Publish docs to #{MOCHA_DOCS_HOST}/docs/mocha"
|
148
|
-
task 'publish_docs' => 'generate_docs' do
|
149
|
-
path = '/home/freerange/docs/mocha'
|
150
|
-
system %(ssh #{MOCHA_DOCS_HOST} "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* #{MOCHA_DOCS_HOST}:#{path})
|
151
|
-
end
|
152
147
|
end
|
153
148
|
|
154
|
-
task 'release' => 'default'
|
155
|
-
Rake::Task['publish_docs'].invoke
|
156
|
-
end
|
149
|
+
task 'release' => 'default'
|
data/bin/build-matrix
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'set'
|
5
|
+
require 'English'
|
4
6
|
|
5
7
|
def execute(*commands)
|
6
8
|
commands.each do |command|
|
@@ -34,11 +36,14 @@ def run(ruby_version, gemfile, task = 'test')
|
|
34
36
|
ENV['MOCHA_OPTIONS'] = 'debug'
|
35
37
|
reset_bundle
|
36
38
|
execute(
|
39
|
+
with_rbenv('gem update bundler --force --no-post-install-message'),
|
37
40
|
with_rbenv("bundle install --gemfile=#{gemfile}"),
|
38
41
|
with_rbenv("bundle exec rake #{task}")
|
39
42
|
)
|
40
43
|
end
|
41
44
|
|
45
|
+
AVAILABLE_RUBY_VERSIONS = `rbenv versions --bare`.split("\n")
|
46
|
+
|
42
47
|
travis_config = YAML.safe_load(File.read('.travis.yml'))
|
43
48
|
build_configs = travis_config['matrix']['include']
|
44
49
|
travis_config['rvm'].each do |ruby_version|
|
@@ -49,6 +54,8 @@ travis_config['rvm'].each do |ruby_version|
|
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
57
|
+
missing_ruby_versions = Set.new
|
58
|
+
|
52
59
|
build_configs.each do |config|
|
53
60
|
ruby_version = config['rvm']
|
54
61
|
gemfile = config['gemfile']
|
@@ -59,11 +66,18 @@ build_configs.each do |config|
|
|
59
66
|
original_environment_variables[k] = ENV[k]
|
60
67
|
ENV[k] = v
|
61
68
|
end
|
62
|
-
|
63
|
-
|
69
|
+
if AVAILABLE_RUBY_VERSIONS.include?(ruby_version)
|
70
|
+
puts
|
71
|
+
puts "Ruby v#{ruby_version}; Gemfile path: #{gemfile}; Environment: #{environment_variables}"
|
72
|
+
run(ruby_version, gemfile)
|
73
|
+
else
|
74
|
+
missing_ruby_versions << ruby_version
|
75
|
+
end
|
64
76
|
ensure
|
65
77
|
original_environment_variables.each do |k, v|
|
66
78
|
ENV[k] = v
|
67
79
|
end
|
68
80
|
end
|
69
81
|
end
|
82
|
+
|
83
|
+
puts "Missing Ruby versions: #{missing_ruby_versions.join(', ')}"
|
data/docs/CNAME
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mocha.jamesmead.org
|
data/docs/Mocha.html
ADDED
@@ -0,0 +1,127 @@
|
|
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.8.0
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "Mocha";
|
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/object.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/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/unexpected_invocation.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>, <span class='object_link'><a href="Mocha/UnexpectedInvocation.html" title="Mocha::UnexpectedInvocation (class)">UnexpectedInvocation</a></span>
|
97
|
+
|
98
|
+
|
99
|
+
</p>
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
110
|
+
<script>
|
111
|
+
window.dataLayer = window.dataLayer || [];
|
112
|
+
function gtag(){dataLayer.push(arguments);}
|
113
|
+
gtag('js', new Date());
|
114
|
+
|
115
|
+
gtag('config', 'UA-625523-7');
|
116
|
+
</script>
|
117
|
+
</div>
|
118
|
+
|
119
|
+
<div id="footer">
|
120
|
+
Generated on Tue Jan 15 17:13:05 2019 by
|
121
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
122
|
+
0.9.16 (ruby-2.5.3).
|
123
|
+
</div>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
</body>
|
127
|
+
</html>
|
data/docs/Mocha/API.html
ADDED
@@ -0,0 +1,1056 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: Mocha::API
|
8
|
+
|
9
|
+
— Mocha 1.8.0
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "Mocha::API";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (A)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Mocha.html" title="Mocha (module)">Mocha</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">API</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: Mocha::API
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
<dl>
|
75
|
+
<dt>Includes:</dt>
|
76
|
+
<dd><span class='object_link'><a href="Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span>, <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></dd>
|
77
|
+
</dl>
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
<dl>
|
83
|
+
<dt>Included in:</dt>
|
84
|
+
<dd><span class='object_link'><a href="Integration/MiniTest/Adapter.html" title="Mocha::Integration::MiniTest::Adapter (module)">Integration::MiniTest::Adapter</a></span>, <span class='object_link'><a href="Integration/TestUnit/Adapter.html" title="Mocha::Integration::TestUnit::Adapter (module)">Integration::TestUnit::Adapter</a></span></dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<dl>
|
90
|
+
<dt>Defined in:</dt>
|
91
|
+
<dd>lib/mocha/api.rb</dd>
|
92
|
+
</dl>
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<h2>Overview</h2><div class="docstring">
|
97
|
+
<div class="discussion">
|
98
|
+
|
99
|
+
<p>Methods added to <code>Test::Unit::TestCase</code>,
|
100
|
+
<code>MiniTest::Unit::TestCase</code> or equivalent.</p>
|
101
|
+
|
102
|
+
|
103
|
+
</div>
|
104
|
+
</div>
|
105
|
+
<div class="tags">
|
106
|
+
|
107
|
+
|
108
|
+
</div>
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
<h2>
|
117
|
+
Instance Method Summary
|
118
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
119
|
+
</h2>
|
120
|
+
|
121
|
+
<ul class="summary">
|
122
|
+
|
123
|
+
<li class="public ">
|
124
|
+
<span class="summary_signature">
|
125
|
+
|
126
|
+
<a href="#mock-instance_method" title="#mock (instance method)">#<strong>mock</strong>(*arguments) { ... } ⇒ Mock </a>
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
</span>
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
<span class="summary_desc"><div class='inline'>
|
141
|
+
<p>Builds a new mock object.</p>
|
142
|
+
</div></span>
|
143
|
+
|
144
|
+
</li>
|
145
|
+
|
146
|
+
|
147
|
+
<li class="public ">
|
148
|
+
<span class="summary_signature">
|
149
|
+
|
150
|
+
<a href="#sequence-instance_method" title="#sequence (instance method)">#<strong>sequence</strong>(name) ⇒ Sequence </a>
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
</span>
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
<span class="summary_desc"><div class='inline'>
|
165
|
+
<p>Builds a new sequence which can be used to constrain the order in which
|
166
|
+
expectations can occur.</p>
|
167
|
+
</div></span>
|
168
|
+
|
169
|
+
</li>
|
170
|
+
|
171
|
+
|
172
|
+
<li class="public ">
|
173
|
+
<span class="summary_signature">
|
174
|
+
|
175
|
+
<a href="#states-instance_method" title="#states (instance method)">#<strong>states</strong>(name) ⇒ StateMachine </a>
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
</span>
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
<span class="summary_desc"><div class='inline'>
|
190
|
+
<p>Builds a new state machine which can be used to constrain the order in
|
191
|
+
which expectations can occur.</p>
|
192
|
+
</div></span>
|
193
|
+
|
194
|
+
</li>
|
195
|
+
|
196
|
+
|
197
|
+
<li class="public ">
|
198
|
+
<span class="summary_signature">
|
199
|
+
|
200
|
+
<a href="#stub-instance_method" title="#stub (instance method)">#<strong>stub</strong>(*arguments) { ... } ⇒ Mock </a>
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
</span>
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
<span class="summary_desc"><div class='inline'>
|
215
|
+
<p>Builds a new mock object.</p>
|
216
|
+
</div></span>
|
217
|
+
|
218
|
+
</li>
|
219
|
+
|
220
|
+
|
221
|
+
<li class="public ">
|
222
|
+
<span class="summary_signature">
|
223
|
+
|
224
|
+
<a href="#stub_everything-instance_method" title="#stub_everything (instance method)">#<strong>stub_everything</strong>(*arguments) { ... } ⇒ Mock </a>
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
</span>
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
<span class="summary_desc"><div class='inline'>
|
239
|
+
<p>Builds a mock object that accepts calls to any method.</p>
|
240
|
+
</div></span>
|
241
|
+
|
242
|
+
</li>
|
243
|
+
|
244
|
+
|
245
|
+
</ul>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="Hooks.html" title="Mocha::Hooks (module)">Hooks</a></span></h3>
|
258
|
+
<p class="inherited"><span class='object_link'><a href="Hooks.html#mocha_setup-instance_method" title="Mocha::Hooks#mocha_setup (method)">#mocha_setup</a></span>, <span class='object_link'><a href="Hooks.html#mocha_teardown-instance_method" title="Mocha::Hooks#mocha_teardown (method)">#mocha_teardown</a></span>, <span class='object_link'><a href="Hooks.html#mocha_verify-instance_method" title="Mocha::Hooks#mocha_verify (method)">#mocha_verify</a></span></p>
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
<h3 class="inherited">Methods included from <span class='object_link'><a href="ParameterMatchers.html" title="Mocha::ParameterMatchers (module)">ParameterMatchers</a></span></h3>
|
269
|
+
<p class="inherited"><span class='object_link'><a href="ParameterMatchers.html#Not-instance_method" title="Mocha::ParameterMatchers#Not (method)">#Not</a></span>, <span class='object_link'><a href="ParameterMatchers.html#all_of-instance_method" title="Mocha::ParameterMatchers#all_of (method)">#all_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_of-instance_method" title="Mocha::ParameterMatchers#any_of (method)">#any_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#any_parameters-instance_method" title="Mocha::ParameterMatchers#any_parameters (method)">#any_parameters</a></span>, <span class='object_link'><a href="ParameterMatchers.html#anything-instance_method" title="Mocha::ParameterMatchers#anything (method)">#anything</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equals-instance_method" title="Mocha::ParameterMatchers#equals (method)">#equals</a></span>, <span class='object_link'><a href="ParameterMatchers.html#equivalent_uri-instance_method" title="Mocha::ParameterMatchers#equivalent_uri (method)">#equivalent_uri</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entries-instance_method" title="Mocha::ParameterMatchers#has_entries (method)">#has_entries</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_entry-instance_method" title="Mocha::ParameterMatchers#has_entry (method)">#has_entry</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_equivalent_query_string-instance_method" title="Mocha::ParameterMatchers#has_equivalent_query_string (method)">#has_equivalent_query_string</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_key-instance_method" title="Mocha::ParameterMatchers#has_key (method)">#has_key</a></span>, <span class='object_link'><a href="ParameterMatchers.html#has_value-instance_method" title="Mocha::ParameterMatchers#has_value (method)">#has_value</a></span>, <span class='object_link'><a href="ParameterMatchers.html#includes-instance_method" title="Mocha::ParameterMatchers#includes (method)">#includes</a></span>, <span class='object_link'><a href="ParameterMatchers.html#instance_of-instance_method" title="Mocha::ParameterMatchers#instance_of (method)">#instance_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#is_a-instance_method" title="Mocha::ParameterMatchers#is_a (method)">#is_a</a></span>, <span class='object_link'><a href="ParameterMatchers.html#kind_of-instance_method" title="Mocha::ParameterMatchers#kind_of (method)">#kind_of</a></span>, <span class='object_link'><a href="ParameterMatchers.html#optionally-instance_method" title="Mocha::ParameterMatchers#optionally (method)">#optionally</a></span>, <span class='object_link'><a href="ParameterMatchers.html#regexp_matches-instance_method" title="Mocha::ParameterMatchers#regexp_matches (method)">#regexp_matches</a></span>, <span class='object_link'><a href="ParameterMatchers.html#responds_with-instance_method" title="Mocha::ParameterMatchers#responds_with (method)">#responds_with</a></span>, <span class='object_link'><a href="ParameterMatchers.html#yaml_equivalent-instance_method" title="Mocha::ParameterMatchers#yaml_equivalent (method)">#yaml_equivalent</a></span></p>
|
270
|
+
|
271
|
+
|
272
|
+
<div id="instance_method_details" class="method_details_list">
|
273
|
+
<h2>Instance Method Details</h2>
|
274
|
+
|
275
|
+
|
276
|
+
<div class="method_details first">
|
277
|
+
<h3 class="signature first" id="mock-instance_method">
|
278
|
+
|
279
|
+
|
280
|
+
<span class="overload">#<strong>mock</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
281
|
+
|
282
|
+
<span class="overload">#<strong>mock</strong>(expected_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
283
|
+
|
284
|
+
<span class="overload">#<strong>mock</strong>(name, expected_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
</h3><div class="docstring">
|
292
|
+
<div class="discussion">
|
293
|
+
|
294
|
+
<p>Builds a new mock object</p>
|
295
|
+
|
296
|
+
|
297
|
+
</div>
|
298
|
+
</div>
|
299
|
+
<div class="tags">
|
300
|
+
|
301
|
+
<div class="examples">
|
302
|
+
<p class="tag_title">Examples:</p>
|
303
|
+
|
304
|
+
|
305
|
+
<p class="example_title"><div class='inline'>
|
306
|
+
<p>Using expected_methods_vs_return_values Hash to setup expectations.</p>
|
307
|
+
</div></p>
|
308
|
+
|
309
|
+
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
310
|
+
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:start</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
311
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span>
|
312
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
313
|
+
<span class='comment'># an error will be raised unless both Motor#start and Motor#stop have been called
|
314
|
+
</span><span class='kw'>end</span></code></pre>
|
315
|
+
|
316
|
+
|
317
|
+
<p class="example_title"><div class='inline'>
|
318
|
+
<p>Using the optional block to setup expectations & stubbed methods
|
319
|
+
[deprecated].</p>
|
320
|
+
</div></p>
|
321
|
+
|
322
|
+
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
323
|
+
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
324
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
325
|
+
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
326
|
+
<span class='kw'>end</span>
|
327
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
328
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
329
|
+
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
330
|
+
</span><span class='kw'>end</span></code></pre>
|
331
|
+
|
332
|
+
</div>
|
333
|
+
<p class="tag_title">Parameters:</p>
|
334
|
+
<ul class="param">
|
335
|
+
|
336
|
+
<li>
|
337
|
+
|
338
|
+
<span class='name'>name</span>
|
339
|
+
|
340
|
+
|
341
|
+
<span class='type'>(<tt>String</tt>)</span>
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
—
|
346
|
+
<div class='inline'>
|
347
|
+
<p>identifies mock object in error messages.</p>
|
348
|
+
</div>
|
349
|
+
|
350
|
+
</li>
|
351
|
+
|
352
|
+
<li>
|
353
|
+
|
354
|
+
<span class='name'>expected_methods_vs_return_values</span>
|
355
|
+
|
356
|
+
|
357
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
—
|
362
|
+
<div class='inline'>
|
363
|
+
<p>expected method name symbols as keys and corresponding return values as
|
364
|
+
values - these expectations are setup as if <span class='object_link'><a href="Mock.html#expects-instance_method" title="Mocha::Mock#expects (method)">Mock#expects</a></span> were called
|
365
|
+
multiple times.</p>
|
366
|
+
</div>
|
367
|
+
|
368
|
+
</li>
|
369
|
+
|
370
|
+
</ul>
|
371
|
+
|
372
|
+
<p class="tag_title">Yields:</p>
|
373
|
+
<ul class="yield">
|
374
|
+
|
375
|
+
<li>
|
376
|
+
|
377
|
+
|
378
|
+
<span class='type'></span>
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
<div class='inline'>
|
384
|
+
<p>optional block to be evaluated in the context of the mock object instance,
|
385
|
+
giving an alternative way to setup stubbed methods.</p>
|
386
|
+
</div>
|
387
|
+
|
388
|
+
</li>
|
389
|
+
|
390
|
+
<li>
|
391
|
+
|
392
|
+
|
393
|
+
<span class='type'></span>
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
<div class='inline'>
|
399
|
+
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
400
|
+
things like instance variables declared in the test will not be available
|
401
|
+
within the block.</p>
|
402
|
+
</div>
|
403
|
+
|
404
|
+
</li>
|
405
|
+
|
406
|
+
<li>
|
407
|
+
|
408
|
+
|
409
|
+
<span class='type'></span>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
<div class='inline'>
|
415
|
+
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
416
|
+
receiver instead.</p>
|
417
|
+
</div>
|
418
|
+
|
419
|
+
</li>
|
420
|
+
|
421
|
+
</ul>
|
422
|
+
<p class="tag_title">Returns:</p>
|
423
|
+
<ul class="return">
|
424
|
+
|
425
|
+
<li>
|
426
|
+
|
427
|
+
|
428
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
—
|
433
|
+
<div class='inline'>
|
434
|
+
<p>a new mock object</p>
|
435
|
+
</div>
|
436
|
+
|
437
|
+
</li>
|
438
|
+
|
439
|
+
</ul>
|
440
|
+
|
441
|
+
</div><table class="source_code">
|
442
|
+
<tr>
|
443
|
+
<td>
|
444
|
+
<pre class="lines">
|
445
|
+
|
446
|
+
|
447
|
+
52
|
448
|
+
53
|
449
|
+
54
|
450
|
+
55
|
451
|
+
56
|
452
|
+
57
|
453
|
+
58</pre>
|
454
|
+
</td>
|
455
|
+
<td>
|
456
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 52</span>
|
457
|
+
|
458
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
459
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
460
|
+
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
461
|
+
<span class='id identifier rubyid_mock'>mock</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
462
|
+
<span class='id identifier rubyid_mock'>mock</span><span class='period'>.</span><span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
463
|
+
<span class='id identifier rubyid_mock'>mock</span>
|
464
|
+
<span class='kw'>end</span></pre>
|
465
|
+
</td>
|
466
|
+
</tr>
|
467
|
+
</table>
|
468
|
+
</div>
|
469
|
+
|
470
|
+
<div class="method_details ">
|
471
|
+
<h3 class="signature " id="sequence-instance_method">
|
472
|
+
|
473
|
+
#<strong>sequence</strong>(name) ⇒ <tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
</h3><div class="docstring">
|
480
|
+
<div class="discussion">
|
481
|
+
|
482
|
+
<p>Builds a new sequence which can be used to constrain the order in which
|
483
|
+
expectations can occur.</p>
|
484
|
+
|
485
|
+
<p>Specify that an expected invocation must occur within a named <span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span> by
|
486
|
+
using <span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span>.</p>
|
487
|
+
|
488
|
+
|
489
|
+
</div>
|
490
|
+
</div>
|
491
|
+
<div class="tags">
|
492
|
+
|
493
|
+
<div class="examples">
|
494
|
+
<p class="tag_title">Examples:</p>
|
495
|
+
|
496
|
+
|
497
|
+
<p class="example_title"><div class='inline'>
|
498
|
+
<p>Ensure methods on egg are invoked in correct order.</p>
|
499
|
+
</div></p>
|
500
|
+
|
501
|
+
<pre class="example code"><code><span class='id identifier rubyid_breakfast'>breakfast</span> <span class='op'>=</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>breakfast</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
502
|
+
|
503
|
+
<span class='id identifier rubyid_egg'>egg</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>egg</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
504
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:crack</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
505
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:fry</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
506
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:eat</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_in_sequence'>in_sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_breakfast'>breakfast</span><span class='rparen'>)</span>
|
507
|
+
<span class='kw'>end</span></code></pre>
|
508
|
+
|
509
|
+
</div>
|
510
|
+
|
511
|
+
<p class="tag_title">Returns:</p>
|
512
|
+
<ul class="return">
|
513
|
+
|
514
|
+
<li>
|
515
|
+
|
516
|
+
|
517
|
+
<span class='type'>(<tt><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></tt>)</span>
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
—
|
522
|
+
<div class='inline'>
|
523
|
+
<p>a new sequence</p>
|
524
|
+
</div>
|
525
|
+
|
526
|
+
</li>
|
527
|
+
|
528
|
+
</ul>
|
529
|
+
|
530
|
+
<p class="tag_title">See Also:</p>
|
531
|
+
<ul class="see">
|
532
|
+
|
533
|
+
<li><span class='object_link'><a href="Expectation.html#in_sequence-instance_method" title="Mocha::Expectation#in_sequence (method)">Expectation#in_sequence</a></span></li>
|
534
|
+
|
535
|
+
</ul>
|
536
|
+
|
537
|
+
</div><table class="source_code">
|
538
|
+
<tr>
|
539
|
+
<td>
|
540
|
+
<pre class="lines">
|
541
|
+
|
542
|
+
|
543
|
+
144
|
544
|
+
145
|
545
|
+
146</pre>
|
546
|
+
</td>
|
547
|
+
<td>
|
548
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 144</span>
|
549
|
+
|
550
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_sequence'>sequence</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
551
|
+
<span class='const'><span class='object_link'><a href="Sequence.html" title="Mocha::Sequence (class)">Sequence</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
552
|
+
<span class='kw'>end</span></pre>
|
553
|
+
</td>
|
554
|
+
</tr>
|
555
|
+
</table>
|
556
|
+
</div>
|
557
|
+
|
558
|
+
<div class="method_details ">
|
559
|
+
<h3 class="signature " id="states-instance_method">
|
560
|
+
|
561
|
+
#<strong>states</strong>(name) ⇒ <tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
</h3><div class="docstring">
|
568
|
+
<div class="discussion">
|
569
|
+
|
570
|
+
<p>Builds a new state machine which can be used to constrain the order in
|
571
|
+
which expectations can occur.</p>
|
572
|
+
|
573
|
+
<p>Specify the initial state of the state machine by using
|
574
|
+
<span class='object_link'><a href="StateMachine.html#starts_as-instance_method" title="Mocha::StateMachine#starts_as (method)">StateMachine#starts_as</a></span>.</p>
|
575
|
+
|
576
|
+
<p>Specify that an expected invocation should change the state of the state
|
577
|
+
machine by using <span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span>.</p>
|
578
|
+
|
579
|
+
<p>Specify that an expected invocation should be constrained to occur within a
|
580
|
+
particular <code>state</code> by using <span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span>.</p>
|
581
|
+
|
582
|
+
<p>A test can contain multiple state machines.</p>
|
583
|
+
|
584
|
+
|
585
|
+
</div>
|
586
|
+
</div>
|
587
|
+
<div class="tags">
|
588
|
+
|
589
|
+
<div class="examples">
|
590
|
+
<p class="tag_title">Examples:</p>
|
591
|
+
|
592
|
+
|
593
|
+
<p class="example_title"><div class='inline'>
|
594
|
+
<p>Constrain expected invocations to occur in particular states.</p>
|
595
|
+
</div></p>
|
596
|
+
|
597
|
+
<pre class="example code"><code><span class='id identifier rubyid_power'>power</span> <span class='op'>=</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>power</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_starts_as'>starts_as</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>off</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
598
|
+
|
599
|
+
<span class='id identifier rubyid_radio'>radio</span> <span class='op'>=</span> <span class='id identifier rubyid_mock'>mock</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>radio</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
600
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_on</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
601
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BBC Radio 4</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
602
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>+5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
603
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:select_channel</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BBC World Service</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
604
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:adjust_volume</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='op'>-</span><span class='int'>5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_when'>when</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>on</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
605
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:switch_off</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='id identifier rubyid_power'>power</span><span class='period'>.</span><span class='id identifier rubyid_is'>is</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>off</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
606
|
+
<span class='kw'>end</span></code></pre>
|
607
|
+
|
608
|
+
</div>
|
609
|
+
|
610
|
+
<p class="tag_title">Returns:</p>
|
611
|
+
<ul class="return">
|
612
|
+
|
613
|
+
<li>
|
614
|
+
|
615
|
+
|
616
|
+
<span class='type'>(<tt><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></tt>)</span>
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
—
|
621
|
+
<div class='inline'>
|
622
|
+
<p>a new state machine</p>
|
623
|
+
</div>
|
624
|
+
|
625
|
+
</li>
|
626
|
+
|
627
|
+
</ul>
|
628
|
+
|
629
|
+
<p class="tag_title">See Also:</p>
|
630
|
+
<ul class="see">
|
631
|
+
|
632
|
+
<li><span class='object_link'><a href="Expectation.html#then-instance_method" title="Mocha::Expectation#then (method)">Expectation#then</a></span></li>
|
633
|
+
|
634
|
+
<li><span class='object_link'><a href="Expectation.html#when-instance_method" title="Mocha::Expectation#when (method)">Expectation#when</a></span></li>
|
635
|
+
|
636
|
+
<li><span class='object_link'><a href="StateMachine.html" title="Mocha::StateMachine (class)">StateMachine</a></span></li>
|
637
|
+
|
638
|
+
</ul>
|
639
|
+
|
640
|
+
</div><table class="source_code">
|
641
|
+
<tr>
|
642
|
+
<td>
|
643
|
+
<pre class="lines">
|
644
|
+
|
645
|
+
|
646
|
+
174
|
647
|
+
175
|
648
|
+
176</pre>
|
649
|
+
</td>
|
650
|
+
<td>
|
651
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 174</span>
|
652
|
+
|
653
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_states'>states</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
654
|
+
<span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_new_state_machine'>new_state_machine</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
|
655
|
+
<span class='kw'>end</span></pre>
|
656
|
+
</td>
|
657
|
+
</tr>
|
658
|
+
</table>
|
659
|
+
</div>
|
660
|
+
|
661
|
+
<div class="method_details ">
|
662
|
+
<h3 class="signature " id="stub-instance_method">
|
663
|
+
|
664
|
+
|
665
|
+
<span class="overload">#<strong>stub</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
666
|
+
|
667
|
+
<span class="overload">#<strong>stub</strong>(stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
668
|
+
|
669
|
+
<span class="overload">#<strong>stub</strong>(name, stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
670
|
+
|
671
|
+
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
</h3><div class="docstring">
|
677
|
+
<div class="discussion">
|
678
|
+
|
679
|
+
<p>Builds a new mock object</p>
|
680
|
+
|
681
|
+
|
682
|
+
</div>
|
683
|
+
</div>
|
684
|
+
<div class="tags">
|
685
|
+
|
686
|
+
<div class="examples">
|
687
|
+
<p class="tag_title">Examples:</p>
|
688
|
+
|
689
|
+
|
690
|
+
<p class="example_title"><div class='inline'>
|
691
|
+
<p>Using stubbed_methods_vs_return_values Hash to setup stubbed methods.</p>
|
692
|
+
</div></p>
|
693
|
+
|
694
|
+
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
695
|
+
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:start</span> <span class='op'>=></span> <span class='kw'>true</span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
696
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span>
|
697
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
698
|
+
<span class='comment'># an error will not be raised even if either Motor#start or Motor#stop has not been called
|
699
|
+
</span><span class='kw'>end</span></code></pre>
|
700
|
+
|
701
|
+
|
702
|
+
<p class="example_title"><div class='inline'>
|
703
|
+
<p>Using the optional block to setup expectations & stubbed methods
|
704
|
+
[deprecated].</p>
|
705
|
+
</div></p>
|
706
|
+
|
707
|
+
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_starts_and_stops'>test_motor_starts_and_stops</span>
|
708
|
+
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
709
|
+
<span class='id identifier rubyid_expects'>expects</span><span class='lparen'>(</span><span class='symbol'>:start</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
710
|
+
<span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='symbol'>:stop</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_returns'>returns</span><span class='lparen'>(</span><span class='kw'>true</span><span class='rparen'>)</span>
|
711
|
+
<span class='kw'>end</span>
|
712
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_start'>start</span><span class='lparen'>(</span><span class='int'>100</span><span class='period'>.</span><span class='id identifier rubyid_rpm'>rpm</span><span class='rparen'>)</span>
|
713
|
+
<span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
714
|
+
<span class='comment'># an error will only be raised if Motor#start(100.rpm) has not been called
|
715
|
+
</span><span class='kw'>end</span></code></pre>
|
716
|
+
|
717
|
+
</div>
|
718
|
+
<p class="tag_title">Parameters:</p>
|
719
|
+
<ul class="param">
|
720
|
+
|
721
|
+
<li>
|
722
|
+
|
723
|
+
<span class='name'>name</span>
|
724
|
+
|
725
|
+
|
726
|
+
<span class='type'>(<tt>String</tt>)</span>
|
727
|
+
|
728
|
+
|
729
|
+
|
730
|
+
—
|
731
|
+
<div class='inline'>
|
732
|
+
<p>identifies mock object in error messages.</p>
|
733
|
+
</div>
|
734
|
+
|
735
|
+
</li>
|
736
|
+
|
737
|
+
<li>
|
738
|
+
|
739
|
+
<span class='name'>stubbed_methods_vs_return_values</span>
|
740
|
+
|
741
|
+
|
742
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
743
|
+
|
744
|
+
|
745
|
+
|
746
|
+
—
|
747
|
+
<div class='inline'>
|
748
|
+
<p>stubbed method name symbols as keys and corresponding return values as
|
749
|
+
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
750
|
+
multiple times.</p>
|
751
|
+
</div>
|
752
|
+
|
753
|
+
</li>
|
754
|
+
|
755
|
+
</ul>
|
756
|
+
|
757
|
+
<p class="tag_title">Yields:</p>
|
758
|
+
<ul class="yield">
|
759
|
+
|
760
|
+
<li>
|
761
|
+
|
762
|
+
|
763
|
+
<span class='type'></span>
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
|
768
|
+
<div class='inline'>
|
769
|
+
<p>optional block to be evaluated in the context of the mock object instance,
|
770
|
+
giving an alternative way to setup stubbed methods.</p>
|
771
|
+
</div>
|
772
|
+
|
773
|
+
</li>
|
774
|
+
|
775
|
+
<li>
|
776
|
+
|
777
|
+
|
778
|
+
<span class='type'></span>
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
|
783
|
+
<div class='inline'>
|
784
|
+
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
785
|
+
things like instance variables declared in the test will not be available
|
786
|
+
within the block.</p>
|
787
|
+
</div>
|
788
|
+
|
789
|
+
</li>
|
790
|
+
|
791
|
+
<li>
|
792
|
+
|
793
|
+
|
794
|
+
<span class='type'></span>
|
795
|
+
|
796
|
+
|
797
|
+
|
798
|
+
|
799
|
+
<div class='inline'>
|
800
|
+
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
801
|
+
receiver instead.</p>
|
802
|
+
</div>
|
803
|
+
|
804
|
+
</li>
|
805
|
+
|
806
|
+
</ul>
|
807
|
+
<p class="tag_title">Returns:</p>
|
808
|
+
<ul class="return">
|
809
|
+
|
810
|
+
<li>
|
811
|
+
|
812
|
+
|
813
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
814
|
+
|
815
|
+
|
816
|
+
|
817
|
+
—
|
818
|
+
<div class='inline'>
|
819
|
+
<p>a new mock object</p>
|
820
|
+
</div>
|
821
|
+
|
822
|
+
</li>
|
823
|
+
|
824
|
+
</ul>
|
825
|
+
|
826
|
+
</div><table class="source_code">
|
827
|
+
<tr>
|
828
|
+
<td>
|
829
|
+
<pre class="lines">
|
830
|
+
|
831
|
+
|
832
|
+
91
|
833
|
+
92
|
834
|
+
93
|
835
|
+
94
|
836
|
+
95
|
837
|
+
96
|
838
|
+
97</pre>
|
839
|
+
</td>
|
840
|
+
<td>
|
841
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 91</span>
|
842
|
+
|
843
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_stub'>stub</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
844
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
845
|
+
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
846
|
+
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
847
|
+
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
848
|
+
<span class='id identifier rubyid_stub'>stub</span>
|
849
|
+
<span class='kw'>end</span></pre>
|
850
|
+
</td>
|
851
|
+
</tr>
|
852
|
+
</table>
|
853
|
+
</div>
|
854
|
+
|
855
|
+
<div class="method_details ">
|
856
|
+
<h3 class="signature " id="stub_everything-instance_method">
|
857
|
+
|
858
|
+
|
859
|
+
<span class="overload">#<strong>stub_everything</strong>(name, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
860
|
+
|
861
|
+
<span class="overload">#<strong>stub_everything</strong>(stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
862
|
+
|
863
|
+
<span class="overload">#<strong>stub_everything</strong>(name, stubbed_methods_vs_return_values = {}, &block) ⇒ <tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt> </span>
|
864
|
+
|
865
|
+
|
866
|
+
|
867
|
+
|
868
|
+
|
869
|
+
|
870
|
+
</h3><div class="docstring">
|
871
|
+
<div class="discussion">
|
872
|
+
|
873
|
+
<p>Builds a mock object that accepts calls to any method. By default it will
|
874
|
+
return <code>nil</code> for any method call.</p>
|
875
|
+
|
876
|
+
|
877
|
+
</div>
|
878
|
+
</div>
|
879
|
+
<div class="tags">
|
880
|
+
|
881
|
+
<div class="examples">
|
882
|
+
<p class="tag_title">Examples:</p>
|
883
|
+
|
884
|
+
|
885
|
+
<p class="example_title"><div class='inline'>
|
886
|
+
<p>Ignore invocations of irrelevant methods.</p>
|
887
|
+
</div></p>
|
888
|
+
|
889
|
+
<pre class="example code"><code><span class='kw'>def</span> <span class='id identifier rubyid_test_motor_stops'>test_motor_stops</span>
|
890
|
+
<span class='id identifier rubyid_motor'>motor</span> <span class='op'>=</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>motor</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:stop</span> <span class='op'>=></span> <span class='kw'>true</span><span class='rparen'>)</span>
|
891
|
+
<span class='id identifier rubyid_assert_nil'>assert_nil</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_irrelevant_method_1'>irrelevant_method_1</span> <span class='comment'># => no error raised
|
892
|
+
</span> <span class='id identifier rubyid_assert_nil'>assert_nil</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_irrelevant_method_2'>irrelevant_method_2</span> <span class='comment'># => no error raised
|
893
|
+
</span> <span class='id identifier rubyid_assert'>assert</span> <span class='id identifier rubyid_motor'>motor</span><span class='period'>.</span><span class='id identifier rubyid_stop'>stop</span>
|
894
|
+
<span class='kw'>end</span></code></pre>
|
895
|
+
|
896
|
+
</div>
|
897
|
+
<p class="tag_title">Parameters:</p>
|
898
|
+
<ul class="param">
|
899
|
+
|
900
|
+
<li>
|
901
|
+
|
902
|
+
<span class='name'>name</span>
|
903
|
+
|
904
|
+
|
905
|
+
<span class='type'>(<tt>String</tt>)</span>
|
906
|
+
|
907
|
+
|
908
|
+
|
909
|
+
—
|
910
|
+
<div class='inline'>
|
911
|
+
<p>identifies mock object in error messages.</p>
|
912
|
+
</div>
|
913
|
+
|
914
|
+
</li>
|
915
|
+
|
916
|
+
<li>
|
917
|
+
|
918
|
+
<span class='name'>stubbed_methods_vs_return_values</span>
|
919
|
+
|
920
|
+
|
921
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
922
|
+
|
923
|
+
|
924
|
+
|
925
|
+
—
|
926
|
+
<div class='inline'>
|
927
|
+
<p>stubbed method name symbols as keys and corresponding return values as
|
928
|
+
values - these stubbed methods are setup as if <span class='object_link'><a href="Mock.html#stubs-instance_method" title="Mocha::Mock#stubs (method)">Mock#stubs</a></span> were called
|
929
|
+
multiple times.</p>
|
930
|
+
</div>
|
931
|
+
|
932
|
+
</li>
|
933
|
+
|
934
|
+
</ul>
|
935
|
+
|
936
|
+
<p class="tag_title">Yields:</p>
|
937
|
+
<ul class="yield">
|
938
|
+
|
939
|
+
<li>
|
940
|
+
|
941
|
+
|
942
|
+
<span class='type'></span>
|
943
|
+
|
944
|
+
|
945
|
+
|
946
|
+
|
947
|
+
<div class='inline'>
|
948
|
+
<p>optional block to be evaluated in the context of the mock object instance,
|
949
|
+
giving an alternative way to setup stubbed methods.</p>
|
950
|
+
</div>
|
951
|
+
|
952
|
+
</li>
|
953
|
+
|
954
|
+
<li>
|
955
|
+
|
956
|
+
|
957
|
+
<span class='type'></span>
|
958
|
+
|
959
|
+
|
960
|
+
|
961
|
+
|
962
|
+
<div class='inline'>
|
963
|
+
<p>note that the block is evaulated by calling Mock#instance_eval and so
|
964
|
+
things like instance variables declared in the test will not be available
|
965
|
+
within the block.</p>
|
966
|
+
</div>
|
967
|
+
|
968
|
+
</li>
|
969
|
+
|
970
|
+
<li>
|
971
|
+
|
972
|
+
|
973
|
+
<span class='type'></span>
|
974
|
+
|
975
|
+
|
976
|
+
|
977
|
+
|
978
|
+
<div class='inline'>
|
979
|
+
<p>deprecated: use Object#tap or define stubs/expectations with an explicit
|
980
|
+
receiver instead.</p>
|
981
|
+
</div>
|
982
|
+
|
983
|
+
</li>
|
984
|
+
|
985
|
+
</ul>
|
986
|
+
<p class="tag_title">Returns:</p>
|
987
|
+
<ul class="return">
|
988
|
+
|
989
|
+
<li>
|
990
|
+
|
991
|
+
|
992
|
+
<span class='type'>(<tt><span class='object_link'><a href="Mock.html" title="Mocha::Mock (class)">Mock</a></span></tt>)</span>
|
993
|
+
|
994
|
+
|
995
|
+
|
996
|
+
—
|
997
|
+
<div class='inline'>
|
998
|
+
<p>a new mock object</p>
|
999
|
+
</div>
|
1000
|
+
|
1001
|
+
</li>
|
1002
|
+
|
1003
|
+
</ul>
|
1004
|
+
|
1005
|
+
</div><table class="source_code">
|
1006
|
+
<tr>
|
1007
|
+
<td>
|
1008
|
+
<pre class="lines">
|
1009
|
+
|
1010
|
+
|
1011
|
+
119
|
1012
|
+
120
|
1013
|
+
121
|
1014
|
+
122
|
1015
|
+
123
|
1016
|
+
124
|
1017
|
+
125
|
1018
|
+
126</pre>
|
1019
|
+
</td>
|
1020
|
+
<td>
|
1021
|
+
<pre class="code"><span class="info file"># File 'lib/mocha/api.rb', line 119</span>
|
1022
|
+
|
1023
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_stub_everything'>stub_everything</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_arguments'>arguments</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1024
|
+
<span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='kw'>if</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>String</span><span class='rparen'>)</span>
|
1025
|
+
<span class='id identifier rubyid_expectations'>expectations</span> <span class='op'>=</span> <span class='id identifier rubyid_arguments'>arguments</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span> <span class='op'>||</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1026
|
+
<span class='id identifier rubyid_stub'>stub</span> <span class='op'>=</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>?</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_named_mock'>named_mock</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='const'>Mockery</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span><span class='period'>.</span><span class='id identifier rubyid_unnamed_mock'>unnamed_mock</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
1027
|
+
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stub_everything'>stub_everything</span>
|
1028
|
+
<span class='id identifier rubyid_stub'>stub</span><span class='period'>.</span><span class='id identifier rubyid_stubs'>stubs</span><span class='lparen'>(</span><span class='id identifier rubyid_expectations'>expectations</span><span class='rparen'>)</span>
|
1029
|
+
<span class='id identifier rubyid_stub'>stub</span>
|
1030
|
+
<span class='kw'>end</span></pre>
|
1031
|
+
</td>
|
1032
|
+
</tr>
|
1033
|
+
</table>
|
1034
|
+
</div>
|
1035
|
+
|
1036
|
+
</div>
|
1037
|
+
|
1038
|
+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-625523-7"></script>
|
1039
|
+
<script>
|
1040
|
+
window.dataLayer = window.dataLayer || [];
|
1041
|
+
function gtag(){dataLayer.push(arguments);}
|
1042
|
+
gtag('js', new Date());
|
1043
|
+
|
1044
|
+
gtag('config', 'UA-625523-7');
|
1045
|
+
</script>
|
1046
|
+
</div>
|
1047
|
+
|
1048
|
+
<div id="footer">
|
1049
|
+
Generated on Tue Jan 15 17:13:05 2019 by
|
1050
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1051
|
+
0.9.16 (ruby-2.5.3).
|
1052
|
+
</div>
|
1053
|
+
|
1054
|
+
</div>
|
1055
|
+
</body>
|
1056
|
+
</html>
|