muack 1.2.0 → 1.5.0

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.
@@ -53,6 +53,21 @@ describe Muack::Mock do
53
53
  Obj.aloha.should.eq [0, 1]
54
54
  end
55
55
 
56
+ would 'proxy and call the original method for keyargs' do
57
+ mock(Obj).bonjour(a: :b, b: :a)
58
+ mock(Obj).bonjour
59
+ Obj.bonjour(a: :b, b: :a).should.eq %i[b a]
60
+ Obj.bonjour.should.eq [0, 1]
61
+ end
62
+
63
+ would 'proxy and call the original method for fake keyargs' do
64
+ args = {a: :b, b: :a}
65
+ mock(Obj).ciao(args)
66
+ mock(Obj).ciao
67
+ Obj.ciao(args).should.eq %i[b a]
68
+ Obj.ciao.should.eq [0, 1]
69
+ end
70
+
56
71
  would 'proxy and call the block with super' do
57
72
  mock(Str).class.peek_return{ |k| k.name.reverse }
58
73
  Str.class.should.eq 'gnirtS'
@@ -60,9 +75,9 @@ describe Muack::Mock do
60
75
 
61
76
  would 'mock proxy and call, mock proxy and call' do
62
77
  mock(Obj).class.peek_return{ |k| k.name.reverse }
63
- Obj.class.should.eq 'tcejbO'
78
+ Obj.class.should.eq 'slC'
64
79
  mock(Obj).class.peek_return{ |k| k.name.upcase }
65
- Obj.class.should.eq 'OBJECT'
80
+ Obj.class.should.eq 'CLS'
66
81
  end
67
82
 
68
83
  would 'stub proxy and call, stub proxy and call' do
@@ -74,12 +89,12 @@ describe Muack::Mock do
74
89
 
75
90
  would 'stub proxy with any times' do
76
91
  stub(Obj).class.peek_return{ |k| k.name.downcase }
77
- 3.times{ Obj.class.should.eq 'object' }
92
+ 3.times{ Obj.class.should.eq 'cls' }
78
93
  end
79
94
 
80
95
  would 'stub proxy and spy' do
81
96
  stub(Obj).class.peek_return{ |k| k.name.downcase }
82
- Obj.class.should.eq 'object'
97
+ Obj.class.should.eq 'cls'
83
98
  spy(Obj).class
84
99
  end
85
100
  end
@@ -1,35 +1,12 @@
1
1
 
2
2
  require 'muack/test'
3
3
 
4
- describe Muack::Satisfy do
4
+ describe Muack::Satisfying do
5
5
  after do
6
6
  Muack.reset
7
7
  Muack::EnsureReset.call
8
8
  end
9
9
 
10
- describe Muack::IsA do
11
- would 'have human readable to_s and inspect' do
12
- matcher = is_a(String)
13
- expected = 'Muack::API.is_a(String)'
14
- matcher.to_s .should.eq expected
15
- matcher.inspect.should.eq expected
16
- end
17
-
18
- would 'satisfy' do
19
- mock(Str).say(is_a(String)){ |arg| arg.reverse }
20
- Str.say('Foo').should.eq 'ooF'
21
- Muack.verify.should.eq true
22
- end
23
-
24
- would 'raise Unexpected error if passing unexpected argument' do
25
- mock(Obj).say(is_a(Array)){ 'boo' }
26
- e = should.raise(Muack::Unexpected){ Obj.say(false) }
27
- e.expected.should.eq 'obj.say(Muack::API.is_a(Array))'
28
- e.was .should.eq 'obj.say(false)'
29
- e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
30
- end
31
- end
32
-
33
10
  describe Muack::Anything do
34
11
  would 'have human readable to_s and inspect' do
35
12
  matcher = anything
@@ -58,63 +35,48 @@ describe Muack::Satisfy do
58
35
  end
59
36
  end
60
37
 
61
- describe Muack::Match do
38
+ describe Muack::IsA do
62
39
  would 'have human readable to_s and inspect' do
63
- matcher = match(/\w/)
64
- expected = 'Muack::API.match(/\w/)'
40
+ matcher = is_a(String)
41
+ expected = 'Muack::API.is_a(String)'
65
42
  matcher.to_s .should.eq expected
66
43
  matcher.inspect.should.eq expected
67
44
  end
68
45
 
69
46
  would 'satisfy' do
70
- mock(Str).say(match(/\w/)){ |arg| arg }
71
- Str.say('aa').should.eq 'aa'
47
+ mock(Str).say(is_a(String)){ |arg| arg.reverse }
48
+ Str.say('Foo').should.eq 'ooF'
72
49
  Muack.verify.should.eq true
