muack 1.3.0 → 1.5.1
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 +5 -5
- data/.travis.yml +19 -9
- data/CHANGES.md +39 -0
- data/Gemfile +0 -4
- data/README.md +33 -24
- data/Rakefile +3 -4
- data/lib/muack/block.rb +4 -15
- data/lib/muack/block_26.rb +16 -0
- data/lib/muack/block_27.rb +16 -0
- data/lib/muack/coat.rb +1 -1
- data/lib/muack/definition.rb +4 -3
- data/lib/muack/failure.rb +5 -4
- data/lib/muack/mock.rb +139 -67
- data/lib/muack/satisfying.rb +20 -11
- data/lib/muack/spy.rb +18 -4
- data/lib/muack/stub.rb +7 -6
- data/lib/muack/test.rb +42 -11
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +65 -55
- data/task/README.md +8 -8
- data/task/gemgem.rb +34 -7
- data/test/test_any_instance_of.rb +16 -2
- data/test/test_from_readme.rb +5 -7
- data/test/test_keyargs.rb +160 -0
- data/test/test_mock.rb +24 -0
- data/test/test_modifier.rb +6 -6
- data/test/test_prepend.rb +121 -0
- data/test/test_proxy.rb +19 -4
- data/test/test_satisfying.rb +39 -10
- data/test/test_spy.rb +149 -0
- data/test/test_stub.rb +0 -95
- data/test/test_visibility.rb +120 -0
- metadata +17 -8
data/test/test_satisfying.rb
CHANGED
@@ -178,13 +178,13 @@ describe Muack::Satisfying do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
would 'satisfy with satisfy' do
|
181
|
-
mock(Str).say(where(:b => is_a(
|
181
|
+
mock(Str).say(where(:b => is_a(Integer))){ |arg| arg[:b] }
|
182
182
|
Str.say(:b => 3).should.eq 3
|
183
183
|
Muack.verify.should.eq true
|
184
184
|
end
|
185
185
|
|
186
186
|
would 'satisfy with satisfy recursive' do
|
187
|
-
spec = where(:a => {:b => is_a(
|
187
|
+
spec = where(:a => {:b => is_a(Integer)})
|
188
188
|
mock(Str).say(spec){ |arg| arg[:a][:b] }
|
189
189
|
Str.say(:a => {:b => 1}).should.eq 1
|
190
190
|
Muack.verify.should.eq true
|
@@ -208,13 +208,32 @@ describe Muack::Satisfying do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
would 'raise Unexpected error if passing unsatisfied argument' do
|
211
|
-
mock(Obj).say(where(:a => 0, :b => is_a(
|
211
|
+
mock(Obj).say(where(:a => 0, :b => is_a(Integer))){ 'boo' }
|
212
212
|
e = should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => 1, :c => 2)}
|
213
213
|
e.expected.should.eq \
|
214
|
-
'obj.say(Muack::API.where({:a=>0, :b=>Muack::API.is_a(
|
214
|
+
'obj.say(Muack::API.where({:a=>0, :b=>Muack::API.is_a(Integer)}))'
|
215
215
|
e.was .should.eq 'obj.say({:a=>0, :b=>1, :c=>2})'
|
216
216
|
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
217
217
|
end
|
218
|
+
|
219
|
+
would 'recurse' do
|
220
|
+
mock(Obj).say(where(:a =>
|
221
|
+
having(:b =>
|
222
|
+
allowing(:c => [is_a(Integer)])))){ 'boo' }
|
223
|
+
e = should.raise(Muack::Unexpected){Obj.say(:a => 0)}
|
224
|
+
e.expected.should.eq \
|
225
|
+
'obj.say(Muack::API.where({:a=>' \
|
226
|
+
'Muack::API.having({:b=>' \
|
227
|
+
'Muack::API.allowing({:c=>' \
|
228
|
+
'[Muack::API.is_a(Integer)]})})}))'
|
229
|
+
e.was .should.eq 'obj.say({:a=>0})'
|
230
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
231
|
+
end
|
232
|
+
|
233
|
+
would 'respect all keys', :groups => [:only] do
|
234
|
+
mock(Obj).say(where(:a => 0)){ 'nnf' }
|
235
|
+
should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => nil)}
|
236
|
+
end
|
218
237
|
end
|
219
238
|
|
220
239
|
describe Muack::Having do
|
@@ -232,13 +251,13 @@ describe Muack::Satisfying do
|
|
232
251
|
end
|
233
252
|
|
234
253
|
would 'satisfy with satisfy' do
|
235
|
-
mock(Str).say(having(:b => is_a(
|
254
|
+
mock(Str).say(having(:b => is_a(Integer))){ |arg| arg[:b] }
|
236
255
|
Str.say(:a => 1, :b => 2).should.eq 2
|
237
256
|
Muack.verify.should.eq true
|
238
257
|
end
|
239
258
|
|
240
259
|
would 'satisfy with satisfy recursive' do
|
241
|
-
spec = having(:a => {:b => is_a(
|
260
|
+
spec = having(:a => {:b => is_a(Integer)})
|
242
261
|
mock(Str).say(spec){ |arg| arg[:a][:c] }
|
243
262
|
Str.say(:a => {:b => 1, :c => 2}, :d => 3).should.eq 2
|
244
263
|
Muack.verify.should.eq true
|
@@ -253,13 +272,18 @@ describe Muack::Satisfying do
|
|
253
272
|
end
|
254
273
|
|
255
274
|
would 'raise Unexpected error if passing unsatisfied argument' do
|
256
|
-
mock(Obj).say(having(:a => 0, :b => is_a(
|
275
|
+
mock(Obj).say(having(:a => 0, :b => is_a(Integer))){ 'boo' }
|
257
276
|
e = should.raise(Muack::Unexpected){ Obj.say(:b => 1) }
|
258
277
|
e.expected.should.eq \
|
259
|
-
'obj.say(Muack::API.having({:a=>0, :b=>Muack::API.is_a(
|
278
|
+
'obj.say(Muack::API.having({:a=>0, :b=>Muack::API.is_a(Integer)}))'
|
260
279
|
e.was .should.eq 'obj.say({:b=>1})'
|
261
280
|
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
262
281
|
end
|
282
|
+
|
283
|
+
would 'respect all keys' do
|
284
|
+
mock(Obj).say(having(:a => 0, :b => nil)){ 'nnf' }
|
285
|
+
should.raise(Muack::Unexpected){Obj.say(:a => 0)}
|
286
|
+
end
|
263
287
|
end
|
264
288
|
|
265
289
|
describe Muack::Allowing do
|
@@ -277,13 +301,13 @@ describe Muack::Satisfying do
|
|
277
301
|
end
|
278
302
|
|
279
303
|
would 'satisfy with satisfy' do
|
280
|
-
mock(Str).say(allowing(:a => is_a(
|
304
|
+
mock(Str).say(allowing(:a => is_a(Integer), :b => 1)){ |arg| arg[:a] }
|
281
305
|
Str.say(:a => 0).should.eq 0
|
282
306
|
Muack.verify.should.eq true
|
283
307
|
end
|
284
308
|
|
285
309
|
would 'satisfy with satisfy recursive' do
|
286
|
-
spec = allowing(:a => {:b => is_a(
|
310
|
+
spec = allowing(:a => {:b => is_a(Integer), :c => 1}, :d => 2)
|
287
311
|
mock(Str).say(spec){ |arg| arg[:a][:b] }
|
288
312
|
Str.say(:a => {:b => 0}).should.eq 0
|
289
313
|
Muack.verify.should.eq true
|
@@ -305,6 +329,11 @@ describe Muack::Satisfying do
|
|
305
329
|
e.was .should.eq 'obj.say({:b=>"1", :c=>2})'
|
306
330
|
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
307
331
|
end
|
332
|
+
|
333
|
+
would 'respect all keys' do
|
334
|
+
mock(Obj).say(allowing(:a => 0)){ 'nnf' }
|
335
|
+
should.raise(Muack::Unexpected){Obj.say(:a => 0, :b => nil)}
|
336
|
+
end
|
308
337
|
end
|
309
338
|
|
310
339
|
describe Muack::Satisfying do
|
data/test/test_spy.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
require 'muack/test'
|
3
|
+
|
4
|
+
describe Muack::Spy do
|
5
|
+
describe 'Muack.verify==true' do
|
6
|
+
after do
|
7
|
+
Muack.verify.should.eq true
|
8
|
+
Muack::EnsureReset.call
|
9
|
+
end
|
10
|
+
|
11
|
+
would 'inspect' do
|
12
|
+
spy( Obj).inspect.should.eq "Muack::API.spy(obj)"
|
13
|
+
end
|
14
|
+
|
15
|
+
would 'work with spy' do
|
16
|
+
stub(Obj).say{0}
|
17
|
+
Obj.say.should.eq 0
|
18
|
+
spy(Obj).say
|
19
|
+
end
|
20
|
+
|
21
|
+
would 'work with spy twice' do
|
22
|
+
stub(Obj).say{}
|
23
|
+
2.times{ Obj.say.should.eq nil }
|
24
|
+
spy(Obj).say.times(2)
|
25
|
+
end
|
26
|
+
|
27
|
+
would 'work with spy spy' do
|
28
|
+
stub(Obj).say{}
|
29
|
+
2.times{ Obj.say.should.eq nil }
|
30
|
+
2.times{ spy(Obj).say }
|
31
|
+
end
|
32
|
+
|
33
|
+
would 'work with call spy and call spy' do
|
34
|
+
stub(Obj).say{}
|
35
|
+
2.times do
|
36
|
+
Obj.say.should.eq nil
|
37
|
+
spy(Obj).say
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
would 'verify spy arguments' do
|
42
|
+
stub(Obj).say(1){|a|a}
|
43
|
+
Obj.say(1).should.eq 1
|
44
|
+
spy(Obj).say(1)
|
45
|
+
end
|
46
|
+
|
47
|
+
would 'properly verify spy arguments' do
|
48
|
+
stub(Obj).say(is_a(String)){|a|a}
|
49
|
+
Obj.say('Hi!').should.eq 'Hi!'
|
50
|
+
spy(Obj).say(is_a(String))
|
51
|
+
end
|
52
|
+
|
53
|
+
would 'ignore messages spies not interested' do
|
54
|
+
stub(Obj).saya{0}
|
55
|
+
stub(Obj).sayb{1}
|
56
|
+
Obj.saya.should.eq 0
|
57
|
+
Obj.sayb.should.eq 1
|
58
|
+
spy(Obj).saya
|
59
|
+
end
|
60
|
+
|
61
|
+
would 'not care about the order' do
|
62
|
+
stub(Obj).say(is_a(Integer)){|i|i} # change to &:itself in the future
|
63
|
+
Obj .say(1).should.eq 1
|
64
|
+
Obj .say(2).should.eq 2
|
65
|
+
spy(Obj).say(2)
|
66
|
+
spy(Obj).say(1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'Muack.verify==false' do
|
71
|
+
after do
|
72
|
+
Muack.reset
|
73
|
+
Muack::EnsureReset.call
|
74
|
+
end
|
75
|
+
|
76
|
+
would 'raise Expected if it is not satisfied' do
|
77
|
+
stub(Obj).say{}
|
78
|
+
spy(Obj).say
|
79
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
80
|
+
e.expected .should.eq 'obj.say()'
|
81
|
+
e.expected_times.should.eq 1
|
82
|
+
e.actual_times .should.eq 0
|
83
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
84
|
+
"called 1 times\n but was 0 times."
|
85
|
+
end
|
86
|
+
|
87
|
+
would 'show correct times for under satisfaction' do
|
88
|
+
stub(Obj).say{}
|
89
|
+
2.times{ Obj.say }
|
90
|
+
spy(Obj).say.times(3)
|
91
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
92
|
+
e.expected .should.eq 'obj.say()'
|
93
|
+
e.expected_times.should.eq 3
|
94
|
+
e.actual_times .should.eq 2
|
95
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
96
|
+
"called 3 times\n but was 2 times."
|
97
|
+
end
|
98
|
+
|
99
|
+
would 'show correct times for over satisfaction' do
|
100
|
+
stub(Obj).say{}
|
101
|
+
2.times{ Obj.say }
|
102
|
+
spy(Obj).say
|
103
|
+
e = should.raise(Muack::Expected){ Muack.verify }
|
104
|
+
e.expected .should.eq 'obj.say()'
|
105
|
+
e.expected_times.should.eq 1
|
106
|
+
e.actual_times .should.eq 2
|
107
|
+
e.message .should.eq "\nExpected: obj.say()\n " \
|
108
|
+
"called 1 times\n but was 2 times."
|
109
|
+
end
|
110
|
+
|
111
|
+
would 'raise Expected if arguments do not match' do
|
112
|
+
stub(Obj).say(is_a(Integer)){}
|
113
|
+
Obj .say(1)
|
114
|
+
spy(Obj).say(0)
|
115
|
+
e = should.raise(Muack::Unexpected){ Muack.verify }
|
116
|
+
e.expected.should.eq "obj.say(0)"
|
117
|
+
e.was .should.eq 'obj.say(1)'
|
118
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
119
|
+
end
|
120
|
+
|
121
|
+
would 'raise Expected if arguments do not match, show original args' do
|
122
|
+
stub(Obj).say(is_a(Integer)){}
|
123
|
+
Obj .say(0)
|
124
|
+
Obj .say(1)
|
125
|
+
Obj .say(2)
|
126
|
+
spy(Obj).say(within(1..1))
|
127
|
+
spy(Obj).say(within(0..0))
|
128
|
+
e = should.raise(Muack::Unexpected){ Muack.verify }
|
129
|
+
e.expected.should.eq "obj.say(Muack::API.within(0..0))\n" \
|
130
|
+
" or: obj.say(Muack::API.within(1..1))"
|
131
|
+
e.was .should.eq 'obj.say(2)'
|
132
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
133
|
+
end
|
134
|
+
|
135
|
+
would 'raise Expected if arguments do not match, show original args' do
|
136
|
+
stub(Obj).say(is_a(Integer)){}
|
137
|
+
Obj .say(2)
|
138
|
+
Obj .say(0)
|
139
|
+
Obj .say(1)
|
140
|
+
spy(Obj).say(within(1..1))
|
141
|
+
spy(Obj).say(within(0..0))
|
142
|
+
e = should.raise(Muack::Unexpected){ Muack.verify }
|
143
|
+
e.expected.should.eq "obj.say(Muack::API.within(1..1))\n" \
|
144
|
+
" or: obj.say(Muack::API.within(0..0))"
|
145
|
+
e.was .should.eq 'obj.say(2)'
|
146
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/test/test_stub.rb
CHANGED
@@ -16,10 +16,6 @@ describe Muack::Stub do
|
|
16
16
|
stub(Obj).inspect.should.eq "Muack::API.stub(obj)"
|
17
17
|
end
|
18
18
|
|
19
|
-
would 'inspect' do
|
20
|
-
spy( Obj).inspect.should.eq "Muack::API.spy(obj)"
|
21
|
-
end
|
22
|
-
|
23
19
|
would 'stub with regular method' do
|
24
20
|
stub(Obj).say{ 'goo' }
|
25
21
|
3.times{ Obj.say.should.eq 'goo' }
|
@@ -43,52 +39,6 @@ describe Muack::Stub do
|
|
43
39
|
Obj.saya.should.eq 1
|
44
40
|
Obj.say .should.eq 0
|
45
41
|
end
|
46
|
-
|
47
|
-
would 'work with spy' do
|
48
|
-
stub(Obj).say{0}
|
49
|
-
Obj.say.should.eq 0
|
50
|
-
spy(Obj).say
|
51
|
-
end
|
52
|
-
|
53
|
-
would 'work with spy twice' do
|
54
|
-
stub(Obj).say{}
|
55
|
-
2.times{ Obj.say.should.eq nil }
|
56
|
-
spy(Obj).say.times(2)
|
57
|
-
end
|
58
|
-
|
59
|
-
would 'work with spy spy' do
|
60
|
-
stub(Obj).say{}
|
61
|
-
2.times{ Obj.say.should.eq nil }
|
62
|
-
2.times{ spy(Obj).say }
|
63
|
-
end
|
64
|
-
|
65
|
-
would 'work with call spy and call spy' do
|
66
|
-
stub(Obj).say{}
|
67
|
-
2.times do
|
68
|
-
Obj.say.should.eq nil
|
69
|
-
spy(Obj).say
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
would 'verify spy arguments' do
|
74
|
-
stub(Obj).say(1){|a|a}
|
75
|
-
Obj.say(1).should.eq 1
|
76
|
-
spy(Obj).say(1)
|
77
|
-
end
|
78
|
-
|
79
|
-
would 'properly verify spy arguments' do
|
80
|
-
stub(Obj).say(is_a(String)){|a|a}
|
81
|
-
Obj.say('Hi!').should.eq 'Hi!'
|
82
|
-
spy(Obj).say(is_a(String))
|
83
|
-
end
|
84
|
-
|
85
|
-
would 'ignore messages spies not interested' do
|
86
|
-
stub(Obj).saya{0}
|
87
|
-
stub(Obj).sayb{1}
|
88
|
-
Obj.saya.should.eq 0
|
89
|
-
Obj.sayb.should.eq 1
|
90
|
-
spy(Obj).saya
|
91
|
-
end
|
92
42
|
end
|
93
43
|
|
94
44
|
describe 'Muack.verify==false' do
|
@@ -113,50 +63,5 @@ describe Muack::Stub do
|
|
113
63
|
e.was .should.eq 'obj.say(false)'
|
114
64
|
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
115
65
|
end
|
116
|
-
|
117
|
-
would 'raise Expected if the spy is not satisfied' do
|
118
|
-
stub(Obj).say{}
|
119
|
-
spy(Obj).say
|
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."
|
126
|
-
end
|
127
|
-
|
128
|
-
would 'raise Expected if the spy is not satisfied enough' do
|
129
|
-
stub(Obj).say{}
|
130
|
-
Obj.say
|
131
|
-
spy(Obj).say(0)
|
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}"
|
136
|
-
end
|
137
|
-
|
138
|
-
would 'show correct times for under satisfaction' do
|
139
|
-
stub(Obj).say{}
|
140
|
-
2.times{ Obj.say }
|
141
|
-
spy(Obj).say.times(3)
|
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."
|
148
|
-
end
|
149
|
-
|
150
|
-
would 'show correct times for over satisfaction' do
|
151
|
-
stub(Obj).say{}
|
152
|
-
2.times{ Obj.say }
|
153
|
-
spy(Obj).say
|
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."
|
160
|
-
end
|
161
66
|
end
|
162
67
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
|
2
|
+
require 'muack/test'
|
3
|
+
|
4
|
+
describe 'retain visibility' do
|
5
|
+
after do
|
6
|
+
expect(Muack.verify).eq true
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify obj, visibility
|
10
|
+
expect(Muack.verify).eq true
|
11
|
+
|
12
|
+
if visibility == :public
|
13
|
+
expect(obj).respond_to? :hello
|
14
|
+
else
|
15
|
+
expect(obj).not.respond_to? :hello
|
16
|
+
expect(obj).respond_to? :hello, true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate visibility
|
21
|
+
klass = Class.new do
|
22
|
+
def greet
|
23
|
+
'hi'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
mod = Module.new do
|
28
|
+
def greet
|
29
|
+
hello
|
30
|
+
end
|
31
|
+
|
32
|
+
def hello
|
33
|
+
'hello'
|
34
|
+
end
|
35
|
+
send visibility, :hello
|
36
|
+
end
|
37
|
+
|
38
|
+
perform(klass, mod)
|
39
|
+
end
|
40
|
+
|
41
|
+
copy :test do
|
42
|
+
%i[public protected private].each do |visibility|
|
43
|
+
would "stub with #{visibility}" do
|
44
|
+
obj = generate(visibility)
|
45
|
+
|
46
|
+
stub(obj).hello{'stubbed'}
|
47
|
+
|
48
|
+
verify(obj, visibility)
|
49
|
+
end
|
50
|
+
|
51
|
+
would "stub proxy with #{visibility}" do
|
52
|
+
obj = generate(visibility)
|
53
|
+
|
54
|
+
stub(obj).hello
|
55
|
+
|
56
|
+
verify(obj, visibility)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'prepend on class stub with object' do
|
62
|
+
def perform(klass, mod)
|
63
|
+
klass.prepend(mod)
|
64
|
+
klass.new
|
65
|
+
end
|
66
|
+
|
67
|
+
paste :test
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'extend on object stub with object' do
|
71
|
+
def perform(klass, mod)
|
72
|
+
obj = klass.new
|
73
|
+
obj.extend(mod)
|
74
|
+
obj
|
75
|
+
end
|
76
|
+
|
77
|
+
paste :test
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'include on singleton_class stub with object' do
|
81
|
+
def perform(klass, mod)
|
82
|
+
obj = klass.new
|
83
|
+
obj.singleton_class.include(mod)
|
84
|
+
obj
|
85
|
+
end
|
86
|
+
|
87
|
+
paste :test
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'prepend on singleton_class stub with object' do
|
91
|
+
def perform(klass, mod)
|
92
|
+
obj = klass.new
|
93
|
+
obj.singleton_class.prepend(mod)
|
94
|
+
obj
|
95
|
+
end
|
96
|
+
|
97
|
+
paste :test
|
98
|
+
end
|
99
|
+
|
100
|
+
# Brought from rspec-mocks
|
101
|
+
would "correctly restore the visibility of methods whose visibility has been tweaked on the singleton class" do
|
102
|
+
# hello is a private method when mixed in, but public on the module
|
103
|
+
# itself
|
104
|
+
mod = Module.new do
|
105
|
+
extend self
|
106
|
+
def hello; :hello; end
|
107
|
+
|
108
|
+
private :hello
|
109
|
+
class << self; public :hello; end
|
110
|
+
end
|
111
|
+
|
112
|
+
expect(mod.hello).eq :hello
|
113
|
+
|
114
|
+
stub(mod).hello{ :stub }
|
115
|
+
|
116
|
+
Muack.reset
|
117
|
+
|
118
|
+
expect(mod.hello).eq :hello
|
119
|
+
end
|
120
|
+
end
|