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_proxy.rb
CHANGED
@@ -8,44 +8,44 @@ describe Muack::Mock do
|
|
8
8
|
Muack::EnsureReset.call
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
would 'proxy with regular method' do
|
12
12
|
mock(Str).reverse
|
13
13
|
Str.reverse.should.eq 'ooM'
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
would 'proxy with private method' do
|
17
17
|
mock(Obj).private.peek_return(&:reverse)
|
18
18
|
Obj.__send__(:private).should.eq 'irp'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
would 'proxy multiple times' do
|
22
22
|
2.times{ mock(Str).reverse }
|
23
23
|
2.times{ Str.reverse.should.eq 'ooM' }
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
would 'proxy multiple times with super method' do
|
27
27
|
2.times{ mock(Str).class }
|
28
28
|
2.times{ Str.class.should.eq String }
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
would 'proxy with super method for multiple arguments' do
|
32
32
|
args = %w[o u]
|
33
33
|
mock(Str).tr(*args)
|
34
34
|
Str.tr(*args).should.eq 'Muu'
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
would 'return modifier itself for any modifier methods' do
|
38
38
|
mock(Str).to_s.peek_return{ |s| s.reverse }.times(2).
|
39
39
|
with_any_args.with_any_args
|
40
40
|
2.times{ Str.to_s.should.eq 'ooM' }
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
would 'proxy and call the original method' do
|
44
44
|
mock(Obj).method_missing(:inspect).peek_return{ |str| str.reverse }
|
45
45
|
Obj.inspect.should.eq 'jbo'
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
would 'proxy and call the original method for multiple arguments' do
|
49
49
|
args = %w[o u]
|
50
50
|
mock(Obj).aloha(*args)
|
51
51
|
mock(Obj).aloha
|
@@ -53,31 +53,31 @@ describe Muack::Mock do
|
|
53
53
|
Obj.aloha.should.eq [0, 1]
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
would 'proxy and call the block with super' do
|
57
57
|
mock(Str).class.peek_return{ |k| k.name.reverse }
|
58
58
|
Str.class.should.eq 'gnirtS'
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
would 'mock proxy and call, mock proxy and call' do
|
62
62
|
mock(Obj).class.peek_return{ |k| k.name.reverse }
|
63
63
|
Obj.class.should.eq 'tcejbO'
|
64
64
|
mock(Obj).class.peek_return{ |k| k.name.upcase }
|
65
65
|
Obj.class.should.eq 'OBJECT'
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
would 'stub proxy and call, stub proxy and call' do
|
69
69
|
stub(Obj).kind_of?(Object).peek_return{ |b| !b }
|
70
70
|
Obj.kind_of?(Object).should.eq false
|
71
71
|
stub(Obj).kind_of?(String).peek_return{ |b| b.to_s }
|
72
72
|
Obj.kind_of?(String).should.eq 'false'
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
would 'stub proxy with any times' do
|
76
76
|
stub(Obj).class.peek_return{ |k| k.name.downcase }
|
77
77
|
3.times{ Obj.class.should.eq 'object' }
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
would 'stub proxy and spy' do
|
81
81
|
stub(Obj).class.peek_return{ |k| k.name.downcase }
|
82
82
|
Obj.class.should.eq 'object'
|
83
83
|
spy(Obj).class
|
@@ -90,19 +90,15 @@ describe Muack::Mock do
|
|
90
90
|
Muack::EnsureReset.call
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
would 'raise Expected error if passing unexpected argument' do
|
94
94
|
mock(Str).reverse
|
95
95
|
Str.reverse.should.eq 'ooM'
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
e.actual_times .should.eq 2
|
103
|
-
e.message .should.eq "\nExpected: \"Moo\".reverse()\n " \
|
104
|
-
"called 1 times\n but was 2 times."
|
105
|
-
end
|
96
|
+
e = should.raise(Muack::Expected){ Str.reverse }
|
97
|
+
e.expected .should.eq '"Moo".reverse()'
|
98
|
+
e.expected_times.should.eq 1
|
99
|
+
e.actual_times .should.eq 2
|
100
|
+
e.message .should.eq "\nExpected: \"Moo\".reverse()\n " \
|
101
|
+
"called 1 times\n but was 2 times."
|
106
102
|
end
|
107
103
|
end
|
108
104
|
end
|
data/test/test_satisfy.rb
CHANGED
@@ -2,46 +2,43 @@
|
|
2
2
|
require 'muack/test'
|
3
3
|
|
4
4
|
describe Muack::Satisfy do
|
5
|
+
after do
|
6
|
+
Muack.reset
|
7
|
+
Muack::EnsureReset.call
|
8
|
+
end
|
9
|
+
|
5
10
|
describe Muack::IsA do
|
6
|
-
|
11
|
+
would 'have human readable to_s and inspect' do
|
7
12
|
matcher = is_a(String)
|
8
13
|
expected = 'Muack::API.is_a(String)'
|
9
14
|
matcher.to_s .should.eq expected
|
10
15
|
matcher.inspect.should.eq expected
|
11
16
|
end
|
12
17
|
|
13
|
-
|
18
|
+
would 'satisfy' do
|
14
19
|
mock(Str).say(is_a(String)){ |arg| arg.reverse }
|
15
20
|
Str.say('Foo').should.eq 'ooF'
|
16
21
|
Muack.verify.should.eq true
|
17
|
-
Muack::EnsureReset.call
|
18
22
|
end
|
19
23
|
|
20
|
-
|
24
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
21
25
|
mock(Obj).say(is_a(Array)){ 'boo' }
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
e.expected.should.eq 'obj.say(Muack::API.is_a(Array))'
|
27
|
-
e.was .should.eq 'obj.say(false)'
|
28
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
29
|
-
ensure
|
30
|
-
Muack.reset
|
31
|
-
Muack::EnsureReset.call
|
32
|
-
end
|
26
|
+
e = should.raise(Muack::Unexpected){ Obj.say(false) }
|
27
|
+
e.expected.should.eq 'obj.say(Muack::API.is_a(Array))'
|
28
|
+
e.was .should.eq 'obj.say(false)'
|
29
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
36
33
|
describe Muack::Anything do
|
37
|
-
|
34
|
+
would 'have human readable to_s and inspect' do
|
38
35
|
matcher = anything
|
39
36
|
expected = 'Muack::API.anything()'
|
40
37
|
matcher.to_s .should.eq expected
|
41
38
|
matcher.inspect.should.eq expected
|
42
39
|
end
|
43
40
|
|
44
|
-
|
41
|
+
would 'satisfy' do
|
45
42
|
mock(Str).say(anything){ |arg| arg*2 }
|
46
43
|
Str.say(5).should.eq 10
|
47
44
|
Muack.verify.should.eq true
|
@@ -50,191 +47,142 @@ describe Muack::Satisfy do
|
|
50
47
|
Str.say('b').should.eq 'B'
|
51
48
|
|
52
49
|
Muack.verify.should.eq true
|
53
|
-
Muack::EnsureReset.call
|
54
50
|
end
|
55
51
|
|
56
|
-
|
52
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
57
53
|
mock(Obj).say(anything){ 'boo' }
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
e.expected.should.eq 'obj.say(Muack::API.anything())'
|
63
|
-
e.was .should.eq 'obj.say(6, 7)'
|
64
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
65
|
-
ensure
|
66
|
-
Muack.reset
|
67
|
-
Muack::EnsureReset.call
|
68
|
-
end
|
54
|
+
e = should.raise(Muack::Unexpected){ Obj.say(6, 7) }
|
55
|
+
e.expected.should.eq 'obj.say(Muack::API.anything())'
|
56
|
+
e.was .should.eq 'obj.say(6, 7)'
|
57
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
69
58
|
end
|
70
59
|
end
|
71
60
|
|
72
61
|
describe Muack::Match do
|
73
|
-
|
62
|
+
would 'have human readable to_s and inspect' do
|
74
63
|
matcher = match(/\w/)
|
75
64
|
expected = 'Muack::API.match(/\w/)'
|
76
65
|
matcher.to_s .should.eq expected
|
77
66
|
matcher.inspect.should.eq expected
|
78
67
|
end
|
79
68
|
|
80
|
-
|
69
|
+
would 'satisfy' do
|
81
70
|
mock(Str).say(match(/\w/)){ |arg| arg }
|
82
71
|
Str.say('aa').should.eq 'aa'
|
83
72
|
Muack.verify.should.eq true
|
84
|
-
Muack::EnsureReset.call
|
85
73
|
end
|
86
74
|
|
87
|
-
|
75
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
88
76
|
mock(Obj).say(match(/\w/)){ 'boo' }
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
e.expected.should.eq 'obj.say(Muack::API.match(/\w/))'
|
94
|
-
e.was .should.eq 'obj.say("!")'
|
95
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
96
|
-
ensure
|
97
|
-
Muack.reset
|
98
|
-
Muack::EnsureReset.call
|
99
|
-
end
|
77
|
+
e = should.raise(Muack::Unexpected){ Obj.say('!') }
|
78
|
+
e.expected.should.eq 'obj.say(Muack::API.match(/\w/))'
|
79
|
+
e.was .should.eq 'obj.say("!")'
|
80
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
100
81
|
end
|
101
82
|
end
|
102
83
|
|
103
84
|
describe Muack::HashIncluding do
|
104
|
-
|
85
|
+
would 'have human readable to_s and inspect' do
|
105
86
|
matcher = hash_including(:b => 2)
|
106
87
|
expected = 'Muack::API.hash_including({:b=>2})'
|
107
88
|
matcher.to_s .should.eq expected
|
108
89
|
matcher.inspect.should.eq expected
|
109
90
|
end
|
110
91
|
|
111
|
-
|
92
|
+
would 'satisfy' do
|
112
93
|
mock(Str).say(hash_including(:b => 2)){ |arg| arg[:a] }
|
113
94
|
Str.say(:a => 1, :b => 2).should.eq 1
|
114
95
|
Muack.verify.should.eq true
|
115
|
-
Muack::EnsureReset.call
|
116
96
|
end
|
117
97
|
|
118
|
-
|
98
|
+
would 'satisfy with satisfy' do
|
119
99
|
mock(Str).say(hash_including(:b => is_a(Fixnum))){ |arg| arg[:b] }
|
120
100
|
Str.say(:a => 1, :b => 2).should.eq 2
|
121
101
|
Muack.verify.should.eq true
|
122
|
-
Muack::EnsureReset.call
|
123
102
|
end
|
124
103
|
|
125
|
-
|
104
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
126
105
|
mock(Obj).say(hash_including(:b => 2)){ 'boo' }
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
ensure
|
135
|
-
Muack.reset
|
136
|
-
Muack::EnsureReset.call
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
should 'raise Unexpected error if passing unsatisfied argument' do
|
106
|
+
e = should.raise(Muack::Unexpected){ Obj.say(:a => 1) }
|
107
|
+
e.expected.should.eq 'obj.say(Muack::API.hash_including({:b=>2}))'
|
108
|
+
e.was .should.eq 'obj.say({:a=>1})'
|
109
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
110
|
+
end
|
111
|
+
|
112
|
+
would 'raise Unexpected error if passing unsatisfied argument' do
|
141
113
|
mock(Obj).say(hash_including(:b => is_a(String))){ 'boo' }
|
142
|
-
|
143
|
-
|
144
|
-
'
|
145
|
-
|
146
|
-
|
147
|
-
'obj.say(Muack::API.hash_including({:b=>Muack::API.is_a(String)}))'
|
148
|
-
e.was .should.eq 'obj.say({:b=>1})'
|
149
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
150
|
-
ensure
|
151
|
-
Muack.reset
|
152
|
-
Muack::EnsureReset.call
|
153
|
-
end
|
114
|
+
e = should.raise(Muack::Unexpected){ Obj.say(:b => 1) }
|
115
|
+
e.expected.should.eq \
|
116
|
+
'obj.say(Muack::API.hash_including({:b=>Muack::API.is_a(String)}))'
|
117
|
+
e.was .should.eq 'obj.say({:b=>1})'
|
118
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
154
119
|
end
|
155
120
|
end
|
156
121
|
|
157
122
|
describe Muack::Including do
|
158
|
-
|
123
|
+
would 'have human readable to_s and inspect' do
|
159
124
|
matcher = including(2)
|
160
125
|
expected = 'Muack::API.including(2)'
|
161
126
|
matcher.to_s .should.eq expected
|
162
127
|
matcher.inspect.should.eq expected
|
163
128
|
end
|
164
129
|
|
165
|
-
|
130
|
+
would 'satisfy' do
|
166
131
|
mock(Str).say(including(2)){ |arg| arg.first }
|
167
132
|
Str.say([1, 2]).should.eq 1
|
168
133
|
Muack.verify.should.eq true
|
169
|
-
Muack::EnsureReset.call
|
170
134
|
end
|
171
135
|
|
172
|
-
|
136
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
173
137
|
mock(Obj).say(including(2)){ 'boo' }
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
e.expected.should.eq 'obj.say(Muack::API.including(2))'
|
179
|
-
e.was .should.eq 'obj.say([1])'
|
180
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
181
|
-
ensure
|
182
|
-
Muack.reset
|
183
|
-
Muack::EnsureReset.call
|
184
|
-
end
|
138
|
+
e = should.raise(Muack::Unexpected){ Obj.say([1]) }
|
139
|
+
e.expected.should.eq 'obj.say(Muack::API.including(2))'
|
140
|
+
e.was .should.eq 'obj.say([1])'
|
141
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
185
142
|
end
|
186
143
|
end
|
187
144
|
|
188
145
|
describe Muack::Within do
|
189
|
-
|
146
|
+
would 'have human readable to_s and inspect' do
|
190
147
|
matcher = within(0..9)
|
191
148
|
expected = 'Muack::API.within(0..9)'
|
192
149
|
matcher.to_s .should.eq expected
|
193
150
|
matcher.inspect.should.eq expected
|
194
151
|
end
|
195
152
|
|
196
|
-
|
153
|
+
would 'satisfy' do
|
197
154
|
mock(Str).say(within(0..9)){ |arg| arg*2 }
|
198
155
|
Str.say(5).should.eq 10
|
199
156
|
Muack.verify.should.eq true
|
200
157
|
|
201
158
|
mock(Str).say(within(%[a b])){ |arg| arg.upcase }
|
202
159
|
Str.say('b').should.eq 'B'
|
203
|
-
|
204
160
|
Muack.verify.should.eq true
|
205
|
-
Muack::EnsureReset.call
|
206
161
|
end
|
207
162
|
|
208
|
-
|
163
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
209
164
|
mock(Obj).say(within(0..5)){ 'boo' }
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
e.expected.should.eq 'obj.say(Muack::API.within(0..5))'
|
215
|
-
e.was .should.eq 'obj.say(6)'
|
216
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
217
|
-
ensure
|
218
|
-
Muack.reset
|
219
|
-
Muack::EnsureReset.call
|
220
|
-
end
|
165
|
+
e = should.raise(Muack::Unexpected){ Obj.say(6) }
|
166
|
+
e.expected.should.eq 'obj.say(Muack::API.within(0..5))'
|
167
|
+
e.was .should.eq 'obj.say(6)'
|
168
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
221
169
|
end
|
222
170
|
end
|
223
171
|
|
224
172
|
describe Muack::RespondTo do
|
225
|
-
|
173
|
+
would 'have human readable to_s and inspect' do
|
226
174
|
matcher = respond_to(:id)
|
227
175
|
expected = 'Muack::API.respond_to(:id)'
|
228
|
-
matcher.to_s .should.start_with expected
|
229
|
-
matcher.inspect.should.start_with expected
|
176
|
+
matcher.to_s .should.start_with? expected
|
177
|
+
matcher.inspect.should.start_with? expected
|
230
178
|
|
231
179
|
matcher = respond_to(:id, :reload)
|
232
180
|
expected = 'Muack::API.respond_to(:id, :reload)'
|
233
|
-
matcher.to_s .should.start_with expected
|
234
|
-
matcher.inspect.should.start_with expected
|
181
|
+
matcher.to_s .should.start_with? expected
|
182
|
+
matcher.inspect.should.start_with? expected
|
235
183
|
end
|
236
184
|
|
237
|
-
|
185
|
+
would 'satisfy' do
|
238
186
|
mock(Str).say(respond_to(:verify, :reset)){ |arg| arg.name }
|
239
187
|
Str.say(Muack).should.eq 'Muack'
|
240
188
|
Muack.verify.should.eq true
|
@@ -242,125 +190,95 @@ describe Muack::Satisfy do
|
|
242
190
|
mock(Str).say(respond_to(:verify )){ |arg| arg.name }
|
243
191
|
Str.say(Muack).should.eq 'Muack'
|
244
192
|
Muack.verify.should.eq true
|
245
|
-
|
246
|
-
Muack::EnsureReset.call
|
247
193
|
end
|
248
194
|
|
249
|
-
|
195
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
250
196
|
mock(Obj).say(respond_to(:nothing)){ 'boo' }
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
e.expected.should.eq 'obj.say(Muack::API.respond_to(:nothing))'
|
256
|
-
e.was .should.eq 'obj.say(0)'
|
257
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
258
|
-
ensure
|
259
|
-
Muack.reset
|
260
|
-
Muack::EnsureReset.call
|
261
|
-
end
|
197
|
+
e = should.raise(Muack::Unexpected){ Obj.say(0) }
|
198
|
+
e.expected.should.eq 'obj.say(Muack::API.respond_to(:nothing))'
|
199
|
+
e.was .should.eq 'obj.say(0)'
|
200
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
262
201
|
end
|
263
202
|
end
|
264
203
|
|
265
204
|
describe Muack::Satisfy do
|
266
|
-
|
205
|
+
would 'have human readable to_s and inspect' do
|
267
206
|
matcher = satisfy{ |arg| arg % 2 == 0 }
|
268
207
|
expected = 'Muack::API.satisfy(#<Proc:'
|
269
|
-
matcher.to_s .should.start_with expected
|
270
|
-
matcher.inspect.should.start_with expected
|
208
|
+
matcher.to_s .should.start_with? expected
|
209
|
+
matcher.inspect.should.start_with? expected
|
271
210
|
end
|
272
211
|
|
273
|
-
|
212
|
+
would 'not crash for top-level subclass' do
|
274
213
|
Class.new(Muack::Satisfy){ def self.name; 'TopLevel'; end }.new.
|
275
214
|
api_name.should.eq 'top_level'
|
276
215
|
end
|
277
216
|
|
278
|
-
|
217
|
+
would 'satisfy' do
|
279
218
|
mock(Str).say(satisfy{ |arg| arg % 2 == 0 }){ |arg| arg + 1 }
|
280
219
|
Str.say(14).should.eq 15
|
281
220
|
Muack.verify.should.eq true
|
282
221
|
Muack::EnsureReset.call
|
283
222
|
end
|
284
223
|
|
285
|
-
|
224
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
286
225
|
mock(Obj).say(satisfy{ |arg| arg % 2 == 0 }){ 'boo' }
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
e.expected.should.start_with 'obj.say(Muack::API.satisfy(#<Proc:'
|
292
|
-
e.was .should.eq 'obj.say(1)'
|
293
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
294
|
-
ensure
|
295
|
-
Muack.reset
|
296
|
-
Muack::EnsureReset.call
|
297
|
-
end
|
226
|
+
e = should.raise(Muack::Unexpected){ Obj.say(1) }
|
227
|
+
e.expected.should.start_with? 'obj.say(Muack::API.satisfy(#<Proc:'
|
228
|
+
e.was .should.eq 'obj.say(1)'
|
229
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
298
230
|
end
|
299
231
|
end
|
300
232
|
|
301
233
|
describe Muack::Satisfy::Disj do
|
302
|
-
|
234
|
+
would 'have human readable to_s and inspect' do
|
303
235
|
matcher = is_a(TrueClass) | is_a(FalseClass)
|
304
236
|
expected = 'Muack::API.is_a(TrueClass) | Muack::API.is_a(FalseClass)'
|
305
|
-
matcher.to_s .should.start_with expected
|
306
|
-
matcher.inspect.should.start_with expected
|
237
|
+
matcher.to_s .should.start_with? expected
|
238
|
+
matcher.inspect.should.start_with? expected
|
307
239
|
end
|
308
240
|
|
309
|
-
|
241
|
+
would 'satisfy' do
|
310
242
|
mock(Str).say(is_a(TrueClass) | is_a(FalseClass)){ |arg| !arg }
|
311
243
|
Str.say(false).should.eq true
|
312
244
|
Muack.verify .should.eq true
|
313
245
|
Muack::EnsureReset.call
|
314
246
|
end
|
315
247
|
|
316
|
-
|
248
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
317
249
|
mock(Obj).say(within('0'..'1') | match(/a/)){ 'boo' }
|
318
|
-
|
319
|
-
|
320
|
-
'
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
e.was .should.eq \
|
325
|
-
'obj.say("2")'
|
326
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
327
|
-
ensure
|
328
|
-
Muack.reset
|
329
|
-
Muack::EnsureReset.call
|
330
|
-
end
|
250
|
+
e = should.raise(Muack::Unexpected){ Obj.say('2') }
|
251
|
+
e.expected.should.eq \
|
252
|
+
'obj.say(Muack::API.within("0".."1") | Muack::API.match(/a/))'
|
253
|
+
e.was .should.eq \
|
254
|
+
'obj.say("2")'
|
255
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
331
256
|
end
|
332
257
|
end
|
333
258
|
|
334
259
|
describe Muack::Satisfy::Conj do
|
335
|
-
|
260
|
+
would 'have human readable to_s and inspect' do
|
336
261
|
matcher = respond_to(:ancestors) & is_a(Class)
|
337
262
|
expected = 'Muack::API.respond_to(:ancestors) & Muack::API.is_a(Class)'
|
338
263
|
matcher.to_s .should.eq expected
|
339
264
|
matcher.inspect.should.eq expected
|
340
265
|
end
|
341
266
|
|
342
|
-
|
267
|
+
would 'satisfy' do
|
343
268
|
mock(Str).say(respond_to(:ancestors) & is_a(Class)){ |arg| arg.new }
|
344
269
|
Str.say(String).should.eq ''
|
345
270
|
Muack.verify .should.eq true
|
346
271
|
Muack::EnsureReset.call
|
347
272
|
end
|
348
273
|
|
349
|
-
|
274
|
+
would 'raise Unexpected error if passing unexpected argument' do
|
350
275
|
mock(Obj).say(anything & within(0..1)){ 'boo' }
|
351
|
-
|
352
|
-
|
353
|
-
'
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
e.was .should.eq \
|
358
|
-
'obj.say(2)'
|
359
|
-
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
360
|
-
ensure
|
361
|
-
Muack.reset
|
362
|
-
Muack::EnsureReset.call
|
363
|
-
end
|
276
|
+
e = should.raise(Muack::Unexpected){ Obj.say(2) }
|
277
|
+
e.expected.should.eq \
|
278
|
+
'obj.say(Muack::API.anything() & Muack::API.within(0..1))'
|
279
|
+
e.was .should.eq \
|
280
|
+
'obj.say(2)'
|
281
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
364
282
|
end
|
365
283
|
end
|
366
284
|
end
|