73
50
  end
74
51
 
75
52
  would 'raise Unexpected error if passing unexpected argument' do
76
- mock(Obj).say(match(/\w/)){ 'boo' }
77
- e = should.raise(Muack::Unexpected){ Obj.say('!') }
78
- e.expected.should.eq 'obj.say(Muack::API.match(/\w/))'
79
- e.was .should.eq 'obj.say("!")'
53
+ mock(Obj).say(is_a(Array)){ 'boo' }
54
+ e = should.raise(Muack::Unexpected){ Obj.say(false) }
55
+ e.expected.should.eq 'obj.say(Muack::API.is_a(Array))'
56
+ e.was .should.eq 'obj.say(false)'
80
57
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
81
58
  end
82
59
  end
83
60
 
84
- describe Muack::HashIncluding do
61
+ describe Muack::Matching do
85
62
  would 'have human readable to_s and inspect' do
86
- matcher = hash_including(:b => 2)
87
- expected = 'Muack::API.hash_including({:b=>2})'
63
+ matcher = matching(/\w/)
64
+ expected = 'Muack::API.matching(/\w/)'
88
65
  matcher.to_s .should.eq expected
89
66
  matcher.inspect.should.eq expected
90
67
  end
91
68
 
92
69
  would 'satisfy' do
93
- mock(Str).say(hash_including(:b => 2)){ |arg| arg[:a] }
94
- Str.say(:a => 1, :b => 2).should.eq 1
95
- Muack.verify.should.eq true
96
- end
97
-
98
- would 'satisfy with satisfy' do
99
- mock(Str).say(hash_including(:b => is_a(Fixnum))){ |arg| arg[:b] }
100
- Str.say(:a => 1, :b => 2).should.eq 2
70
+ mock(Str).say(matching(/\w/)){ |arg| arg }
71
+ Str.say('aa').should.eq 'aa'
101
72
  Muack.verify.should.eq true
102
73
  end
103
74
 
104
75
  would 'raise Unexpected error if passing unexpected argument' do
105
- mock(Obj).say(hash_including(:b => 2)){ 'boo' }
106
- e = should.raise(Muack::Unexpected){ Obj.say(:a => 1) }
107
- e.expected.should.eq 'obj.say(Muack::API.hash_including({:b=>2}))'
108
- e.was .should.eq 'obj.say({:a=>1})'
109
- e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
110
- end
111
-
112
- would 'raise Unexpected error if passing unsatisfied argument' do
113
- mock(Obj).say(hash_including(:b => is_a(String))){ 'boo' }
114
- e = should.raise(Muack::Unexpected){ Obj.say(:b => 1) }
115
- e.expected.should.eq \
116
- 'obj.say(Muack::API.hash_including({:b=>Muack::API.is_a(String)}))'
117
- e.was .should.eq 'obj.say({:b=>1})'
76
+ mock(Obj).say(matching(/\w/)){ 'boo' }
77
+ e = should.raise(Muack::Unexpected){ Obj.say('!') }
78
+ e.expected.should.eq 'obj.say(Muack::API.matching(/\w/))'
79
+ e.was .should.eq 'obj.say("!")'
118
80
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
119
81
  end
120
82
  end
@@ -169,68 +131,241 @@ describe Muack::Satisfy do
169
131
  end
170
132
  end
171
133
 
172
- describe Muack::RespondTo do
134
+ describe Muack::RespondingTo do
173
135
  would 'have human readable to_s and inspect' do
174
- matcher = respond_to(:id)
175
- expected = 'Muack::API.respond_to(:id)'
136
+ matcher = responding_to(:id)
137
+ expected = 'Muack::API.responding_to(:id)'
176
138
  matcher.to_s .should.start_with? expected
177
139
  matcher.inspect.should.start_with? expected
178
140
 
179
- matcher = respond_to(:id, :reload)
180
- expected = 'Muack::API.respond_to(:id, :reload)'
141
+ matcher = responding_to(:id, :reload)
142
+ expected = 'Muack::API.responding_to(:id, :reload)'
181
143
  matcher.to_s .should.start_with? expected
182
144
  matcher.inspect.should.start_with? expected
183
145
  end
184
146
 
185
147
  would 'satisfy' do
186
- mock(Str).say(respond_to(:verify, :reset)){ |arg| arg.name }
148
+ mock(Str).say(responding_to(:verify, :reset)){ |arg| arg.name }
187
149
  Str.say(Muack).should.eq 'Muack'
