rspec 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGES +9 -5
  2. data/Rakefile +35 -29
  3. data/bin/spec +0 -5
  4. data/doc/README +5 -0
  5. data/doc/config.yaml +2 -0
  6. data/doc/plugin/syntax.rb +38 -0
  7. data/doc/reference/rspec reference.page +0 -0
  8. data/doc/src/community.page +8 -0
  9. data/doc/src/default.css +198 -0
  10. data/doc/src/default.template +34 -0
  11. data/doc/src/documentation/api.page +251 -0
  12. data/doc/src/documentation/index.page +8 -0
  13. data/doc/src/documentation/mocks.page +207 -0
  14. data/doc/src/documentation/specs.page +20 -0
  15. data/doc/src/download.page +8 -0
  16. data/doc/src/examples.page +9 -0
  17. data/doc/src/images/ul.gif +0 -0
  18. data/doc/src/index.page +8 -0
  19. data/doc/src/tools/index.page +8 -0
  20. data/doc/src/tools/rails.page +8 -0
  21. data/doc/src/tools/rake.page +8 -0
  22. data/doc/src/tools/rcov.page +8 -0
  23. data/doc/src/tools/spec_runner.page +8 -0
  24. data/doc/src/tools/specdoc.page +8 -0
  25. data/doc/src/tools/test2rspec.page +8 -0
  26. data/doc/src/ul.gif +0 -0
  27. data/doc/src/why_rspec.page +8 -0
  28. data/examples/mocking_spec.rb +2 -2
  29. data/examples/spec_framework_spec.rb +4 -4
  30. data/lib/spec/api/helper/have_helper.rb +55 -55
  31. data/lib/spec/api/mock.rb +111 -38
  32. data/lib/spec/runner/backtrace_tweaker.rb +4 -4
  33. data/lib/spec/runner/context.rb +2 -1
  34. data/lib/spec/runner/context_runner.rb +3 -3
  35. data/lib/spec/runner/option_parser.rb +8 -4
  36. data/lib/spec/runner/simple_text_reporter.rb +29 -19
  37. data/lib/spec/runner/specification.rb +2 -1
  38. data/lib/spec/version.rb +1 -1
  39. data/test/rake/rcov_testtask.rb +45 -0
  40. data/test/spec/api/helper/arbitrary_predicate_test.rb +39 -24
  41. data/test/spec/api/helper/equality_test.rb +19 -0
  42. data/test/spec/api/helper/should_have_test.rb +183 -0
  43. data/test/spec/api/mock_arg_constraints_test.rb +90 -0
  44. data/test/spec/api/mock_test.rb +101 -21
  45. data/test/spec/runner/context_runner_test.rb +3 -3
  46. data/test/spec/runner/context_test.rb +2 -5
  47. data/test/spec/runner/execution_context_test.rb +1 -1
  48. data/test/spec/runner/option_parser_test.rb +16 -8
  49. data/test/spec/runner/simple_text_reporter_test.rb +57 -33
  50. data/test/spec/runner/specification_test.rb +7 -7
  51. data/test/spec/tool/command_line_test.rb +4 -4
  52. data/test/test_helper.rb +2 -2
  53. metadata +37 -8
  54. data/README +0 -38
  55. data/TODO +0 -9
  56. data/TUTORIAL +0 -259
  57. data/WHY_RSPEC +0 -115
