muack 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitmodules +3 -0
- data/.travis.yml +11 -0
- data/CHANGES.md +5 -0
- data/Gemfile +7 -0
- data/LICENSE +201 -0
- data/README.md +494 -0
- data/Rakefile +18 -0
- data/lib/muack.rb +77 -0
- data/lib/muack/any_instance_of.rb +4 -0
- data/lib/muack/definition.rb +5 -0
- data/lib/muack/failure.rb +38 -0
- data/lib/muack/mock.rb +167 -0
- data/lib/muack/modifier.rb +29 -0
- data/lib/muack/proxy.rb +39 -0
- data/lib/muack/satisfy.rb +54 -0
- data/lib/muack/session.rb +12 -0
- data/lib/muack/stub.rb +22 -0
- data/lib/muack/test.rb +26 -0
- data/lib/muack/version.rb +4 -0
- data/muack.gemspec +53 -0
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +268 -0
- data/test/test_any_instance_of.rb +30 -0
- data/test/test_mock.rb +170 -0
- data/test/test_proxy.rb +77 -0
- data/test/test_readme.rb +16 -0
- data/test/test_satisfy.rb +200 -0
- data/test/test_stub.rb +62 -0
- metadata +85 -0
data/test/test_proxy.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
|
2
|
+
require 'muack/test'
|
3
|
+
|
4
|
+
describe Muack::Proxy do
|
5
|
+
describe 'Muack.verify==true' do
|
6
|
+
after do
|
7
|
+
Muack.verify.should.eq true
|
8
|
+
Muack::EnsureReset.call
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'proxy with regular method' do
|
12
|
+
mock_proxy(Str).reverse
|
13
|
+
Str.reverse.should.eq 'ooM'
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'proxy multiple times' do
|
17
|
+
2.times{ mock_proxy(Str).reverse }
|
18
|
+
2.times{ Str.reverse.should.eq 'ooM' }
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'proxy multiple times with super method' do
|
22
|
+
2.times{ mock_proxy(Str).class }
|
23
|
+
2.times{ Str.class.should.eq String }
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'proxy and call the block' do
|
27
|
+
mock_proxy(Obj).method_missing(:inspect){ |str| str.reverse }
|
28
|
+
Obj.inspect.should.eq 'jbo'
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'proxy and call the block with super' do
|
32
|
+
mock_proxy(Str).class{ |k| k.name.reverse }
|
33
|
+
Str.class.should.eq 'gnirtS'
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'mock_proxy and call, mock_proxy and call' do
|
37
|
+
mock_proxy(Obj).class{ |k| k.name.reverse }
|
38
|
+
Obj.class.should.eq 'tcejbO'
|
39
|
+
mock_proxy(Obj).class{ |k| k.name.upcase }
|
40
|
+
Obj.class.should.eq 'OBJECT'
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'stub_proxy and call, stub_proxy and call' do
|
44
|
+
stub_proxy(Obj).kind_of?(Object){ |b| !b }
|
45
|
+
Obj.kind_of?(Object).should.eq false
|
46
|
+
stub_proxy(Obj).kind_of?(String){ |b| b.to_s }
|
47
|
+
Obj.kind_of?(String).should.eq 'false'
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'stub_proxy with any times' do
|
51
|
+
stub_proxy(Obj).class{ |k| k.name.downcase }
|
52
|
+
3.times{ Obj.class.should.eq 'object' }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'Muack.verify==false' do
|
57
|
+
after do
|
58
|
+
Muack.reset
|
59
|
+
Muack::EnsureReset.call
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'raise Muack::Expected error if passing unexpected argument' do
|
63
|
+
mock_proxy(Str).reverse
|
64
|
+
Str.reverse.should.eq 'ooM'
|
65
|
+
begin
|
66
|
+
Str.reverse
|
67
|
+
'never'.should.eq 'reach'
|
68
|
+
rescue Muack::Expected => e
|
69
|
+
e.expected .should.eq '"Moo".reverse()'
|
70
|
+
e.expected_times.should.eq 1
|
71
|
+
e.actual_times .should.eq 2
|
72
|
+
e.message .should.eq "\nExpected: \"Moo\".reverse()\n " \
|
73
|
+
"called 1 times\n but was 2 times."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/test_readme.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'bacon'
|
3
|
+
require 'muack'
|
4
|
+
|
5
|
+
include Muack::API
|
6
|
+
|
7
|
+
describe 'Hello' do
|
8
|
+
before{ Muack.reset }
|
9
|
+
after { Muack.verify }
|
10
|
+
|
11
|
+
should 'say world!' do
|
12
|
+
str = 'Hello'
|
13
|
+
mock(str).say('!'){ |arg| "World#{arg}" }
|
14
|
+
str.say('!').should.equal 'World!'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
|
2
|
+
require 'muack/test'
|
3
|
+
|
4
|
+
describe Muack::Satisfy do
|
5
|
+
describe Muack::IsA do
|
6
|
+
should 'have human readable to_s and inspect' do
|
7
|
+
matcher = is_a(String)
|
8
|
+
expected = 'Muack::API.is_a(String)'
|
9
|
+
matcher.to_s .should.eq expected
|
10
|
+
matcher.inspect.should.eq expected
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'satisfy' do
|
14
|
+
mock(Str).say(is_a(String)){ |arg| arg.reverse }
|
15
|
+
Str.say('Foo').should.eq 'ooF'
|
16
|
+
Muack.verify.should.eq true
|
17
|
+
Muack::EnsureReset.call
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
21
|
+
mock(Obj).say(is_a(Array)){ 'boo' }
|
22
|
+
begin
|
23
|
+
Obj.say(false)
|
24
|
+
'never'.should.eq 'reach'
|
25
|
+
rescue Muack::Unexpected => e
|
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
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Muack::Anything do
|
37
|
+
should 'have human readable to_s and inspect' do
|
38
|
+
matcher = anything
|
39
|
+
expected = 'Muack::API.anything()'
|
40
|
+
matcher.to_s .should.eq expected
|
41
|
+
matcher.inspect.should.eq expected
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'satisfy' do
|
45
|
+
mock(Str).say(anything){ |arg| arg*2 }
|
46
|
+
Str.say(5).should.eq 10
|
47
|
+
Muack.verify.should.eq true
|
48
|
+
|
49
|
+
mock(Str).say(anything){ |arg| arg.upcase }
|
50
|
+
Str.say('b').should.eq 'B'
|
51
|
+
|
52
|
+
Muack.verify.should.eq true
|
53
|
+
Muack::EnsureReset.call
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
57
|
+
mock(Obj).say(anything){ 'boo' }
|
58
|
+
begin
|
59
|
+
Obj.say(6, 7)
|
60
|
+
'never'.should.eq 'reach'
|
61
|
+
rescue Muack::Unexpected => e
|
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
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Muack::Match do
|
73
|
+
should 'have human readable to_s and inspect' do
|
74
|
+
matcher = match(/\w/)
|
75
|
+
expected = 'Muack::API.match(/\w/)'
|
76
|
+
matcher.to_s .should.eq expected
|
77
|
+
matcher.inspect.should.eq expected
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'satisfy' do
|
81
|
+
mock(Str).say(match(/\w/)){ |arg| arg }
|
82
|
+
Str.say('aa').should.eq 'aa'
|
83
|
+
Muack.verify.should.eq true
|
84
|
+
Muack::EnsureReset.call
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
88
|
+
mock(Obj).say(match(/\w/)){ 'boo' }
|
89
|
+
begin
|
90
|
+
Obj.say('!')
|
91
|
+
'never'.should.eq 'reach'
|
92
|
+
rescue Muack::Unexpected => e
|
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
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe Muack::HashIncluding do
|
104
|
+
should 'have human readable to_s and inspect' do
|
105
|
+
matcher = hash_including(:b => 2)
|
106
|
+
expected = 'Muack::API.hash_including({:b=>2})'
|
107
|
+
matcher.to_s .should.eq expected
|
108
|
+
matcher.inspect.should.eq expected
|
109
|
+
end
|
110
|
+
|
111
|
+
should 'satisfy' do
|
112
|
+
mock(Str).say(hash_including(:b => 2)){ |arg| arg[:a] }
|
113
|
+
Str.say(:a => 1, :b => 2).should.eq 1
|
114
|
+
Muack.verify.should.eq true
|
115
|
+
Muack::EnsureReset.call
|
116
|
+
end
|
117
|
+
|
118
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
119
|
+
mock(Obj).say(hash_including(:b => 2)){ 'boo' }
|
120
|
+
begin
|
121
|
+
Obj.say(:a => 1)
|
122
|
+
'never'.should.eq 'reach'
|
123
|
+
rescue Muack::Unexpected => e
|
124
|
+
e.expected.should.eq 'obj.say(Muack::API.hash_including({:b=>2}))'
|
125
|
+
e.was .should.eq 'obj.say({:a=>1})'
|
126
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
127
|
+
ensure
|
128
|
+
Muack.reset
|
129
|
+
Muack::EnsureReset.call
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe Muack::Within do
|
135
|
+
should 'have human readable to_s and inspect' do
|
136
|
+
matcher = within(0..9)
|
137
|
+
expected = 'Muack::API.within(0..9)'
|
138
|
+
matcher.to_s .should.eq expected
|
139
|
+
matcher.inspect.should.eq expected
|
140
|
+
end
|
141
|
+
|
142
|
+
should 'satisfy' do
|
143
|
+
mock(Str).say(within(0..9)){ |arg| arg*2 }
|
144
|
+
Str.say(5).should.eq 10
|
145
|
+
Muack.verify.should.eq true
|
146
|
+
|
147
|
+
mock(Str).say(within(%[a b])){ |arg| arg.upcase }
|
148
|
+
Str.say('b').should.eq 'B'
|
149
|
+
|
150
|
+
Muack.verify.should.eq true
|
151
|
+
Muack::EnsureReset.call
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
155
|
+
mock(Obj).say(within(0..5)){ 'boo' }
|
156
|
+
begin
|
157
|
+
Obj.say(6)
|
158
|
+
'never'.should.eq 'reach'
|
159
|
+
rescue Muack::Unexpected => e
|
160
|
+
e.expected.should.eq 'obj.say(Muack::API.within(0..5))'
|
161
|
+
e.was .should.eq 'obj.say(6)'
|
162
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
163
|
+
ensure
|
164
|
+
Muack.reset
|
165
|
+
Muack::EnsureReset.call
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe Muack::Satisfy do
|
171
|
+
should 'have human readable to_s and inspect' do
|
172
|
+
matcher = satisfy{ |arg| arg % 2 == 0 }
|
173
|
+
expected = 'Muack::API.satisfy(#<Proc:'
|
174
|
+
matcher.to_s .should.start_with expected
|
175
|
+
matcher.inspect.should.start_with expected
|
176
|
+
end
|
177
|
+
|
178
|
+
should 'satisfy' do
|
179
|
+
mock(Str).say(satisfy{ |arg| arg % 2 == 0 }){ |arg| arg + 1 }
|
180
|
+
Str.say(14).should.eq 15
|
181
|
+
Muack.verify.should.eq true
|
182
|
+
Muack::EnsureReset.call
|
183
|
+
end
|
184
|
+
|
185
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
186
|
+
mock(Obj).say(satisfy{ |arg| arg % 2 == 0 }){ 'boo' }
|
187
|
+
begin
|
188
|
+
Obj.say(1)
|
189
|
+
'never'.should.eq 'reach'
|
190
|
+
rescue Muack::Unexpected => e
|
191
|
+
e.expected.should.start_with 'obj.say(Muack::API.satisfy(#<Proc:'
|
192
|
+
e.was .should.eq 'obj.say(1)'
|
193
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
194
|
+
ensure
|
195
|
+
Muack.reset
|
196
|
+
Muack::EnsureReset.call
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
data/test/test_stub.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require 'muack/test'
|
3
|
+
|
4
|
+
describe Muack::Stub do
|
5
|
+
describe 'Muack.verify==true' do
|
6
|
+
after do
|
7
|
+
Muack.verify.should.eq true
|
8
|
+
Muack::EnsureReset.call
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'stub with regular method' do
|
12
|
+
stub(Obj).say{ 'goo' }
|
13
|
+
3.times{ Obj.say.should.eq 'goo' }
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'stub with any arguments' do
|
17
|
+
stub(Str).say{ Str.sub('M', 'H') }.with_any_args
|
18
|
+
Str.say .should.eq 'Hoo'
|
19
|
+
Str.say(0) .should.eq 'Hoo'
|
20
|
+
Str.say(0, 1).should.eq 'Hoo'
|
21
|
+
Str.say(' ').should.eq 'Hoo'
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'accept block form' do
|
25
|
+
stub(Obj){ |o| o.say{0}; o.saya{1} }
|
26
|
+
Obj.saya.should.eq 1
|
27
|
+
Obj.say .should.eq 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'Muack.verify==false' do
|
32
|
+
after do
|
33
|
+
Muack.reset
|
34
|
+
Muack::EnsureReset.call
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'raise Muack::Unexpected error if passing unexpected argument' do
|
38
|
+
stub(Obj).say(true){ 'boo' }
|
39
|
+
begin
|
40
|
+
Obj.say(false)
|
41
|
+
'never'.should.eq 'reach'
|
42
|
+
rescue Muack::Unexpected => e
|
43
|
+
e.expected.should.eq 'obj.say(true)'
|
44
|
+
e.was .should.eq 'obj.say(false)'
|
45
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'give all alternatives' do
|
50
|
+
stub(Obj).say(0){ 'boo' }
|
51
|
+
stub(Obj).say(1){ 'moo' }
|
52
|
+
begin
|
53
|
+
Obj.say(false)
|
54
|
+
'never'.should.eq 'reach'
|
55
|
+
rescue Muack::Unexpected => e
|
56
|
+
e.expected.should.eq "obj.say(0)\n or: obj.say(1)"
|
57
|
+
e.was .should.eq 'obj.say(false)'
|
58
|
+
e.message .should.eq "\nExpected: #{e.expected}\n but was: #{e.was}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: muack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lin Jen-Shin (godfat)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
Muack -- Yet another mocking library.
|
15
|
+
|
16
|
+
Basically it's an [RR][] clone, but much faster under heavy use.
|
17
|
+
It's 32x times faster (750s vs 23s) for running [Rib][] tests.
|
18
|
+
|
19
|
+
[RR]: https://github.com/rr/rr
|
20
|
+
[Rib]: https://github.com/godfat/rib
|
21
|
+
email:
|
22
|
+
- godfat (XD) godfat.org
|
23
|
+
executables: []
|
24
|
+
extensions: []
|
25
|
+
extra_rdoc_files: []
|
26
|
+
files:
|
27
|
+
- .gitmodules
|
28
|
+
- .travis.yml
|
29
|
+
- CHANGES.md
|
30
|
+
- Gemfile
|
31
|
+
- LICENSE
|
32
|
+
- README.md
|
33
|
+
- Rakefile
|
34
|
+
- lib/muack.rb
|
35
|
+
- lib/muack/any_instance_of.rb
|
36
|
+
- lib/muack/definition.rb
|
37
|
+
- lib/muack/failure.rb
|
38
|
+
- lib/muack/mock.rb
|
39
|
+
- lib/muack/modifier.rb
|
40
|
+
- lib/muack/proxy.rb
|
41
|
+
- lib/muack/satisfy.rb
|
42
|
+
- lib/muack/session.rb
|
43
|
+
- lib/muack/stub.rb
|
44
|
+
- lib/muack/test.rb
|
45
|
+
- lib/muack/version.rb
|
46
|
+
- muack.gemspec
|
47
|
+
- task/.gitignore
|
48
|
+
- task/gemgem.rb
|
49
|
+
- test/test_any_instance_of.rb
|
50
|
+
- test/test_mock.rb
|
51
|
+
- test/test_proxy.rb
|
52
|
+
- test/test_readme.rb
|
53
|
+
- test/test_satisfy.rb
|
54
|
+
- test/test_stub.rb
|
55
|
+
homepage: https://github.com/godfat/muack
|
56
|
+
licenses:
|
57
|
+
- Apache License 2.0
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Muack -- Yet another mocking library.
|
79
|
+
test_files:
|
80
|
+
- test/test_any_instance_of.rb
|
81
|
+
- test/test_mock.rb
|
82
|
+
- test/test_proxy.rb
|
83
|
+
- test/test_readme.rb
|
84
|
+
- test/test_satisfy.rb
|
85
|
+
- test/test_stub.rb
|