188
150
  Muack.verify.should.eq true
189
151
 
190
- mock(Str).say(respond_to(:verify )){ |arg| arg.name }
152
+ mock(Str).say(responding_to(:verify )){ |arg| arg.name }
191
153
  Str.say(Muack).should.eq 'Muack'
192
154
  Muack.verify.should.eq true
193
155
  end
194
156
 
195
157
  would 'raise Unexpected error if passing unexpected argument' do
196
- mock(Obj).say(respond_to(:nothing)){ 'boo' }
158
+ mock(Obj).say(responding_to(:nothing)){ 'boo' }
197
159
  e = should.raise(Muack::Unexpected){ Obj.say(0) }
198
- e.expected.should.eq 'obj.say(Muack::API.respond_to(:nothing))'
160
+ e.expected.should.eq 'obj.say(Muack::API.responding_to(:nothing))'
199
161
  e.was .should.eq 'obj.say(0)'
200
162
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
201
163
  end
202
164
  end
203
165
 
204
- describe Muack::Satisfy do
166
+ describe Muack::Where do
167
+ would 'have human readable to_s and inspect' do
168
+ matcher = where(:b => 2)
169
+ expected = 'Muack::API.where({:b=>2})'
170
+ matcher.to_s .should.eq expected
171
+ matcher.inspect.should.eq expected
172
+ end
173
+
174
+ would 'satisfy' do
175
+ mock(Str).say(where(:b => 2)){ |arg| arg[:b] }
176
+ Str.say(:b => 2).should.eq 2
177
+ Muack.verify.should.eq true
178
+ end
179
+
180
+ would 'satisfy with satisfy' do
181
+ mock(Str).say(where(:b => is_a(Integer))){ |arg| arg[:b] }
182
+ Str.say(:b => 3).should.eq 3
183
+ Muack.verify.should.eq true
184
+ end
185
+
186
+ would 'satisfy with satisfy recursive' do
187
+ spec = where(:a => {:b => is_a(Integer)})
188
+ mock(Str).say(spec){ |arg| arg[:a][:b] }
189
+ Str.say(:a => {:b => 1}).should.eq 1
190
+ Muack.verify.should.eq true
191
+ end
192
+
193
+ would 'raise Unexpected error if passing unexpected argument' do
194
+ mock(Obj).say(where(:b => 2)){ 'boo' }
195
+ e = should.raise(Muack::Unexpected){ Obj.say(:b => 1) }
196
+ e.expected.should.eq 'obj.say(Muack::API.where({:b=>2}))'
197
+ e.was .should.eq 'obj.say({:b=>1})'
198
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
199
+ end
200
+
201
+ would 'raise Unexpected error if passing unsatisfied argument' do
202
+ mock(Obj).say(where(:a => 0, :b => is_a(String))){ 'boo' }
203
+ e = should.raise(Muack::Unexpected){ Obj.say(:a => 0) }
204
+ e.expected.should.eq \
205
+ 'obj.say(Muack::API.where({:a=>0, :b=>Muack::API.is_a(String)}))'
206
+ e.was .should.eq 'obj.say({:a=>0})'
207
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
208
+ end
209
+
210
+ would 'raise Unexpected error if passing unsatisfied argument' do
211
+ mock(Obj).say(where(:a => 0, :b => is_a(Integer))){ 'boo' }
212
+ e = should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => 1, :c => 2)}
213
+ e.expected.should.eq \
214
+ 'obj.say(Muack::API.where({:a=>0, :b=>Muack::API.is_a(Integer)}))'
215
+ e.was .should.eq 'obj.say({:a=>0, :b=>1, :c=>2})'
216
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
217
+ end
218
+
219
+ would 'recurse' do
220
+ mock(Obj).say(where(:a =>
221
+ having(:b =>
222
+ allowing(:c => [is_a(Integer)])))){ 'boo' }
223
+ e = should.raise(Muack::Unexpected){Obj.say(:a => 0)}
224
+ e.expected.should.eq \
225
+ 'obj.say(Muack::API.where({:a=>' \
226
+ 'Muack::API.having({:b=>' \
227
+ 'Muack::API.allowing({:c=>' \
228
+ '[Muack::API.is_a(Integer)]})})}))'
229
+ e.was .should.eq 'obj.say({:a=>0})'
230
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
231
+ end
232
+
233
+ would 'respect all keys', :groups => [:only] do
234
+ mock(Obj).say(where(:a => 0)){ 'nnf' }
235
+ should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => nil)}
236
+ end
237
+ end
238
+
239
+ describe Muack::Having do
240
+ would 'have human readable to_s and inspect' do
241
+ matcher = having(:b => 2)
242
+ expected = 'Muack::API.having({:b=>2})'
243
+ matcher.to_s .should.eq expected
244
+ matcher.inspect.should.eq expected
245
+ end
246
+
247
+ would 'satisfy' do
248
+ mock(Str).say(having(:b => 2)){ |arg| arg[:a] }
249
+ Str.say(:a => 1, :b => 2).should.eq 1
250
+ Muack.verify.should.eq true
251
+ end
252
+
253
+ would 'satisfy with satisfy' do
254
+ mock(Str).say(having(:b => is_a(Integer))){ |arg| arg[:b] }
255
+ Str.say(:a => 1, :b => 2).should.eq 2
256
+ Muack.verify.should.eq true
257
+ end
258
+
259
+ would 'satisfy with satisfy recursive' do
260
+ spec = having(:a => {:b => is_a(Integer)})
261
+ mock(Str).say(spec){ |arg| arg[:a][:c] }
262
+ Str.say(:a => {:b => 1, :c => 2}, :d => 3).should.eq 2
263
+ Muack.verify.should.eq true
264
+ end
265
+
266
+ would 'raise Unexpected error if passing unexpected argument' do
267
+ mock(Obj).say(having(:b => 2)){ 'boo' }
268
+ e = should.raise(Muack::Unexpected){ Obj.say(:a => 1) }
269
+ e.expected.should.eq 'obj.say(Muack::API.having({:b=>2}))'
270
+ e.was .should.eq 'obj.say({:a=>1})'
271
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
272
+ end
273
+
274
+ would 'raise Unexpected error if passing unsatisfied argument' do
275
+ mock(Obj).say(having(:a => 0, :b => is_a(Integer))){ 'boo' }
276
+ e = should.raise(Muack::Unexpected){ Obj.say(:b => 1) }
277
+ e.expected.should.eq \
278
+ 'obj.say(Muack::API.having({:a=>0, :b=>Muack::API.is_a(Integer)}))'
279
+ e.was .should.eq 'obj.say({:b=>1})'
280
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
281
+ end
282
+
283
+ would 'respect all keys' do
284
+ mock(Obj).say(having(:a => 0, :b => nil)){ 'nnf' }
285
+ should.raise(Muack::Unexpected){Obj.say(:a => 0)}
286
+ end
287
+ end
288
+
289
+ describe Muack::Allowing do
290
+ would 'have human readable to_s and inspect' do
291
+ matcher = allowing(:b => 2)
292
+ expected = 'Muack::API.allowing({:b=>2})'
293
+ matcher.to_s .should.eq expected
294
+ matcher.inspect.should.eq expected
295
+ end
296
+
297
+ would 'satisfy' do
298
+ mock(Str).say(allowing(:a => 0, :b => 1)){ |arg| arg[:a] }
299
+ Str.say(:a => 0).should.eq 0
300
+ Muack.verify.should.eq true
301
+ end
302
+
303
+ would 'satisfy with satisfy' do
304
+ mock(Str).say(allowing(:a => is_a(Integer), :b => 1)){ |arg| arg[:a] }
305
+ Str.say(:a => 0).should.eq 0
306
+ Muack.verify.should.eq true
307
+ end
308
+
309
+ would 'satisfy with satisfy recursive' do
310
+ spec = allowing(:a => {:b => is_a(Integer), :c => 1}, :d => 2)
311
+ mock(Str).say(spec){ |arg| arg[:a][:b] }
312
+ Str.say(:a => {:b => 0}).should.eq 0
313
+ Muack.verify.should.eq true
314
+ end
315
+
316
+ would 'raise Unexpected error if passing unexpected argument' do
317
+ mock(Obj).say(allowing(:b => 2)){ 'boo' }
318
+ e = should.raise(Muack::Unexpected){ Obj.say(:a => 1) }
319
+ e.expected.should.eq 'obj.say(Muack::API.allowing({:b=>2}))'
320
+ e.was .should.eq 'obj.say({:a=>1})'
321
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
322
+ end
323
+
324
+ would 'raise Unexpected error if passing unsatisfied argument' do
325
+ mock(Obj).say(allowing(:b => is_a(String))){ 'boo' }
326
+ e = should.raise(Muack::Unexpected){ Obj.say(:b => '1', :c => 2) }
327
+ e.expected.should.eq \
328
+ 'obj.say(Muack::API.allowing({:b=>Muack::API.is_a(String)}))'
329
+ e.was .should.eq 'obj.say({:b=>"1", :c=>2})'
330
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
331
+ end
332
+
333
+ would 'respect all keys' do
334
+ mock(Obj).say(allowing(:a => 0)){ 'nnf' }
335
+ should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => nil)}
336
+ end
337
+ end
338
+
339
+ describe Muack::Satisfying do
205
340
  would 'have human readable to_s and inspect' do