@@ -0,0 +1,251 @@
1
+ ---
2
+ title: Core API
3
+ inMenu: true
4
+ ordering: 5
5
+ ---
6
+ h2. Core API
7
+
8
+ When RSpec executes specifications, it defines a method *should* on every object in the system.
9
+ This *should* method is your entry to the magic of RSpec.
10
+
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
13
+ violated.
14
+
15
+ h3. General
16
+
17
+ h4. Arbitrary Block
18
+
19
+ <pre>
20
+ <code>
21
+ target.should.satisfy {|arg| ...}
22
+ target.should.not.satisfy {|arg| ...}
23
+ </code>
24
+ </pre>
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, or true in the case of
28
+ should.not.satisfy, ExpectationNotMetError is raised.
29
+
30
+ <pre>
31
+ <code>
32
+ target.should.satisfy {|arg| arg > 0}
33
+ </code>
34
+ </pre>
35
+
36
+ h4. Equality
37
+ <pre>
38
+ <code>
39
+ target.should.equal <value>
40
+ target.should.not.equal <value>
41
+ </code>
42
+ </pre>
43
+
44
+ The target object is compared to <value> using ==. If the result is false (or
45
+ true for the negated form) ExpectationNotMetError is raised.
46
+
47
+ h4. Floating Point Comparison
48
+
49
+ <pre>
50
+ <code>
51
+ target.should.be.close <value>, <tolerance>
52
+ target.should.not.be.close <value>, <tolerance>
53
+ </code>
54
+ </pre>
55
+
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>.
59
+
60
+ <pre>
61
+ <code>
62
+ target.should.be.close 27.35, 0.05
63
+ </code>
64
+ </pre>
65
+
66
+ h4. Identity
67
+
68
+ <pre>
69
+ <code>
70
+ target.should.be <value>
71
+ target.should.not.be <value>
72
+ </code>
73
+ </pre>
74
+
75
+ The target object is compared to <value> using equal?. If the result is false
76
+ (or true for the negated form) ExpectationNotMetError is raised.
77
+
78
+ h4. Arbitrary Predicate
79
+
80
+
81
+ <pre>
82
+ <code>
83
+ target.should.predicate [optional args]
84
+ target.should.be.predicate [optional args]
85
+ target.should.not.predicate [optional args]
86
+ target.should.not.be.predicate [optional args]
87
+ </code>
88
+ </pre>
89
+
90
+ The message predicate? is sent to target with any supplied arguments. If the
91
+ result is false (or true for the negated form) ExpectationNotMetError is
92
+ raised.
93
+
94
+ <pre>
95
+ <code>
96
+ container.should.include 'a' uses container.include? 'a'
97
+ container.should.be.empty uses container.empty?
98
+ </code>
99
+ </pre>
100
+
101
+ h4. Pattern Matching
102
+
103
+ <pre>
104
+ <code>
105
+ target.should.match <regex>
106
+ target.should.not.match <regex>
107
+ </code>
108
+ </pre>
109
+
110
+ The target is matched against <regex>. An ExpectationNotMetError is raised if
111
+ the match fails or succeeds, respectively.
112
+
113
+ h3. Class/Type
114
+
115
+ h4. Direct Instance
116
+
117
+ <pre>
118
+ <code>
119
+ target.should.be.an.instance.of <class>
120
+ target.should.not.be.an.instance.of <class>
121
+ </code>
122
+ </pre>
123
+
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
+ <class>.
127
+
128
+ h4. Ancestor Class
129
+
130
+ <pre>
131
+ <code>
132
+ target.should.be.a.kind.of <class>
133
+ target.should.not.be.a.kind.of <class>
134
+ </code>
135
+ </pre>
136
+
137
+ As above, but uses target.kind_of? <class>: checking whether <class> is the
138
+ direct class of target, or an ancestor of target's class.
139
+
140
+ h4. Type
141
+
142
+ <pre>
143
+ <code>
144
+ target.should.respond.to <symbol>
145
+ target.should.not.respond.to <symbol>
146
+ </code>
147
+ </pre>
148
+
149
+ Uses target.respond_to? <symbol> to check whether <symbol> is the name of a
150
+ message that target understands.
151
+
152
+ h3. Procs
153
+
154
+ h4. Raising
155
+
156
+ <pre>
157
+ <code>
158
+ proc.should.raise <exception>
159
+ proc.should.not.raise <exception>
160
+ </code>
161
+ </pre>
162
+
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. For example:
165
+
166
+ <pre>
167
+ <code>
168
+ lambda { 3 / 0 }.should.raise ZeroDivisionError
169
+ </code>
170
+ </pre>
171
+
172
+ There is a more general form as well.
173
+
174
+ <pre>
175
+ <code>
176
+ proc.should.raise
177
+ proc.should.not.raise
178
+ </code>
179
+ </pre>
180
+
181
+ These forms don't worry about what exception is raised (or not). All they are
182
+ concern with is that some except was raised, or that no exception was raised.
183
+
184
+ h4. Throwing
185
+
186
+ <pre>
187
+ <code>
188
+ proc.should.throw <symbol>
189
+ proc.should.not.throw <symbol>
190
+ </code>
191
+ </pre>
192
+
193
+ Similar to the above, but checks that <symbol> is thrown from within proc, or
194
+ that it is not. The latter is actually one of two cases: some other symbol is
195
+ thrown, or no symbol is thrown.
196
+
197
+ <pre>
198
+ <code>
199
+ proc.should.not.throw
200
+ </code>
201
+ </pre>
202
+
203
+ This form is more specific. It checks that no symbol is thrown from within proc.
204
+
205
+ h3. Collections
206
+
207
+ h4. Containment
208
+
209
+ <pre>
210
+ <code>
211
+ target.should.include <object>
212
+ </code>
213
+ </pre>
214
+
215
+ This is simply a specific case of the arbitrary predicate form. It uses
216
+ target.include? <object> and raises an ExpectationNotMetError if that returns
217
+ 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, which return a number that is a
220
+ measure of size. Currently length is used if is appropriate, otherwise size is
221
+ attempted.
222
+
223
+ 4. Exact Size
224
+
225
+ <pre>
226
+ <code>
227
+ target.should.have(<number>).<things>
228
+ </code>
229
+ </pre>
230
+
231
+ The <things> of target has a length/size of exactly <number>.
232
+
233
+ h4. Lower Bound
234
+
235
+ <pre>
236
+ <code>
237
+ target.should.have.at.least(<number>).<things>
238
+ </code>
239
+ </pre>
240
+
241
+ The <things> of target has a length/size of no less than <number>.
242
+
243
+ h4. Upper Bound
244
+
245
+ <pre>
246
+ <code>
247
+ target.should.have.at.most(<number>).<things>
248
+ </code>
249
+ </pre>
250
+
251
+ The <things> of target has a length/size of no more than <number>.
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Documentation
3
+ inMenu: true
4
+ ordering: 1
5
+ ---
6
+ h2. Documentation
7
+
8
+ Here is all the doco
@@ -0,0 +1,207 @@
1
+ ---
2
+ title: Mock API
3
+ inMenu: true
4
+ ordering: 5
5
+ ---
6
+ h2. Mock API
7
+
8
+ RSpec contains a full featured Mock Objects framework.
9
+
10
+ h3. Creating a mock
11
+
12
+ <pre>
13
+ <code>
14
+ mock(<name>)
15
+ </code>
16
+ </pre>
17
+
18
+ This creates a new mock with the given name (a string) and registers it. When
19
+ the specification finishes, all registered mocks are verified.
20
+
21
+ <pre>
22
+ <code>
23
+ mock(<name>, <options>)
24
+ </code>
25
+ </pre>
26
+
27
+ 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
+ :null_object. Setting this to true (i.e. :null_object => true) instructs the
30
+ mock to ignore (quietly consume) any messages it hasn't been told to expect.
31
+
32
+ h3. Expecting Messages
33
+
34
+ <pre>
35
+ <code>
36
+ mock.should.receive(<message>)
37
+ </code>
38
+ </pre>
39
+
40
+ The <message> argument is a symbol that is the name of a message that you want
41
+ the mock to be expecting.
42
+
43
+ h3. Arbitrary Message Receive Handling
44
+
45
+ You can supply a block to a message expectation. When the message is received
46
+ by the mock, the block is evaluated, and passed any arguments. The result is
47
+ the return value of the message. For example:
48
+
49
+ <pre>
50
+ <code>
51
+ @mock.should.receive(:random_call) {| a | a.should.be true}
52
+ </code>
53
+ </pre>
54
+
55
+ This allows arbitrary argument validation and result computation.
56
+
57
+ h3. Expecting Arguments
58
+
59
+ <pre>
60
+ <code>
61
+ mock.should.receive(:msg).with(<args>)
62
+ mock.should.receive(:msg).with(1, 2, 3)
63
+ </code>
64
+ </pre>
65
+
66
+ The <args> argument is a series of arguments (e..g. 1, 2, 3) that are expected
67
+ to be passed as arguments to the associated message.
68
+
69
+ <pre>
70
+ <code>
71
+ mock.should.receive(:msg).with(:nothing)
72
+ </code>
73
+ </pre>
74
+
75
+ No arguments are to be accepted by the message.
76
+
77
+ <pre>
78
+ <code>
79
+ mock.should.receive(:msg).with(:anything)
80
+ </code>
81
+ </pre>
82
+
83
+ Any arguments are to be accepted by the message. Additionally, constraints can
84
+ be placed on individual arguments which are looser than value equivalence.
85
+
86
+ <pre>
87
+ <code>
88
+ :anything
89
+ </code>
90
+ </pre>
91
+
92
+ accepts any value for this argument
93
+
94
+ <pre>
95
+ <code>
96
+ mock.should.receive(:msg).with(1, :anything, "A")
97
+ </code>
98
+ </pre>
99
+
100
+ h3. Receive Counts
101
+
102
+ <pre>
103
+ <code>
104
+ mock.should.receive(:msg).with(:nothing).never
105
+ </code>
106
+ </pre>
107
+
108
+ A problem is reported if the message is ever received.
109
+
110
+ <pre>
111
+ <code>
112
+ mock.should.receive(:msg).with(:nothing).any.number.of.times
113
+ </code>
114
+ </pre>
115
+
116
+ The message can be received 0 or more times.
117
+
118
+ <pre>
119
+ <code>
120
+ mock.should.receive(:msg).with(:nothing).once
121
+ </code>
122
+ </pre>
123
+
124
+ A problem is reported is the message is never received, or it is received more
125
+ than once.
126
+
127
+ <pre>
128
+ <code>
129
+ mock.should.receive(:msg).with(:nothing).twice
130
+ </code>
131
+ </pre>
132
+
133
+ A problem is reported is the message is received anything but two times.
134
+
135
+ <pre>
136
+ <code>
137
+ mock.should.receive(:msg).with(:nothing).exactly(n).times
138
+ </code>
139
+ </pre>
140
+
141
+ A problem is reported is the message is received anything but n times.
142
+
143
+ <pre>
144
+ <code>
145
+ mock.should.receive(:msg).with(:nothing).at.least(:once)
146
+ </code>
147
+ </pre>
148
+
149
+ A problem is reported if the message is never received.
150
+
151
+ <pre>
152
+ <code>
153
+ mock.should.receive(:msg).with(:nothing).at.least(:twice)
154
+ </code>
155
+ </pre>
156
+
157
+ A problem is reported is the message is never received or is received only once.
158
+
159
+ <pre>
160
+ <code>
161
+ mock.should.receive(:msg).with(:nothing).at.least(n).times
162
+ </code>
163
+ </pre>
164
+
165
+ A problem is reported is the message is received fewer than n times.
166
+
167
+ h3. Return Values
168
+
169
+ <pre>
170
+ <code>
171
+ mock.should.receive(:msg).with(:nothing).once.and.return(<value>)
172
+ </code>
173
+ </pre>
174
+
175
+ When the expected message is received, <value> will be returned as the result.
176
+
177
+ <pre>
178
+ <code>
179
+ and.return([<value1>, <value2>, …, <valuen>])
180
+ mock.should.receive(:msg).with(:nothing).once.and.return(1, 2, 3)
181
+ </code>
182
+ </pre>
183
+
184
+ When the expected message is received, <valuei> will be returned as the result
185
+ for the ith reception of the message. Once i > n, <valuen> is returned for all
186
+ subsequent receives of the message.
187
+
188
+ <pre>
189
+ <code>
190
+ mock.should.receive(:msg).with(:nothing).once.and.return {…}
191
+ mock.should.receive(:msg).with(:anything).once.and.return {|a, b| a + b}
192
+ </code>
193
+ </pre>
194
+
195
+ When the expected message is received, the result of evaluating the supplied
196
+ block will be returned as the result. The block is passed any arguments passed
197
+ as parts of the message. This capability can be used to compute return values
198
+ based on the arguments.
199
+
200
+ <pre>
201
+ <code>
202
+ mock.should.receive(:msg).with(:anything).once.and.throw(<symbol>)
203
+ mock.should.receive(:msg).with(:anything).once.and.raise(<exception>)
204
+ </code>
205
+ </pre>
206
+
207
+ These instruct the mock to raise an exception or throw a symbol instead of returning a value.on other objects.