muack 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7727020cca0c41dfd846c0b7628aec71c2cbb59
4
- data.tar.gz: 9fb966eb9e9e1dc65d8f0e938d2d0a619813f204
3
+ metadata.gz: 23619481e2ad1d312e8b023d3643e777b11a0532
4
+ data.tar.gz: 182baa8926b5b645f4522f8d4bb03ab32e83c52d
5
5
  SHA512:
6
- metadata.gz: 669fbb6e488468cf698bf28782e989f70a7fa82c447b91ef4efdc62892add2bf828d9604d682fbe4b13780cf1599017fbfff22f5d7fa8bbb43c0603b7e5b5d97
7
- data.tar.gz: b6465725ab6109aeead47a3bba111df9095434ec557017ad0141c1ff441e51054504f4217d19fc6b9e1ad2ef2e86e6fdd8cc59cc3568d2498b89bdd30e257dd4
6
+ metadata.gz: d07419f23b7fd2535e7392bea7df9e744b1e4a1cbf6511bf6ec881e76d4d0d87a5a71e3a4012cc8c54f5dcb30f063196c8bd1cad51ccb5cb97fa3c5a00b9b2a6
7
+ data.tar.gz: 3e25a12d67d1533e56836690440badcf0734f78a11d7ab310db4830df3a501d0040ba50e9538620337db3b51e183a5b29ac6a6ae574e3615c173a8aafa13b805
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGES
2
2
 
3
+ ## Muack 0.7.1 -- 2013-07-13
4
+
5
+ * Added `respond_to` argument matcher corresponding to RR's duck_type.
6
+ * Added `|` and `&` for argument matcher union and intersection. See README.md
7
+
3
8
  ## Muack 0.7.0 -- 2013-06-27
4
9
 
5
10
  ### Incompatible changes
data/README.md CHANGED
@@ -156,8 +156,8 @@ any of the above is supported as well, not only stub.
156
156
  any_instance_of(User) do |u|
157
157
  stub(u).valid? { false }
158
158
  mock(u).errors { [] }
159
- mock_proxy.save
160
- stub_proxy.reload
159
+ mock(u).save.proxy
160
+ stub(u).reload.proxy
161
161
  end
162
162
  ```
163
163
 
@@ -363,7 +363,7 @@ object.foo # fails
363
363
 
364
364
  Multiple mock with different argument set is fine, too.
365
365
 
366
- ```
366
+ ``` ruby
367
367
  mock(object).foo(1, 2).times(0)
368
368
  mock(object).foo(3, 4)
369
369
  object.foo(3, 4) # ok
@@ -462,7 +462,15 @@ mock(object).foobar(is_a(Numeric))
462
462
  object.foobar(99)
463
463
  ```
464
464
 
465
- No boolean supports. Pass a custom satisfy block for it:
465
+ No boolean supports, but you can use union (`|`).
466
+
467
+ ``` ruby
468
+ mock(object).foobar(is_a(TrueClass) | is_a(FalseClass))
469
+ object.foobar(false)
470
+ ```
471
+
472
+ Or simply pass a custom satisfy block for it.
473
+ Though there's not much point here. Just want to demonstrate.
466
474
 
467
475
  ``` ruby
468
476
  mock(object).foobar(
@@ -470,11 +478,21 @@ mock(object).foobar(
470
478
  object.foobar(false)
471
479
  ```
472
480
 
473
- No duck_type supports. Pass a custom satisfy block for it:
481
+ Since duck_type is a weird name to me. Here we use `respond_to(:walk, :talk)`.
474
482
 
