muack 1.2.0 → 1.5.0
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 +47 -0
- data/Gemfile +0 -4
- data/README.md +162 -65
- data/Rakefile +3 -4
- data/lib/muack.rb +43 -11
- 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/error.rb +6 -0
- data/lib/muack/failure.rb +5 -4
- data/lib/muack/mock.rb +134 -68
- data/lib/muack/satisfying.rb +195 -0
- 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 +6 -8
- data/test/test_keyargs.rb +111 -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_satisfy.rb → test_satisfying.rb} +216 -80
- data/test/test_spy.rb +149 -0
- data/test/test_stub.rb +0 -95
- data/test/test_visibility.rb +120 -0
- metadata +20 -11
- data/lib/muack/satisfy.rb +0 -100
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
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Muack -- A fast, small, yet powerful mocking library.
|
@@ -35,13 +35,15 @@ files:
|
|
35
35
|
- lib/muack.rb
|
36
36
|
- lib/muack/any_instance_of.rb
|
37
37
|
- lib/muack/block.rb
|
38
|
+
- lib/muack/block_26.rb
|
39
|
+
- lib/muack/block_27.rb
|
38
40
|
- lib/muack/coat.rb
|
39
41
|
- lib/muack/definition.rb
|
40
42
|
- lib/muack/error.rb
|
41
43
|
- lib/muack/failure.rb
|
42
44
|
- lib/muack/mock.rb
|
43
45
|
- lib/muack/modifier.rb
|
44
|
-
- lib/muack/
|
46
|
+
- lib/muack/satisfying.rb
|
45
47
|
- lib/muack/session.rb
|
46
48
|
- lib/muack/spy.rb
|
47
49
|
- lib/muack/stub.rb
|
@@ -53,16 +55,20 @@ files:
|
|
53
55
|
- test/test_any_instance_of.rb
|
54
56
|
- test/test_coat.rb
|
55
57
|
- test/test_from_readme.rb
|
58
|
+
- test/test_keyargs.rb
|
56
59
|
- test/test_mock.rb
|
57
60
|
- test/test_modifier.rb
|
61
|
+
- test/test_prepend.rb
|
58
62
|
- test/test_proxy.rb
|
59
|
-
- test/
|
63
|
+
- test/test_satisfying.rb
|
64
|
+
- test/test_spy.rb
|
60
65
|
- test/test_stub.rb
|
66
|
+
- test/test_visibility.rb
|
61
67
|
homepage: https://github.com/godfat/muack
|
62
68
|
licenses:
|
63
|
-
- Apache
|
69
|
+
- Apache-2.0
|
64
70
|
metadata: {}
|
65
|
-
post_install_message:
|
71
|
+
post_install_message:
|
66
72
|
rdoc_options: []
|
67
73
|
require_paths:
|
68
74
|
- lib
|
@@ -77,17 +83,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
83
|
- !ruby/object:Gem::Version
|
78
84
|
version: '0'
|
79
85
|
requirements: []
|
80
|
-
|
81
|
-
|
82
|
-
signing_key:
|
86
|
+
rubygems_version: 3.1.4
|
87
|
+
signing_key:
|
83
88
|
specification_version: 4
|
84
89
|
summary: Muack -- A fast, small, yet powerful mocking library.
|
85
90
|
test_files:
|
86
91
|
- test/test_any_instance_of.rb
|
87
92
|
- test/test_coat.rb
|
88
93
|
- test/test_from_readme.rb
|
94
|
+
- test/test_keyargs.rb
|
89
95
|
- test/test_mock.rb
|
90
96
|
- test/test_modifier.rb
|
97
|
+
- test/test_prepend.rb
|
91
98
|
- test/test_proxy.rb
|
92
|
-
- test/
|
99
|
+
- test/test_satisfying.rb
|
100
|
+
- test/test_spy.rb
|
93
101
|
- test/test_stub.rb
|
102
|
+
- test/test_visibility.rb
|