muack 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGES.md +10 -0
- data/Gemfile +1 -1
- data/README.md +43 -9
- data/lib/muack.rb +5 -0
- data/lib/muack/any_instance_of.rb +4 -0
- data/lib/muack/coat.rb +16 -0
- data/lib/muack/failure.rb +1 -1
- data/lib/muack/mock.rb +13 -11
- data/lib/muack/session.rb +16 -10
- data/lib/muack/test.rb +3 -10
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +7 -4
- data/task/gemgem.rb +1 -5
- data/test/test_any_instance_of.rb +25 -27
- data/test/test_coat.rb +48 -0
- data/test/test_from_readme.rb +3 -3
- data/test/test_mock.rb +64 -90
- data/test/test_modifier.rb +17 -17
- data/test/test_proxy.rb +20 -24
- data/test/test_satisfy.rb +97 -179
- data/test/test_stub.rb +50 -74
- metadata +6 -3
data/test/test_stub.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'muack/test'
|
3
3
|
|
4
4
|
describe Muack::Stub do
|
5
|
-
|
5
|
+
would 'raise StubHasNoTimes with stub(obj).f.times(0)' do
|
6
6
|
lambda{ stub(Obj).f.times(0) }.should.raise(Muack::StubHasNoTimes)
|
7
7
|
end
|
8
8
|
|
@@ -12,20 +12,20 @@ describe Muack::Stub do
|
|
12
12
|
Muack::EnsureReset.call
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
would 'inspect' do
|
16
16
|
stub(Obj).inspect.should.eq "Muack::API.stub(obj)"
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
would 'inspect' do
|
20
20
|
spy( Obj).inspect.should.eq "Muack::API.spy(obj)"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
would 'stub with regular method' do
|
24
24
|
stub(Obj).say{ 'goo' }
|
25
25
|
3.times{ Obj.say.should.eq 'goo' }
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
would 'stub with any arguments' do
|
29
29
|
stub(Str).say{ Str.sub('M', 'H') }.with_any_args
|
30
30
|
Str.say .should.eq 'Hoo'
|
31
31
|
Str.say(0) .should.eq 'Hoo'
|
@@ -33,36 +33,36 @@ describe Muack::Stub do
|
|
33
33
|
Str.say(' ').should.eq 'Hoo'
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
would 'pass the actual block' do
|
37
37
|
stub(Obj).say{ |&block| block.call('Hi') }
|
38
38
|
Obj.say{ |msg| msg }.should.eq 'Hi'
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
would 'accept block form' do
|
42
42
|
stub(Obj){ |o| o.say{0}; o.saya{1} }
|
43
43
|
Obj.saya.should.eq 1
|
44
44
|
Obj.say .should.eq 0
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
would '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
|
+
would '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
|
+
would 'work with spy spy' do
|
60
60
|
stub(Obj).say{}
|
61
61
|
2.times{ Obj.say.should.eq nil }
|
62
62
|
2.times{ spy(Obj).say }
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
would 'work with call spy and call spy' do
|
66
66
|
stub(Obj).say{}
|
67
67
|
2.times do
|
68
68
|
Obj.say.should.eq nil
|
@@ -70,19 +70,19 @@ describe Muack::Stub do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
would 'verify spy arguments' do
|
74
74
|
stub(Obj).say(1){|a|a}
|
75
75
|
Obj.say(1).should.eq 1
|
76
76
|
spy(Obj).say(1)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
would 'properly verify spy arguments' do
|
80
80
|
stub(Obj).say(is_a(String)){|a|a}
|
81
81
|
Obj.say('Hi!').should.eq 'Hi!'
|
82
82
|
spy(Obj).say(is_a(String))
|
83
83
|
end
|
84
84
|
|
85
|
-
|
85
|
+
would 'ignore messages spies not interested' do
|
86
86
|
stub(Obj).saya{0}
|
87
87
|
stub(Obj).sayb{1}
|
88
88
|
Obj.saya.should.eq 0
|
@@ -97,90 +97,66 @@ describe Muack::Stub do
|
|
97
97
|
Muack::EnsureReset.call
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
101
101
|
stub(Obj).say(true){ 'boo' }
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
e.expected.should.eq 'obj.say(true)'
|
107
|
-
e.was .should.eq 'obj.say(false)'
|
108
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
109
|
-
end
|
102
|
+
e = should.raise(Muack::Unexpected){ Obj.say(false) }
|
103
|
+
e.expected.should.eq 'obj.say(true)'
|
104
|
+
e.was .should.eq 'obj.say(false)'
|
105
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
110
106
|
end
|
111
107
|
|
112
|
-
|
108
|
+
would 'give all alternatives' do
|
113
109
|
stub(Obj).say(0){ 'boo' }
|
114
110
|
stub(Obj).say(1){ 'moo' }
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
e.expected.should.eq "obj.say(0)\n or: obj.say(1)"
|
120
|
-
e.was .should.eq 'obj.say(false)'
|
121
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
122
|
-
end
|
111
|
+
e = should.raise(Muack::Unexpected){ Obj.say(false) }
|
112
|
+
e.expected.should.eq "obj.say(0)\n or: obj.say(1)"
|
113
|
+
e.was .should.eq 'obj.say(false)'
|
114
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
123
115
|
end
|
124
116
|
|
125
|
-
|
117
|
+
would 'raise Expected if the spy is not satisfied' do
|
126
118
|
stub(Obj).say{}
|
127
119
|
spy(Obj).say
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
e.actual_times .should.eq 0
|
135
|
-
e.message .should.eq "\nExpected: obj.say()\n " \
|
136
|
-
"called 1 times\n but was 0 times."
|
137
|
-
end
|
120
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
121
|
+
e.expected .should.eq 'obj.say()'
|
122
|
+
e.expected_times.should.eq 1
|
123
|
+
e.actual_times .should.eq 0
|
124
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
125
|
+
"called 1 times\n but was 0 times."
|
138
126
|
end
|
139
127
|
|
140
|
-
|
128
|
+
would 'raise Expected if the spy is not satisfied enough' do
|
141
129
|
stub(Obj).say{}
|
142
130
|
Obj.say
|
143
131
|
spy(Obj).say(0)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
e.expected.should.eq "obj.say(0)"
|
149
|
-
e.was .should.eq 'obj.say()'
|
150
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
151
|
-
end
|
132
|
+
e = should.raise(Muack::Unexpected){ Muack.verify }
|
133
|
+
e.expected.should.eq "obj.say(0)"
|
134
|
+
e.was .should.eq 'obj.say()'
|
135
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
152
136
|
end
|
153
137
|
|
154
|
-
|
138
|
+
would 'show correct times for under satisfaction' do
|
155
139
|
stub(Obj).say{}
|
156
140
|
2.times{ Obj.say }
|
157
141
|
spy(Obj).say.times(3)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
e.actual_times .should.eq 2
|
165
|
-
e.message .should.eq "\nExpected: obj.say()\n " \
|
166
|
-
"called 3 times\n but was 2 times."
|
167
|
-
end
|
142
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
143
|
+
e.expected .should.eq 'obj.say()'
|
144
|
+
e.expected_times.should.eq 3
|
145
|
+
e.actual_times .should.eq 2
|
146
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
147
|
+
"called 3 times\n but was 2 times."
|
168
148
|
end
|
169
149
|
|
170
|
-
|
150
|
+
would 'show correct times for over satisfaction' do
|
171
151
|
stub(Obj).say{}
|
172
152
|
2.times{ Obj.say }
|
173
153
|
spy(Obj).say
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
e.actual_times .should.eq 2
|
181
|
-
e.message .should.eq "\nExpected: obj.say()\n " \
|
182
|
-
"called 1 times\n but was 2 times."
|
183
|
-
end
|
154
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
155
|
+
e.expected .should.eq 'obj.say()'
|
156
|
+
e.expected_times.should.eq 1
|
157
|
+
e.actual_times .should.eq 2
|
158
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
159
|
+
"called 1 times\n but was 2 times."
|
184
160
|
end
|
185
161
|
end
|
186
162
|
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: 1.1.
|
4
|
+
version: 1.1.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: 2014-
|
11
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Muack -- A fast, small, yet powerful mocking library.
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/muack.rb
|
36
36
|
- lib/muack/any_instance_of.rb
|
37
37
|
- lib/muack/block.rb
|
38
|
+
- lib/muack/coat.rb
|
38
39
|
- lib/muack/definition.rb
|
39
40
|
- lib/muack/error.rb
|
40
41
|
- lib/muack/failure.rb
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- task/README.md
|
51
52
|
- task/gemgem.rb
|
52
53
|
- test/test_any_instance_of.rb
|
54
|
+
- test/test_coat.rb
|
53
55
|
- test/test_from_readme.rb
|
54
56
|
- test/test_mock.rb
|
55
57
|
- test/test_modifier.rb
|
@@ -76,12 +78,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
78
|
version: '0'
|
77
79
|
requirements: []
|
78
80
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.4.2
|
80
82
|
signing_key:
|
81
83
|
specification_version: 4
|
82
84
|
summary: Muack -- A fast, small, yet powerful mocking library.
|
83
85
|
test_files:
|
84
86
|
- test/test_any_instance_of.rb
|
87
|
+
- test/test_coat.rb
|
85
88
|
- test/test_from_readme.rb
|
86
89
|
- test/test_mock.rb
|
87
90
|
- test/test_modifier.rb
|