206
- matcher = satisfy{ |arg| arg % 2 == 0 }
207
- expected = 'Muack::API.satisfy(#<Proc:'
341
+ matcher = satisfying{ |arg| arg % 2 == 0 }
342
+ expected = 'Muack::API.satisfying(#<Proc:'
208
343
  matcher.to_s .should.start_with? expected
209
344
  matcher.inspect.should.start_with? expected
210
345
  end
211
346
 
212
347
  would 'not crash for top-level subclass' do
213
- Class.new(Muack::Satisfy){ def self.name; 'TopLevel'; end }.new.
348
+ Class.new(Muack::Satisfying){ def self.name; 'TopLevel'; end }.new.
214
349
  api_name.should.eq 'top_level'
215
350
  end
216
351
 
217
352
  would 'satisfy' do
218
- mock(Str).say(satisfy{ |arg| arg % 2 == 0 }){ |arg| arg + 1 }
353
+ mock(Str).say(satisfying{ |arg| arg % 2 == 0 }){ |arg| arg + 1 }
219
354
  Str.say(14).should.eq 15
220
355
  Muack.verify.should.eq true
221
356
  Muack::EnsureReset.call
222
357
  end
223
358
 
224
359
  would 'raise Unexpected error if passing unexpected argument' do
225
- mock(Obj).say(satisfy{ |arg| arg % 2 == 0 }){ 'boo' }
360
+ mock(Obj).say(satisfying{ |arg| arg % 2 == 0 }){ 'boo' }
226
361
  e = should.raise(Muack::Unexpected){ Obj.say(1) }