475
483
  ``` ruby
476
- mock(object).foobar(
477
- satisfy{ |a| a.respond_to?(:walk) && a.respond_to?(:talk) })
484
+ mock(object).foobar(respond_to(:walk, :talk))
485
+ arg = Object.new
486
+ def arg.walk; 'waddle'; end
487
+ def arg.talk; 'quack'; end
488
+ object.foobar(arg)
489
+ ```
490
+
491
+ You can also use intersection (`&`) for multiple responses.
492
+ Though there's not much point here. Just want to demonstrate.
493
+
494
+ ``` ruby
495
+ mock(object).foobar(respond_to(:walk) & respond_to(:talk))
478
496
  arg = Object.new
479
497
  def arg.walk; 'waddle'; end
480
498
  def arg.talk; 'quack'; end
data/lib/muack.rb CHANGED
@@ -61,6 +61,10 @@ module Muack
61
61
  Muack::Within.new(range_or_array)
62
62
  end
63
63
 
64
+ def respond_to *msg
65
+ Muack::RespondTo.new(*msg)
66
+ end
67
+
64
68
  def satisfy &block
65
69
  Muack::Satisfy.new(block)
66
70
  end
data/lib/muack/satisfy.rb CHANGED
@@ -5,6 +5,31 @@ module Muack
5
5
  !!block.call(actual_arg)
6
6
  end
7
7
 
8
+ def | rhs; Satisfy::Union.new(self, rhs); end
9
+ def & rhs; Satisfy::Inter.new(self, rhs); end
10
+
11
+ class Union < Satisfy
12
+ def initialize lhs, rhs
13
+ @lhs, @rhs = lhs, rhs
14
+ super(lambda{ |actual_arg| lhs.match(actual_arg) ||
15
+ rhs.match(actual_arg) })
16
+ end
17
+
18
+ def to_s; "#{@lhs} | #{@rhs}"; end
19
+ alias_method :inspect, :to_s
20
+ end
21
+
22
+ class Inter < Satisfy
23
+ def initialize lhs, rhs
24
+ @lhs, @rhs = lhs, rhs
25
+ super(lambda{ |actual_arg| lhs.match(actual_arg) &&
26
+ rhs.match(actual_arg) })
27
+ end
28
+
29
+ def to_s; "#{@lhs} & #{@rhs}"; end
30
+ alias_method :inspect, :to_s
31
+ end
32
+
8
33
  def to_s
9
34
  "Muack::API.#{api_name}(#{api_args.map(&:inspect).join(', ')})"
10
35
  end
@@ -51,4 +76,11 @@ module Muack
51
76
  [range_or_array]
52
77
  end
53
78
  end
79
+
80
+ class RespondTo < Satisfy
81
+ def initialize *messages
82
+ super lambda{ |actual_arg|
83
+ messages.all?{ |msg| actual_arg.respond_to?(msg) } }, messages
84
+ end
85
+ end
54
86
  end
data/lib/muack/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
data/muack.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "muack"
5
- s.version = "0.7.0"
5
+ s.version = "0.7.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2013-06-27"
9
+ s.date = "2013-07-13"
10
10
  s.description = "Muack -- Yet another mocking library.\n\nBasically it's an [RR][] clone, but much faster under heavy use.\nIt's 32x times faster (750s vs 23s) for running [Rib][] tests.\n\n[RR]: https://github.com/rr/rr\n[Rib]: https://github.com/godfat/rib"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.files = [
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  s.homepage = "https://github.com/godfat/muack"
44
44
  s.licenses = ["Apache License 2.0"]
45
45
  s.require_paths = ["lib"]
46
- s.rubygems_version = "2.0.3"
46
+ s.rubygems_version = "2.0.5"
47
47
  s.summary = "Muack -- Yet another mocking library."
48
48
  s.test_files = [
49
49
  "test/test_any_instance_of.rb",
data/test/test_satisfy.rb CHANGED
@@ -167,6 +167,47 @@ describe Muack::Satisfy do
167
167
  end
168
168
  end
169
169
 
170
+ describe Muack::RespondTo do
171
+ should 'have human readable to_s and inspect' do
172
+ matcher = respond_to(:id)
173
+ expected = 'Muack::API.respond_to(:id)'
174
+ matcher.to_s .should.start_with expected
175
+ matcher.inspect.should.start_with expected
176
+
177
+ matcher = respond_to(:id, :reload)
178
+ expected = 'Muack::API.respond_to(:id, :reload)'
179
+ matcher.to_s .should.start_with expected
180
+ matcher.inspect.should.start_with expected
181
+ end
182
+
183
+ should 'satisfy' do
184
+ mock(Str).say(respond_to(:verify, :reset)){ |arg| arg.name }
185
+ Str.say(Muack).should.eq 'Muack'
186
+ Muack.verify.should.eq true
187
+
188
+ mock(Str).say(respond_to(:verify )){ |arg| arg.name }
189
+ Str.say(Muack).should.eq 'Muack'
190
+ Muack.verify.should.eq true
191
+
192
+ Muack::EnsureReset.call
193
+ end
194
+
195
+ should 'raise Unexpected error if passing unexpected argument' do
196
+ mock(Obj).say(respond_to(:nothing)){ 'boo' }
197
+ begin
198
+ Obj.say(0)
199
+ 'never'.should.eq 'reach'
200
+ rescue Muack::Unexpected => e
201
+ e.expected.should.eq 'obj.say(Muack::API.respond_to(:nothing))'
202
+ e.was .should.eq 'obj.say(0)'
203
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
204
+ ensure
205
+ Muack.reset
206
+ Muack::EnsureReset.call
207
+ end
208
+ end
209
+ end
210
+
170
211
  describe Muack::Satisfy do
171
212
  should 'have human readable to_s and inspect' do
172
213
  matcher = satisfy{ |arg| arg % 2 == 0 }
@@ -197,4 +238,70 @@ describe Muack::Satisfy do
197
238
  end
198
239
  end
199
240
  end
241
+
242
+ describe Muack::Satisfy::Union do
243
+ should 'have human readable to_s and inspect' do
244
+ matcher = is_a(TrueClass) | is_a(FalseClass)
245
+ expected = 'Muack::API.is_a(TrueClass) | Muack::API.is_a(FalseClass)'
246
+ matcher.to_s .should.start_with expected
247
+ matcher.inspect.should.start_with expected
248
+ end
249
+
250
+ should 'satisfy' do
251
+ mock(Str).say(is_a(TrueClass) | is_a(FalseClass)){ |arg| !arg }
252
+ Str.say(false).should.eq true
253
+ Muack.verify .should.eq true
254
+ Muack::EnsureReset.call
255
+ end
256
+
257
+ should 'raise Unexpected error if passing unexpected argument' do
258
+ mock(Obj).say(within('0'..'1') | match(/a/)){ 'boo' }
259
+ begin
260
+ Obj.say('2')
261
+ 'never'.should.eq 'reach'
262
+ rescue Muack::Unexpected => e
263
+ e.expected.should.eq \
264
+ 'obj.say(Muack::API.within("0".."1") | Muack::API.match(/a/))'
265
+ e.was .should.eq \
266
+ 'obj.say("2")'
267
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
268
+ ensure
269
+ Muack.reset
270
+ Muack::EnsureReset.call
271
+ end
272
+ end
273
+ end
274
+
275
+ describe Muack::Satisfy::Inter do
276
+ should 'have human readable to_s and inspect' do
277
+ matcher = respond_to(:ancestors) & is_a(Class)
278
+ expected = 'Muack::API.respond_to(:ancestors) & Muack::API.is_a(Class)'
279
+ matcher.to_s .should.eq expected
280
+ matcher.inspect.should.eq expected
281
+ end
282
+
283
+ should 'satisfy' do
284
+ mock(Str).say(respond_to(:ancestors) & is_a(Class)){ |arg| arg.new }
285
+ Str.say(String).should.eq ''
286
+ Muack.verify .should.eq true
287
+ Muack::EnsureReset.call
288
+ end
289
+
290
+ should 'raise Unexpected error if passing unexpected argument' do
291
+ mock(Obj).say(anything & within(0..1)){ 'boo' }
292
+ begin
293
+ Obj.say(2)
294
+ 'never'.should.eq 'reach'
295
+ rescue Muack::Unexpected => e
296
+ e.expected.should.eq \
297
+ 'obj.say(Muack::API.anything() & Muack::API.within(0..1))'
298
+ e.was .should.eq \
299
+ 'obj.say(2)'
300
+ e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
301
+ ensure
302
+ Muack.reset
303
+ Muack::EnsureReset.call
304
+ end
305
+ end
306
+ end
200
307
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2013-07-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Muack -- Yet another mocking library.
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.0.3
77
+ rubygems_version: 2.0.5
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Muack -- Yet another mocking library.