MacSpec 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +20 -0
  5. data/Rakefile +53 -0
  6. data/lib/mac_spec.rb +59 -0
  7. data/lib/mac_spec/matcher_system.rb +19 -0
  8. data/lib/mac_spec/matcher_system/built_in/change_expectations.rb +36 -0
  9. data/lib/mac_spec/matcher_system/built_in/enumerable_expectations.rb +43 -0
  10. data/lib/mac_spec/matcher_system/built_in/error_expectations.rb +68 -0
  11. data/lib/mac_spec/matcher_system/built_in/operator_expectations.rb +45 -0
  12. data/lib/mac_spec/matcher_system/built_in/truth_expectations.rb +148 -0
  13. data/lib/mac_spec/matcher_system/core/def_matcher.rb +14 -0
  14. data/lib/mac_spec/matcher_system/core/exceptions.rb +7 -0
  15. data/lib/mac_spec/matcher_system/core/expectation_builder.rb +11 -0
  16. data/lib/mac_spec/matcher_system/core/matcher_builder.rb +53 -0
  17. data/lib/mac_spec/matcher_system/core/modals.rb +36 -0
  18. data/lib/mac_spec/mocking_framework.rb +13 -0
  19. data/lib/mac_spec/mocking_framework/extensions/kernel_extension.rb +14 -0
  20. data/lib/mac_spec/mocking_framework/extensions/object_extension.rb +74 -0
  21. data/lib/mac_spec/mocking_framework/message_expectation.rb +127 -0
  22. data/lib/mac_spec/mocking_framework/mock.rb +20 -0
  23. data/lib/mac_spec/testing_framework.rb +13 -0
  24. data/lib/mac_spec/testing_framework/core/functions.rb +26 -0
  25. data/lib/mac_spec/testing_framework/core/kernel_extension.rb +27 -0
  26. data/lib/mac_spec/testing_framework/core/test_case_class_methods.rb +90 -0
  27. data/lib/mac_spec/version.rb +3 -0
  28. data/test/all.rb +6 -0
  29. data/test/mac_spec/matcher_system/built_in/change_expectations_test.rb +68 -0
  30. data/test/mac_spec/matcher_system/built_in/enumerable_expectations_test.rb +91 -0
  31. data/test/mac_spec/matcher_system/built_in/error_expectations_test.rb +144 -0
  32. data/test/mac_spec/matcher_system/built_in/operator_expectations_test.rb +136 -0
  33. data/test/mac_spec/matcher_system/built_in/truth_expectations_test.rb +373 -0
  34. data/test/mac_spec/matcher_system/core/def_matcher_test.rb +100 -0
  35. data/test/mac_spec/matcher_system/core/expectation_builder_test.rb +34 -0
  36. data/test/mac_spec/matcher_system/core/matcher_builder_test.rb +72 -0
  37. data/test/mac_spec/matcher_system/core/modals_test.rb +39 -0
  38. data/test/mac_spec/matcher_system/script.rb +29 -0
  39. data/test/mac_spec/matcher_system/test_helper.rb +2 -0
  40. data/test/mac_spec/mocking_framework/extensions/kernel_extension_test.rb +37 -0
  41. data/test/mac_spec/mocking_framework/extensions/object_extension_test.rb +9 -0
  42. data/test/mac_spec/mocking_framework/message_expectation_test.rb +9 -0
  43. data/test/mac_spec/mocking_framework/mock_test.rb +9 -0
  44. data/test/mac_spec/mocking_framework/regression/mocking_class_methods_test.rb +96 -0
  45. data/test/mac_spec/mocking_framework/regression/negative_expectation_test.rb +33 -0
  46. data/test/mac_spec/mocking_framework/regression/stub_test.rb +19 -0
  47. data/test/mac_spec/mocking_framework/test_helper.rb +1 -0
  48. data/test/mac_spec/test_helper.rb +1 -0
  49. data/test/mac_spec/testing_framework/performance/x_test_performance.rb +125 -0
  50. data/test/mac_spec/testing_framework/regression/before_test.rb +32 -0
  51. data/test/mac_spec/testing_framework/regression/deep_nested_example_groups_test.rb +20 -0
  52. data/test/mac_spec/testing_framework/regression/description_string_test.rb +13 -0
  53. data/test/mac_spec/testing_framework/regression/example_name_test.rb +11 -0
  54. data/test/mac_spec/testing_framework/regression/inherit_not_double_test.rb +39 -0
  55. data/test/mac_spec/testing_framework/regression/surrounding_module_scope_test.rb +31 -0
  56. data/test/mac_spec/testing_framework/regression/testing_functions_test.rb +66 -0
  57. data/test/mac_spec/testing_framework/test_helper.rb +1 -0
  58. data/test/test_helper.rb +1 -0
  59. metadata +150 -0