227
- e.expected.should.start_with? 'obj.say(Muack::API.satisfy(#<Proc:'
362
+ e.expected.should.start_with? 'obj.say(Muack::API.satisfying(#<Proc:'
228
363
  e.was .should.eq 'obj.say(1)'
229
364
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
230
365
  end
231
366
  end
232
367
 
233
- describe Muack::Satisfy::Disj do
368
+ describe Muack::Satisfying::Disj do
234
369
  would 'have human readable to_s and inspect' do
235
370
  matcher = is_a(TrueClass) | is_a(FalseClass)
236
371
  expected = 'Muack::API.is_a(TrueClass) | Muack::API.is_a(FalseClass)'
@@ -246,26 +381,27 @@ describe Muack::Satisfy do
246
381
  end
247
382
 
248
383
  would 'raise Unexpected error if passing unexpected argument' do
249
- mock(Obj).say(within('0'..'1') | match(/a/)){ 'boo' }
384
+ mock(Obj).say(within('0'..'1') | matching(/a/)){ 'boo' }
250
385
  e = should.raise(Muack::Unexpected){ Obj.say('2') }
251
386
  e.expected.should.eq \
252
- 'obj.say(Muack::API.within("0".."1") | Muack::API.match(/a/))'
387
+ 'obj.say(Muack::API.within("0".."1") | Muack::API.matching(/a/))'
253
388
  e.was .should.eq \
254
389
  'obj.say("2")'
255
390
  e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
256
391
  end
257
392
  end
258
393
 
259
- describe Muack::Satisfy::Conj do
394
+ describe Muack::Satisfying::Conj do
260
395
  would 'have human readable to_s and inspect' do
261
- matcher = respond_to(:ancestors) & is_a(Class)
262
- expected = 'Muack::API.respond_to(:ancestors) & Muack::API.is_a(Class)'
396
+ matcher = responding_to(:ancestors) & is_a(Class)
397
+ expected =
398
+ 'Muack::API.responding_to(:ancestors) & Muack::API.is_a(Class)'
263
399
  matcher.to_s .should.eq expected
264
400
  matcher.inspect.should.eq expected
265
401
  end
266
402
 
267
403
  would 'satisfy' do
268
- mock(Str).say(respond_to(:ancestors) & is_a(Class)){ |arg| arg.new }
404
+ mock(Str).say(responding_to(:ancestors) & is_a(Class)){ |arg| arg.new }
269
405
  Str.say(String).should.eq ''
270
406
  Muack.verify .should.eq true
271
407
  Muack::EnsureReset.call