rsanheim-micronaut 0.1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +45 -0
- data/README +17 -0
- data/RSPEC-LICENSE +23 -0
- data/Rakefile +83 -0
- data/bin/micronaut +4 -0
- data/examples/example_helper.rb +36 -0
- data/examples/lib/micronaut/behaviour_example.rb +188 -0
- data/examples/lib/micronaut/configuration_example.rb +70 -0
- data/examples/lib/micronaut/example_example.rb +46 -0
- data/examples/lib/micronaut/expectations/extensions/object_example.rb +72 -0
- data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
- data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +31 -0
- data/examples/lib/micronaut/formatters/base_formatter_example.rb +107 -0
- data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
- data/examples/lib/micronaut/formatters/progress_formatter_example.rb +74 -0
- data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
- data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
- data/examples/lib/micronaut/matchers/be_example.rb +298 -0
- data/examples/lib/micronaut/matchers/change_example.rb +360 -0
- data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
- data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
- data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
- data/examples/lib/micronaut/matchers/handler_example.rb +153 -0
- data/examples/lib/micronaut/matchers/has_example.rb +71 -0
- data/examples/lib/micronaut/matchers/have_example.rb +575 -0
- data/examples/lib/micronaut/matchers/include_example.rb +103 -0
- data/examples/lib/micronaut/matchers/match_example.rb +43 -0
- data/examples/lib/micronaut/matchers/matcher_methods_example.rb +66 -0
- data/examples/lib/micronaut/matchers/operator_matcher_example.rb +189 -0
- data/examples/lib/micronaut/matchers/raise_error_example.rb +346 -0
- data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
- data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
- data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
- data/examples/lib/micronaut/matchers/throw_symbol_example.rb +96 -0
- data/examples/lib/micronaut/runner_example.rb +5 -0
- data/examples/lib/micronaut/runner_options_example.rb +5 -0
- data/examples/lib/micronaut/world_example.rb +102 -0
- data/examples/lib/micronaut_example.rb +23 -0
- data/examples/resources/example_classes.rb +67 -0
- data/lib/autotest/discover.rb +3 -0
- data/lib/autotest/micronaut.rb +47 -0
- data/lib/micronaut/behaviour.rb +211 -0
- data/lib/micronaut/configuration.rb +133 -0
- data/lib/micronaut/example.rb +28 -0
- data/lib/micronaut/expectations/extensions/object.rb +62 -0
- data/lib/micronaut/expectations/extensions/string_and_symbol.rb +19 -0
- data/lib/micronaut/expectations/handler.rb +52 -0
- data/lib/micronaut/expectations/wrap_expectation.rb +57 -0
- data/lib/micronaut/expectations.rb +46 -0
- data/lib/micronaut/formatters/base_formatter.rb +82 -0
- data/lib/micronaut/formatters/base_text_formatter.rb +148 -0
- data/lib/micronaut/formatters/documentation_formatter.rb +62 -0
- data/lib/micronaut/formatters/progress_formatter.rb +36 -0
- data/lib/micronaut/formatters.rb +12 -0
- data/lib/micronaut/kernel_extensions.rb +11 -0
- data/lib/micronaut/matchers/be.rb +204 -0
- data/lib/micronaut/matchers/be_close.rb +22 -0
- data/lib/micronaut/matchers/change.rb +148 -0
- data/lib/micronaut/matchers/eql.rb +26 -0
- data/lib/micronaut/matchers/equal.rb +26 -0
- data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
- data/lib/micronaut/matchers/has.rb +19 -0
- data/lib/micronaut/matchers/have.rb +153 -0
- data/lib/micronaut/matchers/include.rb +80 -0
- data/lib/micronaut/matchers/match.rb +22 -0
- data/lib/micronaut/matchers/method_missing.rb +9 -0
- data/lib/micronaut/matchers/operator_matcher.rb +50 -0
- data/lib/micronaut/matchers/raise_error.rb +128 -0
- data/lib/micronaut/matchers/respond_to.rb +50 -0
- data/lib/micronaut/matchers/satisfy.rb +50 -0
- data/lib/micronaut/matchers/simple_matcher.rb +135 -0
- data/lib/micronaut/matchers/throw_symbol.rb +108 -0
- data/lib/micronaut/matchers.rb +148 -0
- data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
- data/lib/micronaut/mocking/with_mocha.rb +13 -0
- data/lib/micronaut/mocking/with_rr.rb +24 -0
- data/lib/micronaut/mocking.rb +7 -0
- data/lib/micronaut/runner.rb +57 -0
- data/lib/micronaut/runner_options.rb +33 -0
- data/lib/micronaut/world.rb +75 -0
- data/lib/micronaut.rb +37 -0
- metadata +149 -0
@@ -0,0 +1,360 @@
|
|
1
|
+
#Based on patch from Wilson Bilkovich
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
3
|
+
|
4
|
+
class SomethingExpected
|
5
|
+
attr_accessor :some_value
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Micronaut::Matchers do
|
9
|
+
|
10
|
+
describe "should change(actual, message)" do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@instance = SomethingExpected.new
|
14
|
+
@instance.some_value = 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should pass when actual is modified by the block" do
|
18
|
+
lambda {@instance.some_value = 6}.should change(@instance, :some_value)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should fail when actual is not modified by the block" do
|
22
|
+
lambda do
|
23
|
+
lambda {}.should change(@instance, :some_value)
|
24
|
+
end.should fail_with("some_value should have changed, but is still 5")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "should_not change(actual, message)" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@instance = SomethingExpected.new
|
33
|
+
@instance.some_value = 5
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should pass when actual is not modified by the block" do
|
37
|
+
lambda { }.should_not change(@instance, :some_value)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should fail when actual is not modified by the block" do
|
41
|
+
lambda do
|
42
|
+
lambda {@instance.some_value = 6}.should_not change(@instance, :some_value)
|
43
|
+
end.should fail_with("some_value should not have changed, but did change from 5 to 6")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "should change { block }" do
|
49
|
+
|
50
|
+
before do
|
51
|
+
@instance = SomethingExpected.new
|
52
|
+
@instance.some_value = 5
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should pass when actual is modified by the block" do
|
56
|
+
lambda {@instance.some_value = 6}.should change { @instance.some_value }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should fail when actual is not modified by the block" do
|
60
|
+
lambda do
|
61
|
+
lambda {}.should change{ @instance.some_value }
|
62
|
+
end.should fail_with("result should have changed, but is still 5")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should warn if passed a block using do/end instead of {}" do
|
66
|
+
lambda do
|
67
|
+
lambda {}.should change do; end
|
68
|
+
end.should raise_error(Micronaut::Matchers::MatcherError, /block passed to should or should_not/)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "should_not change { block }" do
|
74
|
+
|
75
|
+
before do
|
76
|
+
@instance = SomethingExpected.new
|
77
|
+
@instance.some_value = 5
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should pass when actual is modified by the block" do
|
81
|
+
lambda {}.should_not change{ @instance.some_value }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should fail when actual is not modified by the block" do
|
85
|
+
lambda do
|
86
|
+
lambda {@instance.some_value = 6}.should_not change { @instance.some_value }
|
87
|
+
end.should fail_with("result should not have changed, but did change from 5 to 6")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should warn if passed a block using do/end instead of {}" do
|
91
|
+
lambda do
|
92
|
+
lambda {}.should_not change do; end
|
93
|
+
end.should raise_error(Micronaut::Matchers::MatcherError, /block passed to should or should_not/)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "should change(actual, message).by(expected)" do
|
99
|
+
|
100
|
+
before do
|
101
|
+
@instance = SomethingExpected.new
|
102
|
+
@instance.some_value = 5
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should pass when attribute is changed by expected amount" do
|
106
|
+
lambda { @instance.some_value += 1 }.should change(@instance, :some_value).by(1)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should fail when the attribute is changed by unexpected amount" do
|
110
|
+
lambda do
|
111
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by(1)
|
112
|
+
end.should fail_with("some_value should have been changed by 1, but was changed by 2")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
|
116
|
+
lambda do
|
117
|
+
lambda { @instance.some_value -= 1 }.should change(@instance, :some_value).by(1)
|
118
|
+
end.should fail_with("some_value should have been changed by 1, but was changed by -1")
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "should change{ block }.by(expected)" do
|
124
|
+
|
125
|
+
before do
|
126
|
+
@instance = SomethingExpected.new
|
127
|
+
@instance.some_value = 5
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should pass when attribute is changed by expected amount" do
|
131
|
+
lambda { @instance.some_value += 1 }.should change{@instance.some_value}.by(1)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should fail when the attribute is changed by unexpected amount" do
|
135
|
+
lambda do
|
136
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by(1)
|
137
|
+
end.should fail_with("result should have been changed by 1, but was changed by 2")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
|
141
|
+
lambda do
|
142
|
+
lambda { @instance.some_value -= 1 }.should change{@instance.some_value}.by(1)
|
143
|
+
end.should fail_with("result should have been changed by 1, but was changed by -1")
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "should change(actual, message).by_at_least(expected)" do
|
149
|
+
|
150
|
+
before do
|
151
|
+
@instance = SomethingExpected.new
|
152
|
+
@instance.some_value = 5
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should pass when attribute is changed by greater than the expected amount" do
|
156
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by_at_least(1)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should pass when attribute is changed by the expected amount" do
|
160
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by_at_least(2)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should fail when the attribute is changed by less than the expected amount" do
|
164
|
+
lambda do
|
165
|
+
lambda { @instance.some_value += 1 }.should change(@instance, :some_value).by_at_least(2)
|
166
|
+
end.should fail_with("some_value should have been changed by at least 2, but was changed by 1")
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "should change{ block }.by_at_least(expected)" do
|
172
|
+
|
173
|
+
before do
|
174
|
+
@instance = SomethingExpected.new
|
175
|
+
@instance.some_value = 5
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should pass when attribute is changed by greater than expected amount" do
|
179
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by_at_least(1)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should pass when attribute is changed by the expected amount" do
|
183
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by_at_least(2)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should fail when the attribute is changed by less than the unexpected amount" do
|
187
|
+
lambda do
|
188
|
+
lambda { @instance.some_value += 1 }.should change{@instance.some_value}.by_at_least(2)
|
189
|
+
end.should fail_with("result should have been changed by at least 2, but was changed by 1")
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "should change(actual, message).by_at_most(expected)" do
|
195
|
+
|
196
|
+
before do
|
197
|
+
@instance = SomethingExpected.new
|
198
|
+
@instance.some_value = 5
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should pass when attribute is changed by less than the expected amount" do
|
202
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by_at_most(3)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should pass when attribute is changed by the expected amount" do
|
206
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by_at_most(2)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should fail when the attribute is changed by greater than the expected amount" do
|
210
|
+
lambda do
|
211
|
+
lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by_at_most(1)
|
212
|
+
end.should fail_with("some_value should have been changed by at most 1, but was changed by 2")
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "should change{ block }.by_at_most(expected)" do
|
218
|
+
|
219
|
+
before do
|
220
|
+
@instance = SomethingExpected.new
|
221
|
+
@instance.some_value = 5
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should pass when attribute is changed by less than expected amount" do
|
225
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by_at_most(3)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should pass when attribute is changed by the expected amount" do
|
229
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by_at_most(2)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should fail when the attribute is changed by greater than the unexpected amount" do
|
233
|
+
lambda do
|
234
|
+
lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by_at_most(1)
|
235
|
+
end.should fail_with("result should have been changed by at most 1, but was changed by 2")
|
236
|
+
end
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "should change(actual, message).from(old)" do
|
241
|
+
|
242
|
+
before do
|
243
|
+
@instance = SomethingExpected.new
|
244
|
+
@instance.some_value = 'string'
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should pass when attribute is == to expected value before executing block" do
|
248
|
+
lambda { @instance.some_value = "astring" }.should change(@instance, :some_value).from("string")
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should fail when attribute is not == to expected value before executing block" do
|
252
|
+
lambda do
|
253
|
+
lambda { @instance.some_value = "knot" }.should change(@instance, :some_value).from("cat")
|
254
|
+
end.should fail_with("some_value should have initially been \"cat\", but was \"string\"")
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "should change{ block }.from(old)" do
|
260
|
+
|
261
|
+
before do
|
262
|
+
@instance = SomethingExpected.new
|
263
|
+
@instance.some_value = 'string'
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should pass when attribute is == to expected value before executing block" do
|
267
|
+
lambda { @instance.some_value = "astring" }.should change{@instance.some_value}.from("string")
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should fail when attribute is not == to expected value before executing block" do
|
271
|
+
lambda do
|
272
|
+
lambda { @instance.some_value = "knot" }.should change{@instance.some_value}.from("cat")
|
273
|
+
end.should fail_with("result should have initially been \"cat\", but was \"string\"")
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
describe "should change(actual, message).to(new)" do
|
279
|
+
|
280
|
+
before do
|
281
|
+
@instance = SomethingExpected.new
|
282
|
+
@instance.some_value = 'string'
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should pass when attribute is == to expected value after executing block" do
|
286
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat")
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should fail when attribute is not == to expected value after executing block" do
|
290
|
+
lambda do
|
291
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("dog")
|
292
|
+
end.should fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "should change{ block }.to(new)" do
|
298
|
+
|
299
|
+
before do
|
300
|
+
@instance = SomethingExpected.new
|
301
|
+
@instance.some_value = 'string'
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should pass when attribute is == to expected value after executing block" do
|
305
|
+
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat")
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should fail when attribute is not == to expected value after executing block" do
|
309
|
+
lambda do
|
310
|
+
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("dog")
|
311
|
+
end.should fail_with("result should have been changed to \"dog\", but is now \"cat\"")
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "should change(actual, message).from(old).to(new)" do
|
317
|
+
|
318
|
+
before do
|
319
|
+
@instance = SomethingExpected.new
|
320
|
+
@instance.some_value = 'string'
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should pass when #to comes before #from" do
|
324
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat").from("string")
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should pass when #from comes before #to" do
|
328
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("cat")
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
describe "should change{ block }.from(old).to(new)" do
|
334
|
+
|
335
|
+
before do
|
336
|
+
@instance = SomethingExpected.new
|
337
|
+
@instance.some_value = 'string'
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should pass when #to comes before #from" do
|
341
|
+
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat").from("string")
|
342
|
+
end
|
343
|
+
|
344
|
+
it "should pass when #from comes before #to" do
|
345
|
+
lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("cat")
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should work when the receiver has implemented #send" do
|
351
|
+
@instance = SomethingExpected.new
|
352
|
+
@instance.some_value = "string"
|
353
|
+
def @instance.send(*args); raise "DOH! Library developers shouldn't use #send!" end
|
354
|
+
|
355
|
+
lambda do
|
356
|
+
lambda { @instance.some_value = "cat" }.should change(@instance, :some_value)
|
357
|
+
end.should_not raise_error
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::Matchers do
|
4
|
+
|
5
|
+
describe "should be able to generate their own descriptions" do
|
6
|
+
|
7
|
+
after do
|
8
|
+
Micronaut::Matchers.clear_generated_description
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should == expected" do
|
12
|
+
"this".should == "this"
|
13
|
+
Micronaut::Matchers.generated_description.should == "should == \"this\""
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not == expected" do
|
17
|
+
"this".should_not == "that"
|
18
|
+
Micronaut::Matchers.generated_description.should == "should not == \"that\""
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be empty (arbitrary predicate)" do
|
22
|
+
[].should be_empty
|
23
|
+
Micronaut::Matchers.generated_description.should == "should be empty"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should not be empty (arbitrary predicate)" do
|
27
|
+
[1].should_not be_empty
|
28
|
+
Micronaut::Matchers.generated_description.should == "should not be empty"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be true" do
|
32
|
+
true.should be_true
|
33
|
+
Micronaut::Matchers.generated_description.should == "should be true"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be false" do
|
37
|
+
false.should be_false
|
38
|
+
Micronaut::Matchers.generated_description.should == "should be false"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be nil" do
|
42
|
+
nil.should be_nil
|
43
|
+
Micronaut::Matchers.generated_description.should == "should be nil"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should be > n" do
|
47
|
+
5.should be > 3
|
48
|
+
Micronaut::Matchers.generated_description.should == "should be > 3"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be predicate arg1, arg2 and arg3" do
|
52
|
+
5.0.should be_between(0,10)
|
53
|
+
Micronaut::Matchers.generated_description.should == "should be between 0 and 10"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be_few_words predicate should be transformed to 'be few words'" do
|
57
|
+
5.should be_kind_of(Fixnum)
|
58
|
+
Micronaut::Matchers.generated_description.should == "should be kind of Fixnum"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should preserve a proper prefix for be predicate" do
|
62
|
+
5.should be_a_kind_of(Fixnum)
|
63
|
+
Micronaut::Matchers.generated_description.should == "should be a kind of Fixnum"
|
64
|
+
5.should be_an_instance_of(Fixnum)
|
65
|
+
Micronaut::Matchers.generated_description.should == "should be an instance of Fixnum"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should equal" do
|
69
|
+
expected = "expected"
|
70
|
+
expected.should equal(expected)
|
71
|
+
Micronaut::Matchers.generated_description.should == "should equal \"expected\""
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should_not equal" do
|
75
|
+
5.should_not equal(37)
|
76
|
+
Micronaut::Matchers.generated_description.should == "should not equal 37"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should eql" do
|
80
|
+
"string".should eql("string")
|
81
|
+
Micronaut::Matchers.generated_description.should == "should eql \"string\""
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should not eql" do
|
85
|
+
"a".should_not eql(:a)
|
86
|
+
Micronaut::Matchers.generated_description.should == "should not eql :a"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have_key" do
|
90
|
+
{:a => "a"}.should have_key(:a)
|
91
|
+
Micronaut::Matchers.generated_description.should == "should have key :a"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have n items" do
|
95
|
+
team.should have(3).players
|
96
|
+
Micronaut::Matchers.generated_description.should == "should have 3 players"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should have at least n items" do
|
100
|
+
team.should have_at_least(2).players
|
101
|
+
Micronaut::Matchers.generated_description.should == "should have at least 2 players"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have at most n items" do
|
105
|
+
team.should have_at_most(4).players
|
106
|
+
Micronaut::Matchers.generated_description.should == "should have at most 4 players"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should include" do
|
110
|
+
[1,2,3].should include(3)
|
111
|
+
Micronaut::Matchers.generated_description.should == "should include 3"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should match" do
|
115
|
+
"this string".should match(/this string/)
|
116
|
+
Micronaut::Matchers.generated_description.should == "should match /this string/"
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise_error" do
|
120
|
+
lambda { raise }.should raise_error
|
121
|
+
Micronaut::Matchers.generated_description.should == "should raise Exception"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should raise_error with type" do
|
125
|
+
lambda { raise }.should raise_error(RuntimeError)
|
126
|
+
Micronaut::Matchers.generated_description.should == "should raise RuntimeError"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should raise_error with type and message" do
|
130
|
+
lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
|
131
|
+
Micronaut::Matchers.generated_description.should == "should raise RuntimeError with \"there was an error\""
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should respond_to" do
|
135
|
+
[].should respond_to(:insert)
|
136
|
+
Micronaut::Matchers.generated_description.should == "should respond to [:insert]"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should throw symbol" do
|
140
|
+
lambda { throw :what_a_mess }.should throw_symbol
|
141
|
+
Micronaut::Matchers.generated_description.should == "should throw a Symbol"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should throw symbol (with named symbol)" do
|
145
|
+
lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
|
146
|
+
Micronaut::Matchers.generated_description.should == "should throw :what_a_mess"
|
147
|
+
end
|
148
|
+
|
149
|
+
def team
|
150
|
+
Class.new do
|
151
|
+
def players
|
152
|
+
[1,2,3]
|
153
|
+
end
|
154
|
+
end.new
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "a matcher with no description" do
|
160
|
+
|
161
|
+
def matcher
|
162
|
+
Class.new do
|
163
|
+
def matches?(ignore); true; end
|
164
|
+
def failure_message; ""; end
|
165
|
+
end.new
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should provide a helpful message when used in a string-less example block" do
|
169
|
+
5.should matcher
|
170
|
+
Micronaut::Matchers.generated_description.should =~ /When you call.*description method/m
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::Matchers do
|
4
|
+
|
5
|
+
describe "eql" do
|
6
|
+
|
7
|
+
it "should match when actual.eql?(expected)" do
|
8
|
+
eql(1).matches?(1).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not match when !actual.eql?(expected)" do
|
12
|
+
eql(1).matches?(2).should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should describe itself" do
|
16
|
+
matcher = eql(1)
|
17
|
+
matcher.matches?(1)
|
18
|
+
matcher.description.should == "eql 1"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should provide message, expected and actual on #failure_message" do
|
22
|
+
matcher = eql("1")
|
23
|
+
matcher.matches?(1)
|
24
|
+
matcher.failure_message.should == ["expected \"1\", got 1 (using .eql?)", "1", 1]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should provide message, expected and actual on #negative_failure_message" do
|
28
|
+
matcher = eql(1)
|
29
|
+
matcher.matches?(1)
|
30
|
+
matcher.negative_failure_message.should == ["expected 1 not to equal 1 (using .eql?)", 1, 1]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
|
2
|
+
|
3
|
+
describe Micronaut::Matchers do
|
4
|
+
|
5
|
+
describe "equal" do
|
6
|
+
|
7
|
+
it "should match when actual.equal?(expected)" do
|
8
|
+
equal(1).matches?(1).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not match when !actual.equal?(expected)" do
|
12
|
+
equal("1").matches?("1").should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should describe itself" do
|
16
|
+
matcher = equal(1)
|
17
|
+
matcher.matches?(1)
|
18
|
+
matcher.description.should == "equal 1"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should provide message, expected and actual on #failure_message" do
|
22
|
+
matcher = equal("1")
|
23
|
+
matcher.matches?(1)
|
24
|
+
matcher.failure_message.should == ["expected \"1\", got 1 (using .equal?)", "1", 1]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should provide message, expected and actual on #negative_failure_message" do
|
28
|
+
matcher = equal(1)
|
29
|
+
matcher.matches?(1)
|
30
|
+
matcher.negative_failure_message.should == ["expected 1 not to equal 1 (using .equal?)", 1, 1]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|