@@ -0,0 +1,373 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class Exister
4
+ def initialize(what)
5
+ @what = what
6
+ end
7
+
8
+ def exist?
9
+ @what
10
+ end
11
+ end
12
+
13
+ describe "Truth Expectations" do
14
+
15
+ before do
16
+ @obj = Object.new
17
+ end
18
+
19
+ it "equal" do
20
+ 3.should equal(3)
21
+ end
22
+
23
+ it "negative equal" do
24
+ instance = String.new
25
+
26
+ instance.should_not equal(String.new)
27
+ end
28
+
29
+ it "equal fail" do
30
+ lambda {
31
+ 3.should equal(4)
32
+ }.should raise_error(MacSpec.assertion_failed_error)
33
+ end
34
+
35
+ it "negative equal fail" do
36
+ lambda {
37
+ 3.should_not equal(3)
38
+ }.should raise_error(MacSpec.assertion_failed_error)
39
+ end
40
+
41
+ it "eql" do
42
+ 3.should eql(3)
43
+ end
44
+
45
+ it "eql array" do
46
+ [1,2,3].should eql([1,2,3])
47
+ end
48
+
49
+ it "negative eql" do
50
+ 3.should_not eql(9)
51
+ end
52
+
53
+ it "eql fail" do
54
+ lambda {
55
+ 3.should eql(13)
56
+ }.should raise_error(MacSpec.assertion_failed_error)
57
+ end
58
+
59
+ it "negative eql fail" do
60
+ lambda {
61
+ 3.should_not eql(3)
62
+ }.should raise_error(MacSpec.assertion_failed_error)
63
+ end
64
+
65
+ it "exists" do
66
+ thing = Exister.new(true)
67
+ thing.should exist
68
+ end
69
+
70
+ it "negative exists" do
71
+ thing = Exister.new(false)
72
+ thing.should_not exist
73
+ end
74
+
75
+ it "exists fail" do
76
+ lambda {
77
+ thing = Exister.new(false)
78
+ thing.should exist
79
+ }.should raise_error(MacSpec.assertion_failed_error)
80
+ end
81
+
82
+ it "negative exists fail" do
83
+ lambda {
84
+ thing = Exister.new(true)
85
+ thing.should_not exist
86
+ }.should raise_error(MacSpec.assertion_failed_error)
87
+ end
88
+
89
+ it "be" do
90
+ true.should be(true)
91
+ end
92
+
93
+ it "be array" do
94
+ [1,2,3].should be([1,2,3])
95
+ end
96
+
97
+ it "negative be" do
98
+ true.should_not be(false)
99
+ end
100
+
101
+ it "be fail" do
102
+ lambda {
103
+ true.should be(false)
104
+ }.should raise_error(MacSpec.assertion_failed_error)
105
+ end
106
+
107
+ it "be close" do
108
+ (5.0 - 2.0).should be_close(3.0)
109
+ end
110
+
111
+ it "be close with delta" do
112
+ (5.0 - 2.0).should be_close(3.0, 0.2)
113
+ end
114
+
115
+ it "be close fail" do
116
+ lambda {
117
+ (19.0 - 13.0).should be_close(33.04)
118
+ }.should raise_error(MacSpec.assertion_failed_error)
119
+ end
120
+
121
+ it "be close with delta fail" do
122
+ lambda {
123
+ (19.0 - 13.0).should be_close(6.0, 0.0)
124
+ }.should raise_error(MacSpec.assertion_failed_error)
125
+ end
126
+
127
+ it "satisfy" do
128
+ 13.should satisfy(lambda {|i| i < 15})
129
+ end
130
+
131
+ it "negative satisfy" do
132
+ 13.should_not satisfy(lambda {|i| i < 10})
133
+ end
134
+
135
+ it "satisfy fail" do
136
+ lambda {
137
+ 13.should satisfy(lambda {|i| i > 15})
138
+ }.should raise_error(MacSpec.assertion_failed_error)
139
+ end
140
+
141
+ it "negative satisfy fail" do
142
+ lambda {
143
+ 13.should_not satisfy(lambda {|i| i < 15})
144
+ }.should raise_error(MacSpec.assertion_failed_error)
145
+ end
146
+
147
+ it "equal fail message" do
148
+ obj = equal(4)
149
+ obj.matches?(5)
150
+
151
+ obj.failure_message.should be("Expected 5 to return true for equal?, with '4'.")
152
+ end
153
+
154
+ it "equal negative fail message" do
155
+ obj = equal(5)
156
+ obj.matches?(5)
157
+
158
+ obj.negative_failure_message.should be("Expected 5 to not return true for equal?, with '5'.")
159
+ end
160
+
161
+ it "eql fail message" do
162
+ obj = eql(4)
163
+ obj.matches?(5)
164
+
165
+ obj.failure_message.should be("Expected 5 to return true for eql?, with '4'.")
166
+ end
167
+
168
+ it "eql negative fail message for eql" do
169
+ obj = eql(5)
170
+ obj.matches?(5)
171
+
172
+ obj.negative_failure_message.should be("Expected 5 to not return true for eql?, with '5'.")
173
+ end
174
+
175
+ it "exist fail message" do
176
+ obj = exist
177
+ obj.matches?(Exister.new(false))
178
+
179
+ obj.failure_message.should =~ /Expected .* to return true for exist?/
180
+ end
181
+
182
+ it "exist negative fail message" do
183
+ obj = exist
184
+ obj.matches?(Exister.new(true))
185
+
186
+ obj.negative_failure_message.should =~ /Expected .* to not return true for exist?/
187
+ end
188
+
189
+ it "be close fail message" do
190
+ obj = be_close(3.0)
191
+ obj.matches?(6.0)
192
+
193
+ obj.failure_message.should be("Expected 6.0 to be close to 3.0 (delta: 0.3).")
194
+ end
195
+
196
+ it "be close negative fail message" do
197
+ obj = be_close(5.0)
198
+ obj.matches?(5.0)
199
+
200
+ obj.negative_failure_message.should be("Expected 5.0 to not be close to 5.0 (delta: 0.3).")
201
+ end
202
+
203
+ it "be fail message" do
204
+ obj = be(4)
205
+ obj.matches?(5)
206
+
207
+ obj.failure_message.should be("Expected 5 to be 4.")
208
+ end
209
+
210
+ it "be negative fail message" do
211
+ obj = be(5)
212
+ obj.matches?(5)
213
+
214
+ obj.negative_failure_message.should be("Expected 5 to not be 5.")
215
+ end
216
+
217
+ it "satisfy fail message" do
218
+ obj = satisfy(lambda {|x| x == 4})
219
+ obj.matches?(6)
220
+
221
+ obj.failure_message.should be("Expected 6 to satisfy given block.")
222
+ end
223
+
224
+ it "eql negative fail message for matches" do
225
+ obj = satisfy(lambda {|x| x == 4})
226
+ obj.matches?(4)
227
+
228
+ obj.negative_failure_message.should be("Expected 4 to not satisfy given block.")
229
+ end
230
+
231
+ it "kind of" do
232
+ 3.should be_kind_of(Fixnum)
233
+ end
234
+
235
+ it "kind of fail" do
236
+ lambda {
237
+ 3.should be_kind_of(Hash)
238
+ }.should raise_error(MacSpec.assertion_failed_error)
239
+ end
240
+
241
+ it "negative kind of" do
242
+ 3.should_not be_kind_of(Hash)
243
+ end
244
+
245
+ it "negative kind of fail" do
246
+ lambda {
247
+ 3.should_not be_kind_of(Fixnum)
248
+ }.should raise_error(MacSpec.assertion_failed_error)
249
+ end
250
+
251
+ it "respond to" do
252
+ "foo".should respond_to(:length)
253
+ end
254
+
255
+ it "respond to fail" do
256
+ lambda {
257
+ "foo".should respond_to(:nonexistant_method)
258
+ }.should raise_error(MacSpec.assertion_failed_error)
259
+ end
260
+
261
+ it "negative respond to" do
262
+ "foo".should_not respond_to(:nonexistant_method)
263
+ end
264
+
265
+ it "negative respond to fail" do
266
+ lambda {
267
+ "foo".should_not respond_to(:length)
268
+ }.should raise_error(MacSpec.assertion_failed_error)
269
+ end
270
+
271
+ # be_something
272
+ it "positive be something method missing pass" do
273
+ def @obj.something?
274
+ true
275
+ end
276
+ @obj.should be_something
277
+ end
278
+
279
+ it "positive be something method missing fails" do
280
+ def @obj.something?
281
+ false
282
+ end
283
+ lambda {@obj.should be_something}.should raise_error(MacSpec.assertion_failed_error)
284
+ end
285
+
286
+ it "negative be something method missing pass" do
287
+ def @obj.something?
288
+ false
289
+ end
290
+ @obj.should_not be_something
291
+ end
292
+
293
+ it "negative be something method missing fails" do
294
+ def @obj.something?
295
+ true
296
+ end
297
+ lambda {@obj.should_not be_something}.should raise_error(MacSpec.assertion_failed_error)
298
+ end
299
+
300
+ it "be something method missing fail message" do
301
+ obj = "foo"
302
+ def obj.something?
303
+ true
304
+ end
305
+ matcher_obj = be_something
306
+ obj.should matcher_obj
307
+
308
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with 'no args'.")
309
+ end
310
+
311
+ it "be something method missing negative fail message" do
312
+ obj = "foo"
313
+ def obj.something?
314
+ false
315
+ end
316
+ matcher_obj = be_something
317
+ obj.should_not matcher_obj
318
+
319
+ matcher_obj.negative_failure_message.should =~ /Expected \"foo\" to not return true for something?/
320
+ end
321
+
322
+ # be_something(arg)
323
+ it "positive be something with arg method missing pass" do
324
+ def @obj.something?(arg)
325
+ true
326
+ end
327
+ @obj.should be_something(1)
328
+ end
329
+
330
+ it "positive be something with arg method missing fails" do
331
+ def @obj.something?(arg)
332
+ false
333
+ end
334
+ lambda {@obj.should be_something(1)}.should raise_error(MacSpec.assertion_failed_error)
335
+ end
336
+
337
+ it "negative be something method missing pass" do
338
+ def @obj.something?(arg)
339
+ false
340
+ end
341
+ @obj.should_not be_something(1)
342
+ end
343
+
344
+ it "negative be something method missing fails" do
345
+ def @obj.something?(arg)
346
+ true
347
+ end
348
+ lambda {@obj.should_not be_something(1)}.should raise_error(MacSpec.assertion_failed_error)
349
+ end
350
+
351
+ it "be something method missing fail message" do
352
+ obj = "foo"
353
+ def obj.something?(arg)
354
+ true
355
+ end
356
+ matcher_obj = be_something(1)
357
+ obj.should matcher_obj
358
+
359
+ matcher_obj.failure_message.should be("Expected \"foo\" to return true for something?, with '1'.")
360
+ end
361
+
362
+ it "be something method missing negative fail message" do
363
+ obj = "foo"
364
+ def obj.something?(arg)
365
+ false
366
+ end
367
+ matcher_obj = be_something(1)
368
+ obj.should_not matcher_obj
369
+
370
+ matcher_obj.negative_failure_message.should be("Expected \"foo\" to not return true for something?, with '1'.")
371
+ end
372
+
373
+ end
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ describe "def_matcher" do
4
+
5
+ before do
6
+ @obj = Object.new
7
+ end
8
+
9
+ it "defines method" do
10
+ def_matcher :method_ do |given, matcher, args|
11
+ end
12
+ self.should respond_to(:method_)
13
+ end
14
+
15
+ it "object responds to matches" do
16
+ def_matcher :method_ do |given, matcher, args|
17
+ end
18
+ method_.should respond_to(:matches?)
19
+ end
20
+
21
+ it "fail positive" do
22
+ def_matcher :matcher do |given, matcher, args|
23
+ false
24
+ end
25
+ lambda {1.should matcher}.should raise_error
26
+ end
27
+
28
+ it "pass positive" do
29
+ def_matcher :matcher do |given, matcher, args|
30
+ true
31
+ end
32
+ 1.should matcher
33
+ end
34
+
35
+ it "fail negative" do
36
+ def_matcher :matcher do |given, matcher, args|
37
+ true
38
+ end
39
+ lambda {1.should_not matcher}.should raise_error
40
+ end
41
+
42
+ it "pass negative" do
43
+ def_matcher :matcher do |given, matcher, args|
44
+ false
45
+ end
46
+ 1.should_not matcher
47
+ end
48
+
49
+ it "takes arguments" do
50
+ def_matcher :matcher do |given, matcher, args|
51
+ $args = args
52
+ true
53
+ end
54
+ @obj.should matcher(1,2,3)
55
+ $args.should eql([1,2,3])
56
+ end
57
+
58
+ it "received method" do
59
+ def_matcher :matcher do |given, matcher, args|
60
+ $msgs = matcher.msgs
61
+ true
62
+ end
63
+ @obj.should matcher.method1
64
+ $msgs[0].name.should eql(:method1)
65
+ end
66
+
67
+ it "received method takes args" do
68
+ def_matcher :matcher do |given, matcher, args|
69
+ $msgs = matcher.msgs
70
+ true
71
+ end
72
+ @obj.should matcher.method1(1,2,3)
73
+ $msgs[0].args.should eql([1,2,3])
74
+ end
75
+
76
+ it "received method takes block" do
77
+ def_matcher :matcher do |given, matcher, args|
78
+ $msgs = matcher.msgs
79
+ true
80
+ end
81
+ @obj.should matcher.method1 { "Hello, World!"}
82
+ $msgs[0].block.call.should eql("Hello, World!")
83
+ end
84
+
85
+ it "received method chained" do
86
+ def_matcher :matcher do |given, matcher, args|
87
+ $msgs = matcher.msgs
88
+ true
89
+ end
90
+ @obj.should matcher.method1(1,2,3) { "Hello, World!"}.
91
+ method2(4,5,6) { "Hello chained messages" }
92
+
93
+ $msgs[0].name.should eql(:method1)
94
+ $msgs[1].name.should eql(:method2)
95
+ $msgs[0].args.should eql([1,2,3])
96
+ $msgs[1].args.should eql([4,5,6])
97
+ $msgs[0].block.call.should eql("Hello, World!")
98
+ $msgs[1].block.call.should eql("Hello chained messages")
99
+ end
100
+ end