rspec 0.5.6 → 0.5.7
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 +8 -0
- data/Rakefile +11 -11
- data/bin/spec +4 -1
- data/doc/src/documentation/index.page +37 -37
- data/doc/src/documentation/mocks.page +34 -34
- data/doc/src/documentation/underscores.page +5 -4
- data/doc/src/index.page +2 -2
- data/doc/src/tools/rails.page +11 -0
- data/doc/src/tools/spec.page +18 -3
- data/doc/src/tutorials/notes.txt +17 -6
- data/doc/src/tutorials/stack_04.page.orig +2 -2
- data/doc/src/tutorials/stack_05.page.orig +5 -5
- data/doc/src/tutorials/stack_06.page +7 -7
- data/doc/src/tutorials/stack_06.page.orig +7 -7
- data/examples/custom_formatter.rb +21 -0
- data/examples/mocking_spec.rb +1 -1
- data/examples/stack_spec.rb +21 -21
- data/lib/spec/runner/base_text_formatter.rb +42 -0
- data/lib/spec/runner/context_runner.rb +1 -1
- data/lib/spec/runner/kernel_ext.rb +1 -1
- data/lib/spec/runner/option_parser.rb +23 -7
- data/lib/spec/runner/progress_bar_formatter.rb +1 -1
- data/lib/spec/runner/rdoc_formatter.rb +0 -10
- data/lib/spec/runner/reporter.rb +3 -4
- data/lib/spec/runner/specdoc_formatter.rb +0 -3
- data/lib/spec/runner/specification.rb +3 -7
- data/lib/spec/tool/test_unit_translator.rb +20 -20
- data/lib/spec/version.rb +1 -1
- data/test/spec/api/mocks/mock_ordering_test.rb +28 -0
- data/test/spec/runner/context_test.rb +4 -4
- data/test/spec/runner/failure_dump_test.rb +7 -7
- data/test/spec/runner/option_parser_test.rb +22 -1
- data/test/spec/runner/progress_bar_formatter_test.rb +6 -0
- data/test/spec/runner/rdoc_formatter_test.rb +1 -1
- data/test/spec/runner/reporter_test.rb +9 -8
- data/test/spec/runner/specdoc_formatter_test.rb +5 -0
- data/test/spec/runner/specification_test.rb +8 -8
- data/test/spec/tool/command_line_test.rb +4 -4
- data/test/spec/tool/test_unit_api_spec.rb +25 -25
- metadata +5 -4
data/CHANGES
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= RSpec Changelog
|
2
2
|
|
3
|
+
== Version 0.5.7
|
4
|
+
This release changes examples and documentation to recommend underscores rather than dots,
|
5
|
+
and addresses some bugfixes and changes to the spec commandline.
|
6
|
+
|
7
|
+
* spec DIR now works correctly, recursing down and slurping all *.rb files
|
8
|
+
* All documentation and examples are now using '_' instead of '.'
|
9
|
+
* Custom external formatters can now be specified via --require and --format.
|
10
|
+
|
3
11
|
== Version 0.5.6
|
4
12
|
This release fixes a bug in the Rails controller generator
|
5
13
|
|
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ PKG_FILES = FileList[
|
|
25
25
|
'test/**/*.rb',
|
26
26
|
'examples/**/*.rb',
|
27
27
|
'doc/**/*'
|
28
|
-
]
|
28
|
+
].exclude('EXAMPLES.rd')
|
29
29
|
|
30
30
|
task :default => [:test]
|
31
31
|
|
@@ -132,7 +132,9 @@ end
|
|
132
132
|
|
133
133
|
desc "Creates a tag in svn"
|
134
134
|
task :tag do
|
135
|
-
|
135
|
+
puts "Creating tag in SVN"
|
136
|
+
`svn cp svn+ssh://#{ENV['RUBYFORGE_USER']}@rubyforge.org/var/svn/rspec/trunk svn+ssh://#{ENV['RUBYFORGE_USER']}@rubyforge.org/var/svn/rspec/tags/#{Spec::VERSION::TAG} -m "Tag release #{Spec::VERSION::STRING}"`
|
137
|
+
puts "Done!"
|
136
138
|
end
|
137
139
|
|
138
140
|
desc "Build the website with rdoc and rcov, but do not publish it"
|
@@ -148,15 +150,13 @@ end
|
|
148
150
|
|
149
151
|
desc "Upload Website to RubyForge"
|
150
152
|
task :publish_website => [:verify_user, :website] do
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
publisher.upload
|
159
|
-
end
|
153
|
+
publisher = Rake::SshDirPublisher.new(
|
154
|
+
"rspec-website@rubyforge.org",
|
155
|
+
"/var/www/gforge-projects/#{PKG_NAME}",
|
156
|
+
"doc/output"
|
157
|
+
)
|
158
|
+
|
159
|
+
publisher.upload
|
160
160
|
end
|
161
161
|
|
162
162
|
task :package_rails do
|
data/bin/spec
CHANGED
@@ -3,9 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../lib/spec") # better stack
|
|
3
3
|
|
4
4
|
$context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV, false, STDERR, STDOUT)
|
5
5
|
|
6
|
+
# If ARGV is a glob, it will actually each over each one of the matching files.
|
6
7
|
ARGV.each do |file_or_dir|
|
7
8
|
if File.lstat(file_or_dir).directory? then
|
8
|
-
|
9
|
+
Dir["#{file_or_dir}/**/*.rb"].each do |file|
|
10
|
+
require "#{file}"
|
11
|
+
end
|
9
12
|
else
|
10
13
|
require file_or_dir
|
11
14
|
end
|
@@ -14,21 +14,21 @@ h3. General
|
|
14
14
|
h4. Arbitrary Block
|
15
15
|
|
16
16
|
<ruby>
|
17
|
-
target.
|
18
|
-
target.
|
17
|
+
target.should_satisfysatisfy {|arg| ...}
|
18
|
+
target.should_satisfynot.satisfy {|arg| ...}
|
19
19
|
</ruby>
|
20
20
|
|
21
21
|
The supplied block is evaluated, passing <code>target</code> as the sole argument. If the block evaluates to <code>false</code>, <code>ExpectationNotMetError</code> is raised.
|
22
22
|
|
23
23
|
<ruby>
|
24
|
-
target.
|
24
|
+
target.should_satisfysatisfy {|arg| arg > 0}
|
25
25
|
</ruby>
|
26
26
|
|
27
27
|
h4. Equality
|
28
28
|
|
29
29
|
<ruby>
|
30
|
-
target.
|
31
|
-
target.
|
30
|
+
target.should_satisfyequal <value>
|
31
|
+
target.should_satisfynot.equal <value>
|
32
32
|
</ruby>
|
33
33
|
|
34
34
|
The target object is compared to <code>value</code> using ==. If the result is <code>false</code>, <code>ExpectationNotMetError</code> is raised.
|
@@ -36,21 +36,21 @@ The target object is compared to <code>value</code> using ==. If the result is <
|
|
36
36
|
h4. Floating Point Comparison
|
37
37
|
|
38
38
|
<ruby>
|
39
|
-
target.
|
40
|
-
target.
|
39
|
+
target.should_satisfybe.close <value>, <tolerance>
|
40
|
+
target.should_satisfynot.be.close <value>, <tolerance>
|
41
41
|
</ruby>
|
42
42
|
|
43
43
|
The target object is compared to <code>value</code>. If they differ by more that <code>tolerance</code>, <code>ExpectationNotMetError</code> is raised. In the negated case, <code>ExpectationNotMetError</code> is raised if they differ by less than <code>tolerance</code>.
|
44
44
|
|
45
45
|
<ruby>
|
46
|
-
target.
|
46
|
+
target.should_satisfybe.close 27.35, 0.05
|
47
47
|
</ruby>
|
48
48
|
|
49
49
|
h4. Identity
|
50
50
|
|
51
51
|
<ruby>
|
52
|
-
target.
|
53
|
-
target.
|
52
|
+
target.should_satisfybe <value>
|
53
|
+
target.should_satisfynot.be <value>
|
54
54
|
</ruby>
|
55
55
|
|
56
56
|
The target object is compared to <code>value</code> using <code>equal?</code>. If the result is <code>false</code>, <code>ExpectationNotMetError</code> is raised.
|
@@ -58,10 +58,10 @@ The target object is compared to <code>value</code> using <code>equal?</code>. I
|
|
58
58
|
h4. Arbitrary Predicate
|
59
59
|
|
60
60
|
<ruby>
|
61
|
-
target.
|
62
|
-
target.
|
63
|
-
target.
|
64
|
-
target.
|
61
|
+
target.should_satisfypredicate [optional args]
|
62
|
+
target.should_satisfybe.predicate [optional args]
|
63
|
+
target.should_satisfynot.predicate [optional args]
|
64
|
+
target.should_satisfynot.be.predicate [optional args]
|
65
65
|
</ruby>
|
66
66
|
|
67
67
|
The message <code>predicate?</code> is sent to <code>target</code> with any supplied arguments. If the result is <code>false</code>, <code>ExpectationNotMetError</code> is raised.
|
@@ -69,15 +69,15 @@ The message <code>predicate?</code> is sent to <code>target</code> with any supp
|
|
69
69
|
For example:
|
70
70
|
|
71
71
|
<ruby>
|
72
|
-
container.
|
73
|
-
container.
|
72
|
+
container.should_satisfyinclude('a') => container.include?('a')
|
73
|
+
container.should_satisfybe.empty => container.empty?
|
74
74
|
</ruby>
|
75
75
|
|
76
76
|
h4. Pattern Matching
|
77
77
|
|
78
78
|
<ruby>
|
79
|
-
target.
|
80
|
-
target.
|
79
|
+
target.should_satisfymatch <regex>
|
80
|
+
target.should_satisfynot.match <regex>
|
81
81
|
</ruby>
|
82
82
|
|
83
83
|
The <code>target</code> is matched against <code>regex</code>. An <code>ExpectationNotMetError</code> is raised if the match fails.
|
@@ -87,8 +87,8 @@ h3. Class/Type
|
|
87
87
|
h4. Direct Instance
|
88
88
|
|
89
89
|
<ruby>
|
90
|
-
target.
|
91
|
-
target.
|
90
|
+
target.should_satisfybe.an.instance.of <class>
|
91
|
+
target.should_satisfynot.be.an.instance.of <class>
|
92
92
|
</ruby>
|
93
93
|
|
94
94
|
An <code>ExpectationNotMetError</code> is raised if <code>target</code> is not or is, respectively, an direct instance of <code>class</code>. As expected this correlates to <code>target.instance_of? class</code>.
|
@@ -96,8 +96,8 @@ An <code>ExpectationNotMetError</code> is raised if <code>target</code> is not o
|
|
96
96
|
h4. Ancestor Class
|
97
97
|
|
98
98
|
<ruby>
|
99
|
-
target.
|
100
|
-
target.
|
99
|
+
target.should_satisfybe.a.kind.of <class>
|
100
|
+
target.should_satisfynot.be.a.kind.of <class>
|
101
101
|
</ruby>
|
102
102
|
|
103
103
|
As above, but uses <code>target.kind_of? class</code>: checking whether <code>class</code> is the direct class of <code>target</code>, or an ancestor of <code>target</code>'s direct class.
|
@@ -105,8 +105,8 @@ As above, but uses <code>target.kind_of? class</code>: checking whether <code>cl
|
|
105
105
|
h4. Type
|
106
106
|
|
107
107
|
<ruby>
|
108
|
-
target.
|
109
|
-
target.
|
108
|
+
target.should_satisfyrespond.to <symbol>
|
109
|
+
target.should_satisfynot.respond.to <symbol>
|
110
110
|
</ruby>
|
111
111
|
|
112
112
|
Uses <code>target.respond_to?(symbol)</code> to check whether <code>symbol</code> is the name of a message that <code>target</code> understands.
|
@@ -116,21 +116,21 @@ h3. Procs
|
|
116
116
|
h4. Raising
|
117
117
|
|
118
118
|
<ruby>
|
119
|
-
proc.
|
120
|
-
proc.
|
119
|
+
proc.should_satisfyraise <exception>
|
120
|
+
proc.should_satisfynot.raise <exception>
|
121
121
|
</ruby>
|
122
122
|
|
123
123
|
Checks that <code>proc</code> causes the named exception to be raised or not. The latter is actually one of two cases: some other exception is raised, or no exception is raised. Typically the <code>proc</code> is created in place using <code>lambda</code>. For example:
|
124
124
|
|
125
125
|
<ruby>
|
126
|
-
lambda { 3 / 0 }.
|
126
|
+
lambda { 3 / 0 }.should_satisfyraise ZeroDivisionError
|
127
127
|
</ruby>
|
128
128
|
|
129
129
|
There is a more general form as well.
|
130
130
|
|
131
131
|
<ruby>
|
132
|
-
proc.
|
133
|
-
proc.
|
132
|
+
proc.should_satisfyraise
|
133
|
+
proc.should_satisfynot.raise
|
134
134
|
</ruby>
|
135
135
|
|
136
136
|
These forms don't worry about what exception is raised (or not). All they are concerned with is that some except was raised, or that no exception was.
|
@@ -138,14 +138,14 @@ These forms don't worry about what exception is raised (or not). All they are co
|
|
138
138
|
h4. Throwing
|
139
139
|
|
140
140
|
<ruby>
|
141
|
-
proc.
|
142
|
-
proc.
|
141
|
+
proc.should_satisfythrow <symbol>
|
142
|
+
proc.should_satisfynot.throw <symbol>
|
143
143
|
</ruby>
|
144
144
|
|
145
145
|
Similar to the above, but checks that <code>symbol</code> is thrown from within <code>proc</code>, or not. The latter is actually one of two cases: some other symbol is thrown, or no symbol is thrown.
|
146
146
|
|
147
147
|
<ruby>
|
148
|
-
proc.
|
148
|
+
proc.should_satisfynot.throw
|
149
149
|
</ruby>
|
150
150
|
|
151
151
|
This form is more specific. It checks that no symbol is thrown from within <code>proc</code>.
|
@@ -155,8 +155,8 @@ h3. Collections
|
|
155
155
|
h4. Containment
|
156
156
|
|
157
157
|
<ruby>
|
158
|
-
target.
|
159
|
-
target.
|
158
|
+
target.should_satisfyinclude <object>
|
159
|
+
target.should_satisfynot.include <object>
|
160
160
|
</ruby>
|
161
161
|
|
162
162
|
This is simply a specific case of the arbitrary predicate form. It uses <code>target.include?(object)</code> and raises an <code>ExpectationNotMetError</code> if that returns false.
|
@@ -166,7 +166,7 @@ The remaining collection forms are a little more involved. They rely on two thin
|
|
166
166
|
h4. Exact Size
|
167
167
|
|
168
168
|
<ruby>
|
169
|
-
target.
|
169
|
+
target.should_satisfyhave(<number>).things
|
170
170
|
</ruby>
|
171
171
|
|
172
172
|
The <code>things</code> of <code>target</code> has a length/size of exactly <code>number</code>.
|
@@ -174,7 +174,7 @@ The <code>things</code> of <code>target</code> has a length/size of exactly <cod
|
|
174
174
|
h4. Lower Bound
|
175
175
|
|
176
176
|
<ruby>
|
177
|
-
target.
|
177
|
+
target.should_satisfyhave.at.least(<number>).things
|
178
178
|
</ruby>
|
179
179
|
|
180
180
|
The <code>things</code> of <code>target</code> has a length/size of no less than <code>number</code>.
|
@@ -182,7 +182,7 @@ The <code>things</code> of <code>target</code> has a length/size of no less than
|
|
182
182
|
h4. Upper Bound
|
183
183
|
|
184
184
|
<ruby>
|
185
|
-
target.
|
185
|
+
target.should_satisfyhave.at.most(<number>).things
|
186
186
|
</ruby>
|
187
187
|
|
188
188
|
The <code>things</code> of <code>target</code> has a length/size of no more than <code>number</code>.
|
@@ -27,7 +27,7 @@ my_mock = mock("blah", :null_object => true)
|
|
27
27
|
h3. Expecting Messages
|
28
28
|
|
29
29
|
<ruby>
|
30
|
-
my_mock.
|
30
|
+
my_mock.should_receivereceive(<message>)
|
31
31
|
</ruby>
|
32
32
|
|
33
33
|
The <code>message</code> argument is a symbol that is the name of a message that you want the mock to expect.
|
@@ -39,7 +39,7 @@ by the mock, the block is evaluated, and passed any arguments. The result is
|
|
39
39
|
the return value of the message. For example:
|
40
40
|
|
41
41
|
<ruby>
|
42
|
-
my_mock.
|
42
|
+
my_mock.should_receivereceive(:random_call) {| a | a.should_receivebe true}
|
43
43
|
</ruby>
|
44
44
|
|
45
45
|
This allows arbitrary argument validation and result computation. It's handy and kind of cool to be able to do this, but I advise against it. Mocks should not be functional. they should be completely declarative. That said, it's sometimes useful to give them some minimal behaviour.
|
@@ -47,25 +47,25 @@ This allows arbitrary argument validation and result computation. It's handy an
|
|
47
47
|
h3. Expecting Arguments
|
48
48
|
|
49
49
|
<ruby>
|
50
|
-
my_mock.
|
50
|
+
my_mock.should_receivereceive(:msg).with(<args>)
|
51
51
|
</ruby>
|
52
52
|
|
53
53
|
for example:
|
54
54
|
|
55
55
|
<ruby>
|
56
|
-
my_mock.
|
56
|
+
my_mock.should_receivereceive(:msg).with(1, 2, 3)
|
57
57
|
</ruby>
|
58
58
|
|
59
59
|
The <code>args</code> argument is a series of arguments (e.g. 1, 2, 3) that are expected to be passed as arguments to the associated message.
|
60
60
|
|
61
61
|
<ruby>
|
62
|
-
my_mock.
|
62
|
+
my_mock.should_receivereceive(:msg).with(:no_args)
|
63
63
|
</ruby>
|
64
64
|
|
65
65
|
The message (<code>msg</code>) is expected to be passed no arguments.
|
66
66
|
|
67
67
|
<ruby>
|
68
|
-
my_mock.
|
68
|
+
my_mock.should_receivereceive(:msg).with(:any_args)
|
69
69
|
</ruby>
|
70
70
|
|
71
71
|
Any arguments (and any number of arguments) are to be accepted. This includes cases where no arguments are provided. *This is the default when no <code>with()</code> clause is specified.* Even so, sometimes you want to be explicit about it.
|
@@ -79,7 +79,7 @@ h4. :anything
|
|
79
79
|
accepts any value for this argument, e.g.:
|
80
80
|
|
81
81
|
<ruby>
|
82
|
-
my_mock.
|
82
|
+
my_mock.should_receivereceive(:msg).with(1, :anything, "A")
|
83
83
|
</ruby>
|
84
84
|
|
85
85
|
h4. :numeric
|
@@ -87,7 +87,7 @@ h4. :numeric
|
|
87
87
|
accepts any numeric value for this argument, e.g.:
|
88
88
|
|
89
89
|
<ruby>
|
90
|
-
my_mock.
|
90
|
+
my_mock.should_receivereceive(:msg).with(a, :numeric, "b")
|
91
91
|
</ruby>
|
92
92
|
|
93
93
|
h4. :boolean
|
@@ -95,7 +95,7 @@ h4. :boolean
|
|
95
95
|
accepts a boolean value for this argument, e.g.:
|
96
96
|
|
97
97
|
<ruby>
|
98
|
-
my_mock.
|
98
|
+
my_mock.should_receivereceive(:msg).with(a, :boolean, "b")
|
99
99
|
</ruby>
|
100
100
|
|
101
101
|
h4. :string
|
@@ -103,7 +103,7 @@ h4. :string
|
|
103
103
|
accepts any string for this argument, e.g.:
|
104
104
|
|
105
105
|
<ruby>
|
106
|
-
my_mock.
|
106
|
+
my_mock.should_receivereceive(:msg).with(a, :string, "b")
|
107
107
|
</ruby>
|
108
108
|
|
109
109
|
h4. duck_type(message(s))
|
@@ -112,55 +112,55 @@ accepts any object that responds to the prescribed message(s), e.g.:
|
|
112
112
|
|
113
113
|
<ruby>
|
114
114
|
#accepts a Fixnum for the second arg
|
115
|
-
my_mock.
|
115
|
+
my_mock.should_receivereceive(:msg).with(a, duck_type(:abs, :div), "b")
|
116
116
|
</ruby>
|
117
117
|
|
118
118
|
h3. Receive Counts
|
119
119
|
|
120
120
|
<ruby>
|
121
|
-
my_mock.
|
121
|
+
my_mock.should_receivereceive(:msg).never
|
122
122
|
</ruby>
|
123
123
|
|
124
124
|
An exception is raised if the message is ever received.
|
125
125
|
|
126
126
|
<ruby>
|
127
|
-
my_mock.
|
127
|
+
my_mock.should_receivereceive(:msg).any.number.of.times
|
128
128
|
</ruby>
|
129
129
|
|
130
130
|
The message can be received 0 or more times.
|
131
131
|
|
132
132
|
<ruby>
|
133
|
-
my_mock.
|
133
|
+
my_mock.should_receivereceive(:msg).once
|
134
134
|
</ruby>
|
135
135
|
|
136
136
|
An exception is raised if the message is never received, or it is received more than once.
|
137
137
|
|
138
138
|
<ruby>
|
139
|
-
my_mock.
|
139
|
+
my_mock.should_receivereceive(:msg).twice
|
140
140
|
</ruby>
|
141
141
|
|
142
142
|
An exception is raised if the message is received anything but two times.
|
143
143
|
|
144
144
|
<ruby>
|
145
|
-
my_mock.
|
145
|
+
my_mock.should_receivereceive(:msg).exactly(n).times
|
146
146
|
</ruby>
|
147
147
|
|
148
148
|
An exception is raised if the message is received anything but <code>n</code> times.
|
149
149
|
|
150
150
|
<ruby>
|
151
|
-
my_mock.
|
151
|
+
my_mock.should_receivereceive(:msg).at.least(:once)
|
152
152
|
</ruby>
|
153
153
|
|
154
154
|
An exception is raised if the message is never received.
|
155
155
|
|
156
156
|
<ruby>
|
157
|
-
my_mock.
|
157
|
+
my_mock.should_receivereceive(:msg).at.least(:twice)
|
158
158
|
</ruby>
|
159
159
|
|
160
160
|
An exception is raised if the message is never received or is received only once.
|
161
161
|
|
162
162
|
<ruby>
|
163
|
-
my_mock.
|
163
|
+
my_mock.should_receivereceive(:msg).at.least(n).times
|
164
164
|
</ruby>
|
165
165
|
|
166
166
|
An exception is raised if the message is received fewer than <code>n</code> times.
|
@@ -170,7 +170,7 @@ h3. Return Values
|
|
170
170
|
h4. Single return value
|
171
171
|
|
172
172
|
<ruby>
|
173
|
-
my_mock.
|
173
|
+
my_mock.should_receivereceive(:msg).once.and.return(<value>)
|
174
174
|
</ruby>
|
175
175
|
|
176
176
|
Each time the expected message is received, <code>value</code> will be returned as the result.
|
@@ -193,7 +193,7 @@ and.return([[1, 2, 3]])
|
|
193
193
|
h4. Computed return value
|
194
194
|
|
195
195
|
<ruby>
|
196
|
-
my_mock.
|
196
|
+
my_mock.should_receivereceive(:msg).once.and.return {...}
|
197
197
|
</ruby>
|
198
198
|
|
199
199
|
When the expected message is received, the result of evaluating the supplied
|
@@ -201,14 +201,14 @@ block will be returned as the result. The block is passed any arguments passed
|
|
201
201
|
as arguments of the message. This capability can be used to compute return values based on the arguments. For example:
|
202
202
|
|
203
203
|
<ruby>
|
204
|
-
my_mock.
|
204
|
+
my_mock.should_receivereceive(:msg).with(:numeric, :numeric) once.and.return {|a, b| a + b}
|
205
205
|
</ruby>
|
206
206
|
|
207
207
|
h3. Raising and Throwing
|
208
208
|
|
209
209
|
<ruby>
|
210
|
-
my_mock.
|
211
|
-
my_mock.
|
210
|
+
my_mock.should_receivereceive(:msg).once.and.raise(<exception>)
|
211
|
+
my_mock.should_receivereceive(:msg).once.and.throw(<symbol>)
|
212
212
|
</ruby>
|
213
213
|
|
214
214
|
These instruct the mock to raise an exception or throw a symbol, respectively, instead of returning a value.
|
@@ -216,7 +216,7 @@ These instruct the mock to raise an exception or throw a symbol, respectively, i
|
|
216
216
|
h3. Yielding
|
217
217
|
|
218
218
|
<ruby>
|
219
|
-
my_mock.
|
219
|
+
my_mock.should_receivereceive(:msg).once.and.yield([<value-1>, <value-2>, ..., <value-n>])
|
220
220
|
</ruby>
|
221
221
|
|
222
222
|
When the expected message is received, the mock will yield the values to the passed block.
|
@@ -229,8 +229,8 @@ It shouldn't be the case very often, but it can be handy at times.
|
|
229
229
|
Labeling expectations as being ordered is done by the <code>ordered</code> call:
|
230
230
|
|
231
231
|
<ruby>
|
232
|
-
my_mock.
|
233
|
-
my_mock.
|
232
|
+
my_mock.should_receivereceive(:flip).once.ordered
|
233
|
+
my_mock.should_receivereceive(:flop).once.ordered
|
234
234
|
</ruby>
|
235
235
|
|
236
236
|
If the send of <code>flop</code> is seen before <code>flip</code> the specification will fail.
|
@@ -238,9 +238,9 @@ If the send of <code>flop</code> is seen before <code>flip</code> the specificat
|
|
238
238
|
Of course, chains of ordered expectations can be set up:
|
239
239
|
|
240
240
|
<ruby>
|
241
|
-
my_mock.
|
242
|
-
my_mock.
|
243
|
-
my_mock.
|
241
|
+
my_mock.should_receivereceive(:one).ordered
|
242
|
+
my_mock.should_receivereceive(:two).ordered
|
243
|
+
my_mock.should_receivereceive(:three).ordered
|
244
244
|
</ruby>
|
245
245
|
|
246
246
|
The expected order is the order in which the expectations are declared.
|
@@ -248,10 +248,10 @@ The expected order is the order in which the expectations are declared.
|
|
248
248
|
Order-independant expectations can be set anywhere in the expectation sequence, in any order. Only the order of expectations tagged with the <code>ordered</code> call is significant. Likewise, calls to order-independant methods can be made in any order, even interspersed with calls to order-dependant methods. For example:
|
249
249
|
|
250
250
|
<ruby>
|
251
|
-
my_mock.
|
252
|
-
my_mock.
|
253
|
-
my_mock.
|
254
|
-
my_mock.
|
251
|
+
my_mock.should_receivereceive(:zero)
|
252
|
+
my_mock.should_receivereceive(:one).ordered
|
253
|
+
my_mock.should_receivereceive(:two).ordered
|
254
|
+
my_mock.should_receivereceive(:one_and_a_half)
|
255
255
|
my_mock.one
|
256
256
|
my_mock.one_and_a_half
|
257
257
|
my_mock.zero
|