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