muack 1.4.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 +12 -0
- data/Gemfile +0 -4
- data/README.md +17 -16
- 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 +123 -65
- data/lib/muack/spy.rb +3 -3
- data/lib/muack/stub.rb +7 -5
- data/lib/muack/test.rb +42 -11
- data/lib/muack/version.rb +1 -1
- data/muack.gemspec +65 -57
- data/task/README.md +8 -8
- data/task/gemgem.rb +29 -7
- data/test/test_any_instance_of.rb +16 -2
- data/test/test_from_readme.rb +5 -7
- 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_satisfying.rb +12 -12
- data/test/test_spy.rb +4 -4
- data/test/test_visibility.rb +120 -0
- metadata +15 -8
data/lib/muack/spy.rb
CHANGED
@@ -26,12 +26,12 @@ module Muack
|
|
26
26
|
next unless __mock_defis.key?(disp.msg) # ignore undefined spies
|
27
27
|
|
28
28
|
defis = __mock_defis[disp.msg]
|
29
|
-
if idx = __mock_find_checked_difi(defis, disp
|
29
|
+
if idx = __mock_find_checked_difi(defis, disp, :index)
|
30
30
|
__mock_disps_push(defis.delete_at(idx)) # found, dispatch it
|
31
31
|
elsif defis.empty? # show called candidates
|
32
|
-
__mock_failed(disp
|
32
|
+
__mock_failed(disp)
|
33
33
|
else # show expected candidates
|
34
|
-
__mock_failed(disp
|
34
|
+
__mock_failed(disp, defis)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/muack/stub.rb
CHANGED
@@ -14,14 +14,16 @@ module Muack
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# used for mocked object to dispatch mocked method
|
17
|
-
def __mock_dispatch
|
18
|
-
|
17
|
+
def __mock_dispatch actual_call
|
18
|
+
defis = __mock_defis[actual_call.msg]
|
19
|
+
|
20
|
+
if disp = __mock_find_checked_difi(defis, actual_call)
|
19
21
|
# our spies are interested in this
|
20
|
-
__mock_disps_push(
|
21
|
-
|
22
|
+
__mock_disps_push(actual_call)
|
23
|
+
disp
|
22
24
|
else
|
23
25
|
Mock.__send__(:raise, # Wrong argument
|
24
|
-
Unexpected.new(object,
|
26
|
+
Unexpected.new(object, defis, actual_call))
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/muack/test.rb
CHANGED
@@ -2,20 +2,51 @@
|
|
2
2
|
require 'pork/auto'
|
3
3
|
require 'muack'
|
4
4
|
|
5
|
-
Pork::
|
5
|
+
Pork::Suite.include(Muack::API)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
end
|
12
|
-
def
|
13
|
-
|
7
|
+
Str = String.new('Moo')
|
8
|
+
class Cls
|
9
|
+
def inspect
|
10
|
+
'obj'
|
11
|
+
end
|
12
|
+
def aloha a=0, b=1
|
13
|
+
[a, b]
|
14
|
+
end
|
15
|
+
def bonjour a: 0, b: 1
|
16
|
+
[a, b]
|
17
|
+
end
|
18
|
+
def ciao h={a: 0, b: 1}
|
19
|
+
h.values_at(:a, :b)
|
20
|
+
end
|
21
|
+
module Prepend
|
22
|
+
def prepend_aloha a=0, b=1
|
23
|
+
[a, b]
|
24
|
+
end
|
25
|
+
def prepend_bonjour a: 0, b: 1
|
26
|
+
[a, b]
|
27
|
+
end
|
28
|
+
def prepend_ciao h={a: 0, b: 1}
|
29
|
+
h.values_at(:a, :b)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
prepend Prepend
|
14
33
|
end
|
15
|
-
|
16
|
-
|
34
|
+
Obj = Cls.new
|
35
|
+
class << Obj
|
36
|
+
private def private
|
37
|
+
'pri'
|
38
|
+
end
|
39
|
+
|
40
|
+
def single_aloha a=0, b=1
|
41
|
+
[a, b]
|
42
|
+
end
|
43
|
+
def single_bonjour a: 0, b: 1
|
44
|
+
[a, b]
|
45
|
+
end
|
46
|
+
def single_ciao h={a: 0, b: 1}
|
47
|
+
h.values_at(:a, :b)
|
48
|
+
end
|
17
49
|
end
|
18
|
-
Obj.singleton_class.__send__(:private, :private)
|
19
50
|
|
20
51
|
Muack::EnsureReset = lambda{
|
21
52
|
[Obj, Str].each do |o|
|
data/lib/muack/version.rb
CHANGED
data/muack.gemspec
CHANGED
@@ -1,64 +1,72 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: muack 1.
|
2
|
+
# stub: muack 1.5.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name = "muack"
|
6
|
-
s.version = "1.
|
5
|
+
s.name = "muack".freeze
|
6
|
+
s.version = "1.5.0"
|
7
7
|
|
8
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
-
s.require_paths = ["lib"]
|
10
|
-
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "
|
12
|
-
s.description = "Muack -- A fast, small, yet powerful mocking library.\n\nInspired by [RR][], and it's 32x times faster (750s vs 23s) than RR\nfor running [Rib][] tests.\n\n[RR]: https://github.com/rr/rr\n[Rib]: https://github.com/godfat/rib"
|
13
|
-
s.email = ["godfat (XD) godfat.org"]
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["Lin Jen-Shin (godfat)".freeze]
|
11
|
+
s.date = "2020-11-28"
|
12
|
+
s.description = "Muack -- A fast, small, yet powerful mocking library.\n\nInspired by [RR][], and it's 32x times faster (750s vs 23s) than RR\nfor running [Rib][] tests.\n\n[RR]: https://github.com/rr/rr\n[Rib]: https://github.com/godfat/rib".freeze
|
13
|
+
s.email = ["godfat (XD) godfat.org".freeze]
|
14
14
|
s.files = [
|
15
|
-
".gitignore",
|
16
|
-
".gitmodules",
|
17
|
-
".travis.yml",
|
18
|
-
"CHANGES.md",
|
19
|
-
"Gemfile",
|
20
|
-
"LICENSE",
|
21
|
-
"README.md",
|
22
|
-
"Rakefile",
|
23
|
-
"lib/muack.rb",
|
24
|
-
"lib/muack/any_instance_of.rb",
|
25
|
-
"lib/muack/block.rb",
|
26
|
-
"lib/muack/
|
27
|
-
"lib/muack/
|
28
|
-
"lib/muack/
|
29
|
-
"lib/muack/
|
30
|
-
"lib/muack/
|
31
|
-
"lib/muack/
|
32
|
-
"lib/muack/
|
33
|
-
"lib/muack/
|
34
|
-
"lib/muack/
|
35
|
-
"lib/muack/
|
36
|
-
"lib/muack/
|
37
|
-
"lib/muack/
|
38
|
-
"muack.
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"test/
|
44
|
-
"test/
|
45
|
-
"test/
|
46
|
-
"test/
|
47
|
-
"test/
|
48
|
-
"test/
|
49
|
-
"test/
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
15
|
+
".gitignore".freeze,
|
16
|
+
".gitmodules".freeze,
|
17
|
+
".travis.yml".freeze,
|
18
|
+
"CHANGES.md".freeze,
|
19
|
+
"Gemfile".freeze,
|
20
|
+
"LICENSE".freeze,
|
21
|
+
"README.md".freeze,
|
22
|
+
"Rakefile".freeze,
|
23
|
+
"lib/muack.rb".freeze,
|
24
|
+
"lib/muack/any_instance_of.rb".freeze,
|
25
|
+
"lib/muack/block.rb".freeze,
|
26
|
+
"lib/muack/block_26.rb".freeze,
|
27
|
+
"lib/muack/block_27.rb".freeze,
|
28
|
+
"lib/muack/coat.rb".freeze,
|
29
|
+
"lib/muack/definition.rb".freeze,
|
30
|
+
"lib/muack/error.rb".freeze,
|
31
|
+
"lib/muack/failure.rb".freeze,
|
32
|
+
"lib/muack/mock.rb".freeze,
|
33
|
+
"lib/muack/modifier.rb".freeze,
|
34
|
+
"lib/muack/satisfying.rb".freeze,
|
35
|
+
"lib/muack/session.rb".freeze,
|
36
|
+
"lib/muack/spy.rb".freeze,
|
37
|
+
"lib/muack/stub.rb".freeze,
|
38
|
+
"lib/muack/test.rb".freeze,
|
39
|
+
"lib/muack/version.rb".freeze,
|
40
|
+
"muack.gemspec".freeze,
|
41
|
+
"task/README.md".freeze,
|
42
|
+
"task/gemgem.rb".freeze,
|
43
|
+
"test/test_any_instance_of.rb".freeze,
|
44
|
+
"test/test_coat.rb".freeze,
|
45
|
+
"test/test_from_readme.rb".freeze,
|
46
|
+
"test/test_keyargs.rb".freeze,
|
47
|
+
"test/test_mock.rb".freeze,
|
48
|
+
"test/test_modifier.rb".freeze,
|
49
|
+
"test/test_prepend.rb".freeze,
|
50
|
+
"test/test_proxy.rb".freeze,
|
51
|
+
"test/test_satisfying.rb".freeze,
|
52
|
+
"test/test_spy.rb".freeze,
|
53
|
+
"test/test_stub.rb".freeze,
|
54
|
+
"test/test_visibility.rb".freeze]
|
55
|
+
s.homepage = "https://github.com/godfat/muack".freeze
|
56
|
+
s.licenses = ["Apache-2.0".freeze]
|
57
|
+
s.rubygems_version = "3.1.4".freeze
|
58
|
+
s.summary = "Muack -- A fast, small, yet powerful mocking library.".freeze
|
54
59
|
s.test_files = [
|
55
|
-
"test/test_any_instance_of.rb",
|
56
|
-
"test/test_coat.rb",
|
57
|
-
"test/test_from_readme.rb",
|
58
|
-
"test/
|
59
|
-
"test/
|
60
|
-
"test/
|
61
|
-
"test/
|
62
|
-
"test/
|
63
|
-
"test/
|
60
|
+
"test/test_any_instance_of.rb".freeze,
|
61
|
+
"test/test_coat.rb".freeze,
|
62
|
+
"test/test_from_readme.rb".freeze,
|
63
|
+
"test/test_keyargs.rb".freeze,
|
64
|
+
"test/test_mock.rb".freeze,
|
65
|
+
"test/test_modifier.rb".freeze,
|
66
|
+
"test/test_prepend.rb".freeze,
|
67
|
+
"test/test_proxy.rb".freeze,
|
68
|
+
"test/test_satisfying.rb".freeze,
|
69
|
+
"test/test_spy.rb".freeze,
|
70
|
+
"test/test_stub.rb".freeze,
|
71
|
+
"test/test_visibility.rb".freeze]
|
64
72
|
end
|
data/task/README.md
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
|
5
5
|
Provided tasks:
|
6
6
|
|
7
|
-
rake clean #
|
7
|
+
rake clean # Trash ignored files
|
8
8
|
rake gem:build # Build gem
|
9
9
|
rake gem:install # Install gem
|
10
10
|
rake gem:release # Release gem
|
11
11
|
rake gem:spec # Generate gemspec
|
12
|
-
rake test # Run tests
|
12
|
+
rake test # Run tests
|
13
13
|
|
14
14
|
## REQUIREMENTS:
|
15
15
|
|
16
|
-
* Tested with MRI (official CRuby)
|
16
|
+
* Tested with MRI (official CRuby) and JRuby.
|
17
17
|
|
18
18
|
## INSTALLATION:
|
19
19
|
|
@@ -23,13 +23,13 @@ And in Rakefile:
|
|
23
23
|
|
24
24
|
``` ruby
|
25
25
|
begin
|
26
|
-
require "#{
|
26
|
+
require "#{__dir__}/task/gemgem"
|
27
27
|
rescue LoadError
|
28
|
-
sh 'git submodule update --init'
|
28
|
+
sh 'git submodule update --init --recursive'
|
29
29
|
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
30
|
end
|
31
31
|
|
32
|
-
Gemgem.init(
|
32
|
+
Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
|
33
33
|
s.name = 'your-gem'
|
34
34
|
s.version = '0.1.0'
|
35
35
|
end
|
@@ -37,9 +37,9 @@ end
|
|
37
37
|
|
38
38
|
## LICENSE:
|
39
39
|
|
40
|
-
Apache License 2.0
|
40
|
+
Apache License 2.0 (Apache-2.0)
|
41
41
|
|
42
|
-
Copyright (c) 2011-
|
42
|
+
Copyright (c) 2011-2019, Lin Jen-Shin (godfat)
|
43
43
|
|
44
44
|
Licensed under the Apache License, Version 2.0 (the "License");
|
45
45
|
you may not use this file except in compliance with the License.
|
data/task/gemgem.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Gemgem
|
3
3
|
class << self
|
4
|
-
attr_accessor :dir, :spec, :spec_create
|
4
|
+
attr_accessor :dir, :spec, :submodules, :spec_create
|
5
5
|
end
|
6
6
|
|
7
7
|
module_function
|
@@ -11,12 +11,14 @@ module Gemgem
|
|
11
11
|
def pkg_dir ; "#{dir}/pkg" ; end
|
12
12
|
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
13
|
|
14
|
-
def init dir, &block
|
14
|
+
def init dir, options={}, &block
|
15
15
|
self.dir = dir
|
16
|
-
$LOAD_PATH.unshift("#{dir}/lib")
|
17
16
|
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
17
|
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
18
|
+
self.submodules = options[:submodules] || []
|
19
19
|
self.spec_create = block
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
|
20
22
|
end
|
21
23
|
|
22
24
|
def create
|
@@ -26,7 +28,7 @@ module Gemgem
|
|
26
28
|
|
27
29
|
s.description = description.join
|
28
30
|
s.summary = description.first
|
29
|
-
s.license =
|
31
|
+
s.license = license
|
30
32
|
|
31
33
|
s.date = Time.now.strftime('%Y-%m-%d')
|
32
34
|
s.files = gem_files
|
@@ -115,6 +117,7 @@ module Gemgem
|
|
115
117
|
SimpleCov.start do
|
116
118
|
add_filter('test/')
|
117
119
|
add_filter('test.rb')
|
120
|
+
submodules_libs.each(&method(:add_filter))
|
118
121
|
end
|
119
122
|
end
|
120
123
|
|
@@ -159,11 +162,15 @@ module Gemgem
|
|
159
162
|
end
|
160
163
|
|
161
164
|
def strip_home_path path
|
162
|
-
path.sub(ENV['HOME']
|
165
|
+
path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
|
163
166
|
end
|
164
167
|
|
165
168
|
def strip_cwd_path path
|
166
|
-
path.sub(Dir.pwd
|
169
|
+
path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
|
170
|
+
end
|
171
|
+
|
172
|
+
def submodules_libs
|
173
|
+
submodules.map{ |path| "#{dir}/#{path}/lib" }
|
167
174
|
end
|
168
175
|
|
169
176
|
def git *args
|
@@ -201,6 +208,11 @@ module Gemgem
|
|
201
208
|
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
202
209
|
end
|
203
210
|
|
211
|
+
def license
|
212
|
+
readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
|
213
|
+
split(/[()]/).map(&:strip).reject(&:empty?).last
|
214
|
+
end
|
215
|
+
|
204
216
|
def all_files
|
205
217
|
@all_files ||= fold_files(glob).sort
|
206
218
|
end
|
@@ -221,7 +233,8 @@ module Gemgem
|
|
221
233
|
|
222
234
|
def gem_files
|
223
235
|
@gem_files ||= all_files.reject{ |f|
|
224
|
-
f =~
|
236
|
+
f =~ submodules_pattern ||
|
237
|
+
(f =~ ignored_pattern && !git_files.include?(f))
|
225
238
|
}
|
226
239
|
end
|
227
240
|
|
@@ -253,6 +266,15 @@ module Gemgem
|
|
253
266
|
end
|
254
267
|
end
|
255
268
|
|
269
|
+
def submodules_pattern
|
270
|
+
@submodules_pattern ||= if submodules.empty?
|
271
|
+
/^$/
|
272
|
+
else
|
273
|
+
Regexp.new(submodules.map{ |path|
|
274
|
+
"^#{Regexp.escape(path)}/" }.join('|'))
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
256
278
|
def expand_patterns pathes
|
257
279
|
# http://git-scm.com/docs/gitignore
|
258
280
|
pathes.flat_map{ |path|
|
@@ -57,8 +57,8 @@ describe Muack::AnyInstanceOf do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
would 'mock with multiple any_instance_of call' do
|
60
|
-
any_instance_of(klass){ |inst| mock(inst).f(is_a(
|
61
|
-
any_instance_of(klass){ |inst| mock(inst).f(is_a(
|
60
|
+
any_instance_of(klass){ |inst| mock(inst).f(is_a(Integer)){ |i| i+1 } }
|
61
|
+
any_instance_of(klass){ |inst| mock(inst).f(is_a(Integer)){ |i| i+2 } }
|
62
62
|
obj = klass.new
|
63
63
|
obj.f(2).should.eq 3
|
64
64
|
obj.f(2).should.eq 4
|
@@ -112,4 +112,18 @@ describe Muack::AnyInstanceOf do
|
|
112
112
|
|
113
113
|
obj.f.should.eq 0
|
114
114
|
end
|
115
|
+
|
116
|
+
# Brought from rspec-mocks and it's currently failing on rspec-mocks
|
117
|
+
would 'stub any_instance_of on module extending it self' do
|
118
|
+
mod = Module.new {
|
119
|
+
extend self
|
120
|
+
def hello; :hello; end
|
121
|
+
}
|
122
|
+
|
123
|
+
any_instance_of(mod){ |inst| stub(inst).hello{ :stub } }
|
124
|
+
|
125
|
+
expect(mod.hello).eq(:stub)
|
126
|
+
expect(Muack.verify)
|
127
|
+
expect(mod.hello).eq(:hello)
|
128
|
+
end
|
115
129
|
end
|
data/test/test_from_readme.rb
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
require 'muack/test'
|
3
3
|
|
4
4
|
describe 'from README.md' do
|
5
|
-
readme = File.read(
|
6
|
-
"#{File.dirname(File.expand_path(__FILE__))}/../README.md")
|
5
|
+
readme = File.read("#{__dir__}/../README.md")
|
7
6
|
codes = readme.scan(/``` ruby(.+?)```/m).map(&:first)
|
8
7
|
|
9
8
|
after{ Muack.reset }
|
@@ -12,15 +11,14 @@ describe 'from README.md' do
|
|
12
11
|
include Muack::API
|
13
12
|
|
14
13
|
def describe desc, &block
|
15
|
-
@
|
16
|
-
|
14
|
+
@suite.describe(desc, &block)
|
15
|
+
Pork::Executor.execute(:stat => @stat, :suite => @suite)
|
17
16
|
end
|
18
17
|
|
19
18
|
def results; @results ||= []; end
|
20
19
|
def p res ; results << res ; end
|
21
20
|
|
22
21
|
def verify expects
|
23
|
-
return if results.empty?
|
24
22
|
results.zip(expects).each do |(res, exp)|
|
25
23
|
next if exp == 'ok'
|
26
24
|
if exp.start_with?('raise')
|
@@ -34,10 +32,10 @@ describe 'from README.md' do
|
|
34
32
|
|
35
33
|
codes.each.with_index do |code, index|
|
36
34
|
would 'pass from README.md #%02d' % index do
|
37
|
-
|
35
|
+
suite, stat = Class.new(self.class){ init }, pork_stat
|
38
36
|
context = Module.new do
|
39
37
|
extend Context
|
40
|
-
@
|
38
|
+
@suite, @stat = suite, stat
|
41
39
|
end
|
42
40
|
begin
|
43
41
|
context.instance_eval(code, 'README.md', 0)
|