muack 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +27 -0
- data/README.md +31 -4
- data/lib/muack/modifier.rb +5 -0
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +2 -2
- data/test/test_mock.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0cc50c953e21826fe85b70e03238b3c22486195
|
4
|
+
data.tar.gz: 621fad09a9fb9fe21edd940d33e60d0415c12c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
213
|
-
|
214
|
-
|
215
|
-
|
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|
|
data/lib/muack/modifier.rb
CHANGED
data/lib/muack/version.rb
CHANGED
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.5.
|
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-
|
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 = [
|
data/test/test_mock.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Muack -- Yet another mocking library.
|