rspec 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +9 -1
- data/README +1 -0
- data/Rakefile +14 -6
- data/doc/README +1 -1
- data/doc/reference/rspec reference.page +0 -0
- data/doc/src/community.page +0 -1
- data/doc/src/default.template +1 -3
- data/doc/src/documentation/api.page +36 -35
- data/doc/src/documentation/index.page +9 -4
- data/doc/src/documentation/meta.info +22 -0
- data/doc/src/documentation/mocks.page +68 -32
- data/doc/src/download.page +0 -1
- data/doc/src/examples.page +1 -2
- data/doc/src/index.page +0 -1
- data/doc/src/meta.info +23 -0
- data/doc/src/tools/index.page +139 -4
- data/doc/src/tools/meta.info +12 -0
- data/doc/src/tools/rails.page +0 -1
- data/doc/src/tools/rake.page +0 -1
- data/doc/src/tools/test2rspec.page +10 -3
- data/doc/src/why_rspec.page +0 -1
- data/examples/airport_spec.rb +14 -4
- data/examples/empty_stack_spec.rb +21 -0
- data/examples/stack_spec.rb +4 -1
- data/lib/spec.rb +2 -1
- data/lib/spec/api/helper/should_helper.rb +5 -4
- data/lib/spec/api/helper/should_negator.rb +2 -0
- data/lib/spec/api/mock.rb +4 -7
- data/lib/spec/runner/backtrace_tweaker.rb +3 -4
- data/lib/spec/runner/execution_context.rb +4 -0
- data/lib/spec/runner/kernel_ext.rb +1 -2
- data/lib/spec/runner/option_parser.rb +12 -7
- data/lib/spec/version.rb +10 -7
- data/test/spec/api/helper/raising_test.rb +12 -0
- data/test/spec/api/helper/should_satisfy_test.rb +8 -6
- data/test/spec/api/mock_arg_constraints_test.rb +1 -10
- data/test/spec/api/mock_test.rb +71 -2
- data/test/spec/runner/context_runner_test.rb +23 -0
- data/test/spec/runner/context_test.rb +41 -0
- data/test/spec/runner/execution_context_test.rb +7 -0
- data/test/spec/runner/kernel_ext_test.rb +14 -0
- data/test/spec/runner/option_parser_test.rb +17 -10
- metadata +8 -8
- data/doc/src/documentation/specs.page +0 -20
- data/doc/src/tools/rcov.page +0 -8
- data/doc/src/tools/spec_runner.page +0 -8
- data/doc/src/tools/specdoc.page +0 -8
data/CHANGES
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
= RSpec Changelog
|
2
2
|
|
3
|
+
== Version 0.5.2
|
4
|
+
This release has minor improvements to the commandline and fixes some gem warnings
|
5
|
+
|
6
|
+
* Readded README to avoid RDoc warnings [aslak_hellesoy]
|
7
|
+
* Added --version switch to commandline [aslak_hellesoy]
|
8
|
+
* More changes to the mock API [dastels], [dchelimsky]
|
9
|
+
|
3
10
|
== Version 0.5.1
|
4
11
|
This release is the first release of RSpec with a new website. It will look better soon.
|
5
12
|
|
@@ -7,7 +14,8 @@ This release is the first release of RSpec with a new website. It will look bett
|
|
7
14
|
* Added website based on webgen [aslak_hellesoy]
|
8
15
|
* Modified test task to use rcov [aslak_hellesoy]
|
9
16
|
* Deleted unused code (thanks, rcov!) [aslak_hellesoy]
|
10
|
-
* Various changes to the mock API [dastels]
|
17
|
+
* Various changes to the mock API [dastels], [dchelimsky]
|
18
|
+
* Various improvements to failure reporting [dchelimsky]
|
11
19
|
|
12
20
|
== Version 0.5.0
|
13
21
|
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
See http://rspec.rubyforge.org
|
data/Rakefile
CHANGED
@@ -136,19 +136,27 @@ task :clobber do
|
|
136
136
|
rm_rf 'doc/output'
|
137
137
|
end
|
138
138
|
|
139
|
-
task :release => [:clobber, :
|
139
|
+
task :release => [:clobber, :verify_user, :verify_password, :test, :upload_releases, :publish_website, :publish_news]
|
140
140
|
|
141
|
-
|
141
|
+
desc "Build the website with rdoc and rcov, but do not publish it"
|
142
|
+
task :website => [:clobber, :test, :doc, :rdoc, :rcov]
|
143
|
+
|
144
|
+
task :rcov => [:test] do
|
145
|
+
rm_rf 'doc/output/coverage'
|
146
|
+
mkdir 'doc/output' unless File.exists? 'doc/output'
|
142
147
|
mv 'coverage', 'doc/output'
|
143
148
|
end
|
144
149
|
|
145
|
-
task :
|
150
|
+
task :verify_user do
|
146
151
|
raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
|
152
|
+
end
|
153
|
+
|
154
|
+
task :verify_password do
|
147
155
|
raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
|
148
156
|
end
|
149
157
|
|
150
158
|
desc "Upload Website to RubyForge"
|
151
|
-
task :publish_website => [:
|
159
|
+
task :publish_website => [:verify_user, :website] do
|
152
160
|
publisher = Rake::SshDirPublisher.new(
|
153
161
|
"#{ENV['RUBYFORGE_USER']}@rubyforge.org",
|
154
162
|
"/var/www/gforge-projects/#{PKG_NAME}",
|
@@ -159,7 +167,7 @@ task :publish_website => [:doc, :rdoc, :rcov] do
|
|
159
167
|
end
|
160
168
|
|
161
169
|
desc "Release gem to RubyForge. You must make sure lib/version.rb is aligned with the CHANGELOG file"
|
162
|
-
task :upload_releases => :package do
|
170
|
+
task :upload_releases => [:verify_user, :verify_password, :package] do
|
163
171
|
|
164
172
|
release_files = FileList[
|
165
173
|
"pkg/#{PKG_FILE_NAME}.gem",
|
@@ -177,7 +185,7 @@ task :upload_releases => :package do
|
|
177
185
|
end
|
178
186
|
|
179
187
|
desc "Publish news on RubyForge"
|
180
|
-
task :publish_news do
|
188
|
+
task :publish_news => [:verify_user, :verify_password] do
|
181
189
|
Rake::XForge::NewsPublisher.new(MetaProject::Project::XForge::RubyForge.new(PKG_NAME)) do |news|
|
182
190
|
# Never hardcode user name and password in the Rakefile!
|
183
191
|
news.user_name = ENV['RUBYFORGE_USER']
|
data/doc/README
CHANGED
@@ -2,4 +2,4 @@ The website can be generated with
|
|
2
2
|
webgen
|
3
3
|
(Install the following gems: webgen, redcloth, bluecloth)
|
4
4
|
|
5
|
-
TODO: write rake task that will generate website, put rdoc underneath it and upload
|
5
|
+
TODO: write rake task that will generate website, put rdoc underneath it and upload everything.
|
Binary file
|
data/doc/src/community.page
CHANGED
data/doc/src/default.template
CHANGED
@@ -9,7 +9,7 @@ When RSpec executes specifications, it defines a method *should* on every object
|
|
9
9
|
This *should* method is your entry to the magic of RSpec.
|
10
10
|
|
11
11
|
Almost all expectation forms have a corresponding negated form. It is listed
|
12
|
-
when it is supported and is met when ever the non negated form would be
|
12
|
+
when it is supported and, in general, is met when ever the non negated form would be
|
13
13
|
violated.
|
14
14
|
|
15
15
|
h3. General
|
@@ -23,9 +23,9 @@ target.should.not.satisfy {|arg| ...}
|
|
23
23
|
</code>
|
24
24
|
</pre>
|
25
25
|
|
26
|
-
The supplied block is evaluated, passing target as the sole argument. If the
|
27
|
-
block evaluates to false in the case of should.satisfy
|
28
|
-
should.not.satisfy
|
26
|
+
The supplied block is evaluated, passing <code>target</code> as the sole argument. If the
|
27
|
+
block evaluates to <code>false</code> in the case of <code>should.satisfy</code>, or <code>true</code> in the case of
|
28
|
+
<code>should.not.satisfy</code>, <code>ExpectationNotMetError</code> is raised.
|
29
29
|
|
30
30
|
<pre>
|
31
31
|
<code>
|
@@ -34,6 +34,7 @@ target.should.satisfy {|arg| arg > 0}
|
|
34
34
|
</pre>
|
35
35
|
|
36
36
|
h4. Equality
|
37
|
+
|
37
38
|
<pre>
|
38
39
|
<code>
|
39
40
|
target.should.equal <value>
|
@@ -41,8 +42,8 @@ target.should.not.equal <value>
|
|
41
42
|
</code>
|
42
43
|
</pre>
|
43
44
|
|
44
|
-
The target object is compared to <value> using ==. If the result is false (or
|
45
|
-
true for the negated form) ExpectationNotMetError is raised.
|
45
|
+
The target object is compared to <code>value</code> using ==. If the result is <code>false</code> (or
|
46
|
+
<code>true</code> for the negated form) <code>ExpectationNotMetError</code> is raised.
|
46
47
|
|
47
48
|
h4. Floating Point Comparison
|
48
49
|
|
@@ -53,9 +54,9 @@ target.should.not.be.close <value>, <tolerance>
|
|
53
54
|
</code>
|
54
55
|
</pre>
|
55
56
|
|
56
|
-
The target object is compared to <value>. In the former case, if they differ
|
57
|
-
by more that <tolerance> ExpectationNotMetError is raised. In the latter case,
|
58
|
-
it is raised if they differ by less than <tolerance>.
|
57
|
+
The target object is compared to <code>value</code>. In the former case, if they differ
|
58
|
+
by more that <code>tolerance</code> <code>ExpectationNotMetError</code> is raised. In the latter case,
|
59
|
+
it is raised if they differ by less than <code>tolerance</code>.
|
59
60
|
|
60
61
|
<pre>
|
61
62
|
<code>
|
@@ -72,8 +73,8 @@ target.should.not.be <value>
|
|
72
73
|
</code>
|
73
74
|
</pre>
|
74
75
|
|
75
|
-
The target object is compared to <value> using equal
|
76
|
-
(or true for the negated form) ExpectationNotMetError is raised.
|
76
|
+
The target object is compared to <code>value</code> using <code>equal?</code>. If the result is <code>false</code>
|
77
|
+
(or <code>true</code> for the negated form) <code>ExpectationNotMetError</code> is raised.
|
77
78
|
|
78
79
|
h4. Arbitrary Predicate
|
79
80
|
|
@@ -87,14 +88,14 @@ target.should.not.be.predicate [optional args]
|
|
87
88
|
</code>
|
88
89
|
</pre>
|
89
90
|
|
90
|
-
The message predicate
|
91
|
-
result is false (or true for the negated form) ExpectationNotMetError is
|
91
|
+
The message <code>predicate?</code> is sent to <code>target</code> with any supplied arguments. If the
|
92
|
+
result is <code>false</code> (or <code>true</code> for the negated form) <code>ExpectationNotMetError</code> is
|
92
93
|
raised.
|
93
94
|
|
94
95
|
<pre>
|
95
96
|
<code>
|
96
|
-
container.should.include 'a'
|
97
|
-
container.should.be.empty
|
97
|
+
container.should.include 'a' => container.include? 'a'
|
98
|
+
container.should.be.empty => container.empty?
|
98
99
|
</code>
|
99
100
|
</pre>
|
100
101
|
|
@@ -107,7 +108,7 @@ target.should.not.match <regex>
|
|
107
108
|
</code>
|
108
109
|
</pre>
|
109
110
|
|
110
|
-
The target is matched against <regex>. An ExpectationNotMetError is raised if
|
111
|
+
The <code>target</code> is matched against <code>regex</code>. An <code>ExpectationNotMetError</code> is raised if
|
111
112
|
the match fails or succeeds, respectively.
|
112
113
|
|
113
114
|
h3. Class/Type
|
@@ -121,9 +122,9 @@ target.should.not.be.an.instance.of <class>
|
|
121
122
|
</code>
|
122
123
|
</pre>
|
123
124
|
|
124
|
-
An ExpectationNotMetError is raised if target is not or is, respectively, an
|
125
|
-
direct instance of <class>. As expected this correlates to target.instance_of?
|
126
|
-
|
125
|
+
An <code>ExpectationNotMetError</code> is raised if <code>target</code> is not or is, respectively, an
|
126
|
+
direct instance of <code>class</code>. As expected this correlates to <code>target.instance_of?
|
127
|
+
class</code>.
|
127
128
|
|
128
129
|
h4. Ancestor Class
|
129
130
|
|
@@ -134,8 +135,8 @@ target.should.not.be.a.kind.of <class>
|
|
134
135
|
</code>
|
135
136
|
</pre>
|
136
137
|
|
137
|
-
As above, but uses target.kind_of?
|
138
|
-
direct class of target
|
138
|
+
As above, but uses <code>target.kind_of? class</code>: checking whether <code>class</code> is the
|
139
|
+
direct class of <code>target</code>, or an ancestor of <code>target</code>'s class.
|
139
140
|
|
140
141
|
h4. Type
|
141
142
|
|
@@ -146,8 +147,8 @@ target.should.not.respond.to <symbol>
|
|
146
147
|
</code>
|
147
148
|
</pre>
|
148
149
|
|
149
|
-
Uses target.respond_to?
|
150
|
-
message that target understands.
|
150
|
+
Uses <code>target.respond_to? symbol?</code> to check whether <code>symbol</code> is the name of a
|
151
|
+
message that <code>target</code> understands.
|
151
152
|
|
152
153
|
h3. Procs
|
153
154
|
|
@@ -160,8 +161,8 @@ proc.should.not.raise <exception>
|
|
160
161
|
</code>
|
161
162
|
</pre>
|
162
163
|
|
163
|
-
Checks that proc does or doesn't cause the named exception to be raised.
|
164
|
-
Typically the proc is created in place using lambda
|
164
|
+
Checks that <code>proc</code> does or doesn't cause the named exception to be raised.
|
165
|
+
Typically the <code>proc</code> is created in place using <code>lambda</code>. For example:
|
165
166
|
|
166
167
|
<pre>
|
167
168
|
<code>
|
@@ -190,7 +191,7 @@ proc.should.not.throw <symbol>
|
|
190
191
|
</code>
|
191
192
|
</pre>
|
192
193
|
|
193
|
-
Similar to the above, but checks that <symbol> is thrown from within proc
|
194
|
+
Similar to the above, but checks that <code>symbol</code> is thrown from within <code>proc</code>, or
|
194
195
|
that it is not. The latter is actually one of two cases: some other symbol is
|
195
196
|
thrown, or no symbol is thrown.
|
196
197
|
|
@@ -200,7 +201,7 @@ proc.should.not.throw
|
|
200
201
|
</code>
|
201
202
|
</pre>
|
202
203
|
|
203
|
-
This form is more specific. It checks that no symbol is thrown from within proc
|
204
|
+
This form is more specific. It checks that no symbol is thrown from within <code>proc</code>.
|
204
205
|
|
205
206
|
h3. Collections
|
206
207
|
|
@@ -213,14 +214,14 @@ target.should.include <object>
|
|
213
214
|
</pre>
|
214
215
|
|
215
216
|
This is simply a specific case of the arbitrary predicate form. It uses
|
216
|
-
target.include?
|
217
|
+
<code>target.include? object</code> and raises an <code>ExpectationNotMetError</code> if that returns
|
217
218
|
false. The remaining collection forms are a little more involved. They rely on
|
218
|
-
two things: target responds to the message <things> by returning an object
|
219
|
-
that responds to either length or size
|
220
|
-
measure of size. Currently length is used if is appropriate, otherwise size is
|
219
|
+
two things: <code>target</code> responds to the message <code>things</code> by returning an object
|
220
|
+
that responds to either <code>length</code> or <code>size</code>, which return a number that is a
|
221
|
+
measure of size. Currently <code>length</code> is used if is appropriate, otherwise <code>size</code> is
|
221
222
|
attempted.
|
222
223
|
|
223
|
-
|
224
|
+
h4. Exact Size
|
224
225
|
|
225
226
|
<pre>
|
226
227
|
<code>
|
@@ -228,7 +229,7 @@ target.should.have(<number>).<things>
|
|
228
229
|
</code>
|
229
230
|
</pre>
|
230
231
|
|
231
|
-
The <things> of target has a length/size of exactly <number>.
|
232
|
+
The <code>things</code> of <code>target</code> has a length/size of exactly <code>number</code>.
|
232
233
|
|
233
234
|
h4. Lower Bound
|
234
235
|
|
@@ -238,7 +239,7 @@ target.should.have.at.least(<number>).<things>
|
|
238
239
|
</code>
|
239
240
|
</pre>
|
240
241
|
|
241
|
-
The <things> of target has a length/size of no less than <number>.
|
242
|
+
The <code>things</code> of <code>target</code> has a length/size of no less than <code>number</code>.
|
242
243
|
|
243
244
|
h4. Upper Bound
|
244
245
|
|
@@ -248,4 +249,4 @@ target.should.have.at.most(<number>).<things>
|
|
248
249
|
</code>
|
249
250
|
</pre>
|
250
251
|
|
251
|
-
The <things> of target has a length/size of no more than <number>.
|
252
|
+
The <code>things</code> of <code>target</code> has a length/size of no more than <code>number</code>.
|
@@ -1,8 +1,13 @@
|
|
1
1
|
---
|
2
|
-
title:
|
2
|
+
title: Writing Specifications
|
3
3
|
inMenu: true
|
4
|
-
ordering: 1
|
5
4
|
---
|
6
|
-
h2.
|
5
|
+
h2. Writing Specifications
|
7
6
|
|
8
|
-
|
7
|
+
An RSpec specification is a Ruby file with a context and one or more specifications. Example:
|
8
|
+
|
9
|
+
{ruby_inline: {filename: ../examples/empty_stack_spec.rb}}
|
10
|
+
|
11
|
+
A context represents a collection of specifications and must be defined with a name and a block (do-end).
|
12
|
+
A specification is defined with the *specify* keyword and a sentence describing what's being specified.
|
13
|
+
It is highly recommended to include
|
@@ -0,0 +1,22 @@
|
|
1
|
+
index.page:
|
2
|
+
orderInfo: 10
|
3
|
+
|
4
|
+
api.page:
|
5
|
+
orderInfo: 11
|
6
|
+
|
7
|
+
mocks.page:
|
8
|
+
orderInfo: 12
|
9
|
+
|
10
|
+
rdoc.html:
|
11
|
+
title: RDoc
|
12
|
+
dest: ../rdoc/index.html
|
13
|
+
inMenu: true
|
14
|
+
orderInfo: 13
|
15
|
+
|
16
|
+
rcov.html:
|
17
|
+
title: RCov
|
18
|
+
dest: ../coverage/index.html
|
19
|
+
inMenu: true
|
20
|
+
orderInfo: 14
|
21
|
+
|
22
|
+
|
@@ -1,7 +1,6 @@
|
|
1
1
|
---
|
2
2
|
title: Mock API
|
3
3
|
inMenu: true
|
4
|
-
ordering: 5
|
5
4
|
---
|
6
5
|
h2. Mock API
|
7
6
|
|
@@ -25,8 +24,8 @@ mock(<name>, <options>)
|
|
25
24
|
</pre>
|
26
25
|
|
27
26
|
As above, but allows you to specific options to tweak the mock's behaviour.
|
28
|
-
The <options> argument is a hash. Currently the only supported option is
|
29
|
-
|
27
|
+
The <code>options</code> argument is a hash. Currently the only supported option is
|
28
|
+
<code>:null_object</code>. Setting this to true (i.e. <code>:null_object => true</code>) instructs the
|
30
29
|
mock to ignore (quietly consume) any messages it hasn't been told to expect.
|
31
30
|
|
32
31
|
h3. Expecting Messages
|
@@ -37,7 +36,7 @@ mock.should.receive(<message>)
|
|
37
36
|
</code>
|
38
37
|
</pre>
|
39
38
|
|
40
|
-
The <message> argument is a symbol that is the name of a message that you want
|
39
|
+
The <code>message</code> argument is a symbol that is the name of a message that you want
|
41
40
|
the mock to be expecting.
|
42
41
|
|
43
42
|
h3. Arbitrary Message Receive Handling
|
@@ -63,12 +62,12 @@ mock.should.receive(:msg).with(1, 2, 3)
|
|
63
62
|
</code>
|
64
63
|
</pre>
|
65
64
|
|
66
|
-
The <args> argument is a series of arguments (e..g. 1, 2, 3) that are expected
|
65
|
+
The <code>args</code> argument is a series of arguments (e..g. 1, 2, 3) that are expected
|
67
66
|
to be passed as arguments to the associated message.
|
68
67
|
|
69
68
|
<pre>
|
70
69
|
<code>
|
71
|
-
mock.should.receive(:msg).with(:
|
70
|
+
mock.should.receive(:msg).with(:no_args)
|
72
71
|
</code>
|
73
72
|
</pre>
|
74
73
|
|
@@ -76,32 +75,63 @@ No arguments are to be accepted by the message.
|
|
76
75
|
|
77
76
|
<pre>
|
78
77
|
<code>
|
79
|
-
mock.should.receive(:msg).with(:
|
78
|
+
mock.should.receive(:msg).with(:any_args)
|
80
79
|
</code>
|
81
80
|
</pre>
|
82
81
|
|
83
|
-
Any arguments are to be accepted by the message.
|
84
|
-
|
82
|
+
Any arguments are to be accepted by the message. This includes cases where no
|
83
|
+
arguments are provided. *This is the default when no <code>with()</code> clause is
|
84
|
+
specified.* Even so, sometimes you want to be explicit about it.
|
85
|
+
|
86
|
+
h3. Argument Constraints
|
87
|
+
|
88
|
+
Constraints can be placed on individual arguments which are looser than value equivalence.
|
89
|
+
|
90
|
+
h4. :anything
|
91
|
+
|
92
|
+
accepts any value for this argument
|
85
93
|
|
86
94
|
<pre>
|
87
95
|
<code>
|
88
|
-
:anything
|
96
|
+
mock.should.receive(:msg).with(1, :anything, "A")
|
89
97
|
</code>
|
90
98
|
</pre>
|
91
99
|
|
92
|
-
|
100
|
+
h4. :numeric
|
101
|
+
|
102
|
+
accepts any numeric value for this argument
|
93
103
|
|
94
104
|
<pre>
|
95
105
|
<code>
|
96
|
-
mock.should.receive(:msg).with(
|
106
|
+
mock.should.receive(:msg).with(a, :numeric, "b")
|
107
|
+
</code>
|
108
|
+
</pre>
|
109
|
+
|
110
|
+
h4. :boolean
|
111
|
+
|
112
|
+
accepts a boolean value for this argument
|
113
|
+
|
114
|
+
<pre>
|
115
|
+
<code>
|
116
|
+
mock.should.receive(:msg).with(a, :boolean, "b")
|
97
117
|
</code>
|
98
118
|
</pre>
|
99
119
|
|
120
|
+
h4. :string
|
121
|
+
|
122
|
+
accepts any string for this argument
|
123
|
+
|
124
|
+
<pre>
|
125
|
+
<code>
|
126
|
+
mock.should.receive(:msg).with(a, :string, "b")
|
127
|
+
</code>
|
128
|
+
</pre>
|
129
|
+
|
100
130
|
h3. Receive Counts
|
101
131
|
|
102
132
|
<pre>
|
103
133
|
<code>
|
104
|
-
mock.should.receive(:msg).
|
134
|
+
mock.should.receive(:msg).never
|
105
135
|
</code>
|
106
136
|
</pre>
|
107
137
|
|
@@ -109,7 +139,7 @@ A problem is reported if the message is ever received.
|
|
109
139
|
|
110
140
|
<pre>
|
111
141
|
<code>
|
112
|
-
mock.should.receive(:msg).
|
142
|
+
mock.should.receive(:msg).any.number.of.times
|
113
143
|
</code>
|
114
144
|
</pre>
|
115
145
|
|
@@ -117,7 +147,7 @@ The message can be received 0 or more times.
|
|
117
147
|
|
118
148
|
<pre>
|
119
149
|
<code>
|
120
|
-
mock.should.receive(:msg).
|
150
|
+
mock.should.receive(:msg).once
|
121
151
|
</code>
|
122
152
|
</pre>
|
123
153
|
|
@@ -126,7 +156,7 @@ than once.
|
|
126
156
|
|
127
157
|
<pre>
|
128
158
|
<code>
|
129
|
-
mock.should.receive(:msg).
|
159
|
+
mock.should.receive(:msg).twice
|
130
160
|
</code>
|
131
161
|
</pre>
|
132
162
|
|
@@ -134,7 +164,7 @@ A problem is reported is the message is received anything but two times.
|
|
134
164
|
|
135
165
|
<pre>
|
136
166
|
<code>
|
137
|
-
mock.should.receive(:msg).
|
167
|
+
mock.should.receive(:msg).exactly(n).times
|
138
168
|
</code>
|
139
169
|
</pre>
|
140
170
|
|
@@ -142,7 +172,7 @@ A problem is reported is the message is received anything but n times.
|
|
142
172
|
|
143
173
|
<pre>
|
144
174
|
<code>
|
145
|
-
mock.should.receive(:msg).
|
175
|
+
mock.should.receive(:msg).at.least(:once)
|
146
176
|
</code>
|
147
177
|
</pre>
|
148
178
|
|
@@ -150,7 +180,7 @@ A problem is reported if the message is never received.
|
|
150
180
|
|
151
181
|
<pre>
|
152
182
|
<code>
|
153
|
-
mock.should.receive(:msg).
|
183
|
+
mock.should.receive(:msg).at.least(:twice)
|
154
184
|
</code>
|
155
185
|
</pre>
|
156
186
|
|
@@ -158,7 +188,7 @@ A problem is reported is the message is never received or is received only once.
|
|
158
188
|
|
159
189
|
<pre>
|
160
190
|
<code>
|
161
|
-
mock.should.receive(:msg).
|
191
|
+
mock.should.receive(:msg).at.least(n).times
|
162
192
|
</code>
|
163
193
|
</pre>
|
164
194
|
|
@@ -168,40 +198,46 @@ h3. Return Values
|
|
168
198
|
|
169
199
|
<pre>
|
170
200
|
<code>
|
171
|
-
mock.should.receive(:msg).
|
201
|
+
mock.should.receive(:msg).once.and.return(<value>)
|
172
202
|
</code>
|
173
203
|
</pre>
|
174
204
|
|
175
|
-
When the expected message is received, <value> will be returned as the result.
|
205
|
+
When the expected message is received, <code>value</code> will be returned as the result.
|
176
206
|
|
177
207
|
<pre>
|
178
208
|
<code>
|
179
|
-
and.return([<
|
180
|
-
mock.should.receive(:msg).with(:nothing).once.and.return(1, 2, 3)
|
209
|
+
and.return([<value-1>, <value-2>, ..., <value-n>])
|
181
210
|
</code>
|
182
211
|
</pre>
|
183
212
|
|
184
|
-
When the expected message is received, <
|
185
|
-
for the ith reception of the message. Once i > n, <
|
213
|
+
When the expected message is received, <code>value-i</code> will be returned as the result
|
214
|
+
for the ith reception of the message. Once i > n, <code>value-n</code> is returned for all
|
186
215
|
subsequent receives of the message.
|
187
216
|
|
188
217
|
<pre>
|
189
218
|
<code>
|
190
|
-
mock.should.receive(:msg).
|
191
|
-
mock.should.receive(:msg).with(:anything).once.and.return {|a, b| a + b}
|
219
|
+
mock.should.receive(:msg).once.and.return {...}
|
192
220
|
</code>
|
193
221
|
</pre>
|
194
222
|
|
195
223
|
When the expected message is received, the result of evaluating the supplied
|
196
224
|
block will be returned as the result. The block is passed any arguments passed
|
197
225
|
as parts of the message. This capability can be used to compute return values
|
198
|
-
based on the arguments.
|
226
|
+
based on the arguments. For example:
|
227
|
+
|
228
|
+
<pre>
|
229
|
+
<code>
|
230
|
+
mock.should.receive(:msg).once.and.return {|a, b| a + b}
|
231
|
+
</code>
|
232
|
+
</pre>
|
233
|
+
|
234
|
+
h3. Raising and Throwing
|
199
235
|
|
200
236
|
<pre>
|
201
237
|
<code>
|
202
|
-
mock.should.receive(:msg).
|
203
|
-
mock.should.receive(:msg).
|
238
|
+
mock.should.receive(:msg).once.and.raise(<exception>)
|
239
|
+
mock.should.receive(:msg).once.and.throw(<symbol>)
|
204
240
|
</code>
|
205
241
|
</pre>
|
206
242
|
|
207
|
-
These instruct the mock to raise an exception or throw a symbol instead of returning a value.
|
243
|
+
These instruct the mock to raise an exception or throw a symbol instead of returning a value.
|