muack 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ca32470f688bde71bc3a56bed45ead89c3c9123
4
- data.tar.gz: c54e8badae54d1b321cf5c95cc0facdc36b2a604
3
+ metadata.gz: b0cc50c953e21826fe85b70e03238b3c22486195
4
+ data.tar.gz: 621fad09a9fb9fe21edd940d33e60d0415c12c5f
5
5
  SHA512:
6
- metadata.gz: 7cfb937f5866fa9b92380029a3b2327874b4e28a0e87bb99652e7f0550a8b62731cd0bea78d2854bb2b379ce7dd1734cc5c837333b6463724adbf5cb8733dbbb
7
- data.tar.gz: b47a79b28dbfe31d81e78c99308ef45596556531436bcd8294987b5d688301cdfbbee8a8eb7d8437712337b3e39a44f70085ac1b50ca16512faf58bdb9676ddb
6
+ metadata.gz: f9453f77aeadc5efcecfd33e6785a7ec4d8700c01e72367910f6b68be0480dc2e3699f87c5658c2ce41601ad78b3f3ca2800ba78aa4ccde9d8ee6ea8234e14a8
7
+ data.tar.gz: 0d69e0c4d3c544ef7e69c2b60691f369086cac70f2284167dadfc03613087fa2bd78476675ddf9f8504a811eca1abbeb625312082b33f043bb241ccf8928ba41
data/CHANGES.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # CHANGES
2
2
 
3
+ ## Muack 0.5.2 -- 2013-06-26
4
+
5
+ * Add `returns` modifier which you can pass the return values if passing
6
+ a block to a certain method is not convenient (e.g. `[]`).
7
+
8
+ Instead of sending `method_missing` to pass a block:
9
+
10
+ ``` ruby
11
+ stub(object).method_missing(:[], is_a(Fixnum)){ |a| a+1 }
12
+ object[1] #=> 2
13
+ ```
14
+
15
+ You could now use `returns` to pass the block.
16
+
17
+ ``` ruby
18
+ stub(object)[is_a(Fixnum)].returns{ |a| a + 1 }
19
+ object[1] #=> 2
20
+ ```
21
+
22
+ Or if you only want to return a simple value, you could also pass the
23
+ value directly without passing a block:
24
+
25
+ ``` ruby
26
+ stub(object)[is_a(Fixnum)].returns(2)
27
+ object[1] #=> 2
28
+ ```
29
+
3
30
  ## Muack 0.5.1 -- 2013-06-25
4
31
 
5
32
  * Fix issues with multiple call to any_instance_of with the same class.
data/README.md CHANGED
@@ -209,10 +209,37 @@ mock(object).method_missing(:inspect){ 'bar' }.times(2)
209
209
 
210
210
  #### [Stubbing method implementation / return value](https://github.com/rr/rr/blob/e4b4907fd0488738affb4dab8ce88cbe9fa6580e/doc/03_api_overview.md#stubbing-method-implementation--return-value)
211
211
 
212
- Again, there's only one true API form you can use. On the other hand,
213
- since Muack is more strict than RR. Passing no arguments means you
214
- really don't want any argument. Here we need to specify the argument
215
- for Muack. The example should be changed to:
212
+ Again, we embrace one true API to avoid confusion, unless the alternative
213
+ API really has a great advantage. So we encourage people to use the block to
214
+ return values. However, sometimes you cannot easily do that for certain
215
+ methods due to Ruby's syntax. For example, you can't pass a block to
216
+ a subscript operator `[]`. As a workaround, you can do it with
217
+ `method_missing`, though it's not very obvious if you don't know
218
+ what is `method_missing`.
219
+
220
+ ``` ruby
221
+ stub(object).method_missing(:[], is_a(Fixnum)){ |a| a+1 }
222
+ object[1] #=> 2
223
+ ```
224
+
225
+ Instead you can do this with `returns`:
226
+
227
+ ``` ruby
228
+ stub(object)[is_a(Fixnum)].returns{ |a| a + 1 }
229
+ object[1] #=> 2
230
+ ```
231
+
232
+ You can also pass a value directly to `returns` if you only want to return
233
+ a simple value.
234
+
235
+ ``` ruby
236
+ stub(object)[is_a(Fixnum)].returns(2)
237
+ object[1] #=> 2
238
+ ```
239
+
240
+ On the other hand, since Muack is more strict than RR. Passing no arguments
241
+ means you really don't want any argument. Here we need to specify the
242
+ argument for Muack. The example in RR should be changed to this in Muack:
216
243
 
217
244
  ``` ruby
218
245
  stub(object).foo(is_a(Fixnum), anything){ |age, count, &block|
@@ -9,6 +9,11 @@ module Muack
9
9
  self
10
10
  end
11
11
 
12
+ # Public API
13
+ def returns val=nil, &block
14
+ defi.block = block || lambda{ val }
15
+ end
16
+
12
17
  # Public API
13
18
  def times number
14
19
  if number >= 1
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '0.5.1'
3
+ VERSION = '0.5.2'
4
4
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "muack"
5
- s.version = "0.5.1"
5
+ s.version = "0.5.2"
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-25"
9
+ s.date = "2013-06-26"
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 = [
@@ -76,6 +76,16 @@ describe Muack::Mock do
76
76
  Muack.verify.should.eq true
77
77
  obj.f .should.eq 0
78
78
  end
79
+
80
+ should 'return values with returns with a value' do
81
+ mock(Obj).say.returns(0)
82
+ Obj.say.should.eq 0
83
+ end
84
+
85
+ should 'return values with returns with a block' do
86
+ mock(Obj).say.returns{0}
87
+ Obj.say.should.eq 0
88
+ end
79
89
  end
80
90
 
81
91
  describe 'Muack.verify==false' do
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.5.1
4
+ version: 0.5.2
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-25 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Muack -- Yet another mocking library.