muack 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +17 -0
- data/README.md +23 -9
- data/lib/muack/failure.rb +1 -1
- data/lib/muack/spy.rb +3 -1
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +3 -3
- data/test/test_mock.rb +2 -2
- data/test/test_stub.rb +16 -8
- 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: f1c224f1dd6be101ec8dada7a46d3df32f788d82
|
4
|
+
data.tar.gz: cc3f213b4d737ecea14fb3492467c985dcbbe685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 690163afe7968b15fde073e447d54604a20c431645fc56fd56e8fa5f52f1ea0d10bdec7e92ebb78c2b3a38c6291d79c242f49aec6744a7a2639c1abf44e52c90
|
7
|
+
data.tar.gz: 9b4ff0d87fd84b0f76b17983f1e2524fa60d435b5ad48c87f593dbde6c2fc0d5dead257beac7147bad5a37def75dd567c145dc07ab9760ed2310b3ebdaf356ad
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Muack 1.1.0 -- 2014-04-17
|
4
|
+
|
5
|
+
Improvements:
|
6
|
+
|
7
|
+
* Now we show "Unexpected call" instead of "Expected ... was not called".
|
8
|
+
This should make it easier to read and understand.
|
9
|
+
|
10
|
+
Incompatible changes:
|
11
|
+
|
12
|
+
* Previously, if you're using a spy, it would examine all the messages for
|
13
|
+
the given stub. However this might not be desired as then we need to
|
14
|
+
specify everything in the stub for the say. Tedious. From now on, spies
|
15
|
+
would only examine specified messages, ignoring unspecified stubbed
|
16
|
+
methods. This sort of breaks the concept that "mocks = stubs + spies"
|
17
|
+
as spies would not fully examine the stubs now. It's now more like:
|
18
|
+
"mocks >= stubs + spies".
|
19
|
+
|
3
20
|
## Muack 1.0.4 -- 2014-03-29
|
4
21
|
|
5
22
|
* Now we could `Muack.verify(obj)` or `Muack.reset(obj)` a single object.
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Muack is much simpler and thus much faster and much more consistent.
|
|
25
25
|
|
26
26
|
## REQUIREMENTS:
|
27
27
|
|
28
|
-
* Tested with MRI (official CRuby)
|
28
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
29
29
|
|
30
30
|
## INSTALLATION:
|
31
31
|
|
@@ -77,9 +77,10 @@ There are also 3 different kinds of mocks in Muack, which are:
|
|
77
77
|
* Stubs
|
78
78
|
* Spies
|
79
79
|
|
80
|
-
You could
|
80
|
+
You could think of _mocks_ are sort of _stubs_ combined with _spies_. Here's
|
81
|
+
the inequation:
|
81
82
|
|
82
|
-
mock
|
83
|
+
mock >= stub + spy
|
83
84
|
|
84
85
|
Stubs help us inject methods into the objects we want to observe. Spies
|
85
86
|
help us observe the behaviours of the objects. As for mocks, they inject
|
@@ -113,13 +114,21 @@ or not, but sometimes we do care. With stubs and spies, we could always put
|
|
113
114
|
stubs in the before/setup block, and only when we really care if they are
|
114
115
|
called or not, we put spies to examine.
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
section for more detail.
|
117
|
+
The other difference is that, spies could partially verify the corresponding
|
118
|
+
stubs, but not necessarily completely as mocks. For example, we could stub
|
119
|
+
two methods, but only verify one of them with a spy.
|
120
120
|
|
121
|
-
|
122
|
-
|
121
|
+
``` ruby
|
122
|
+
obj = Object.new
|
123
|
+
stub(obj).name{ 'obj' }
|
124
|
+
stub(obj).id { 12345 }
|
125
|
+
p obj.name # 'obj'
|
126
|
+
p obj.id # 12345
|
127
|
+
spy(obj).name
|
128
|
+
p Muack.verify # true
|
129
|
+
```
|
130
|
+
|
131
|
+
This is similar as mixing mocks and stubs, as in the following example:
|
123
132
|
|
124
133
|
``` ruby
|
125
134
|
obj = Object.new
|
@@ -133,6 +142,11 @@ p Muack.verify # true
|
|
133
142
|
However you should not mix mocks and stubs with the same method, or you
|
134
143
|
might encounter some unexpected result. Jump to _Caveat_ for more detail.
|
135
144
|
|
145
|
+
On the other hand, stubs aren't limited to testing. If we want to monkey
|
146
|
+
patching something, stubs could be useful as we don't care how many times
|
147
|
+
the injected methods are called. Jump to _Muack as a mocky patching library_
|
148
|
+
section for more detail.
|
149
|
+
|
136
150
|
### reset and verify
|
137
151
|
|
138
152
|
Calling `Muack.reset` is essentially resetting all mocks, returning all
|
data/lib/muack/failure.rb
CHANGED
@@ -16,7 +16,7 @@ module Muack
|
|
16
16
|
@was = "#{obj.inspect}.#{msg}(" \
|
17
17
|
"#{args.map(&:inspect).join(', ')})"
|
18
18
|
if expected_defis.empty?
|
19
|
-
super("\
|
19
|
+
super("\nUnexpected call: #{@was}")
|
20
20
|
else
|
21
21
|
build_expected(obj, expected_defis)
|
22
22
|
super("\nExpected: #{expected}\n but was: #{was}")
|
data/lib/muack/spy.rb
CHANGED
@@ -10,7 +10,9 @@ module Muack
|
|
10
10
|
|
11
11
|
# used for Muack::Session#verify
|
12
12
|
def __mock_verify
|
13
|
-
@secret.each
|
13
|
+
@secret.each do |defi|
|
14
|
+
__mock_dispatch(defi.msg, defi.args) if __mock_defis.key?(defi.msg)
|
15
|
+
end
|
14
16
|
super # simulate dispatching before passing to mock to verify
|
15
17
|
end
|
16
18
|
|
data/lib/muack/version.rb
CHANGED
data/muack.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: muack 1.0
|
2
|
+
# stub: muack 1.1.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "muack"
|
6
|
-
s.version = "1.0
|
6
|
+
s.version = "1.1.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2014-
|
11
|
+
s.date = "2014-04-17"
|
12
12
|
s.description = "Muack -- A fast, small, yet powerful mocking library.\n\nInspired by [RR][], and it's 32x times faster (750s vs 23s) than RR\nfor running [Rib][] tests.\n\n[RR]: https://github.com/rr/rr\n[Rib]: https://github.com/godfat/rib"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
data/test/test_mock.rb
CHANGED
@@ -160,7 +160,7 @@ describe Muack::Mock do
|
|
160
160
|
rescue Muack::Unexpected => e
|
161
161
|
e.expected.should.eq nil
|
162
162
|
e.was .should.eq 'obj.say()'
|
163
|
-
e.message .should.
|
163
|
+
e.message .should.eq "\nUnexpected call: #{e.was}"
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -172,7 +172,7 @@ describe Muack::Mock do
|
|
172
172
|
rescue Muack::Unexpected => e
|
173
173
|
e.expected.should.eq nil
|
174
174
|
e.was .should.eq 'obj.say(true)'
|
175
|
-
e.message .should.
|
175
|
+
e.message .should.eq "\nUnexpected call: #{e.was}"
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
data/test/test_stub.rb
CHANGED
@@ -47,13 +47,13 @@ describe Muack::Stub do
|
|
47
47
|
should 'work with spy' do
|
48
48
|
stub(Obj).say{0}
|
49
49
|
Obj.say.should.eq 0
|
50
|
-
|
50
|
+
spy(Obj).say
|
51
51
|
end
|
52
52
|
|
53
53
|
should 'work with spy twice' do
|
54
54
|
stub(Obj).say{}
|
55
55
|
2.times{ Obj.say.should.eq nil }
|
56
|
-
|
56
|
+
spy(Obj).say.times(2)
|
57
57
|
end
|
58
58
|
|
59
59
|
should 'work with spy spy' do
|
@@ -65,13 +65,21 @@ describe Muack::Stub do
|
|
65
65
|
should 'verify spy arguments' do
|
66
66
|
stub(Obj).say(1){|a|a}
|
67
67
|
Obj.say(1).should.eq 1
|
68
|
-
|
68
|
+
spy(Obj).say(1)
|
69
69
|
end
|
70
70
|
|
71
71
|
should 'properly verify spy arguments' do
|
72
72
|
stub(Obj).say(is_a(String)){|a|a}
|
73
73
|
Obj.say('Hi!').should.eq 'Hi!'
|
74
|
-
|
74
|
+
spy(Obj).say(is_a(String))
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'ignore messages spies not interested' do
|
78
|
+
stub(Obj).saya{0}
|
79
|
+
stub(Obj).sayb{1}
|
80
|
+
Obj.saya.should.eq 0
|
81
|
+
Obj.sayb.should.eq 1
|
82
|
+
spy(Obj).saya
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
@@ -108,7 +116,7 @@ describe Muack::Stub do
|
|
108
116
|
|
109
117
|
should 'raise Expected if the spy is not satisfied' do
|
110
118
|
stub(Obj).say{}
|
111
|
-
|
119
|
+
spy(Obj).say
|
112
120
|
begin
|
113
121
|
Muack.verify
|
114
122
|
'never'.should.eq 'reach'
|
@@ -124,7 +132,7 @@ describe Muack::Stub do
|
|
124
132
|
should 'raise Expected if the spy is not satisfied enough' do
|
125
133
|
stub(Obj).say{}
|
126
134
|
Obj.say
|
127
|
-
|
135
|
+
spy(Obj).say(0)
|
128
136
|
begin
|
129
137
|
Muack.verify
|
130
138
|
'never'.should.eq 'reach'
|
@@ -138,7 +146,7 @@ describe Muack::Stub do
|
|
138
146
|
should 'show correct times for under satisfaction' do
|
139
147
|
stub(Obj).say{}
|
140
148
|
2.times{ Obj.say }
|
141
|
-
|
149
|
+
spy(Obj).say.times(3)
|
142
150
|
begin
|
143
151
|
Muack.verify
|
144
152
|
'never'.should.eq 'reach'
|
@@ -154,7 +162,7 @@ describe Muack::Stub do
|
|
154
162
|
should 'show correct times for over satisfaction' do
|
155
163
|
stub(Obj).say{}
|
156
164
|
2.times{ Obj.say }
|
157
|
-
|
165
|
+
spy(Obj).say
|
158
166
|
begin
|
159
167
|
Muack.verify
|
160
168
|
'never'.should.eq 'reach'
|
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: 1.0
|
4
|
+
version: 1.1.0
|
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: 2014-
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Muack -- A fast, small, yet powerful mocking library.
|