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.
@@ -116,6 +116,7 @@ module Muack
116
116
  end
117
117
 
118
118
  class Where < Satisfying
119
+ None = Object.new
119
120
  def initialize spec
120
121
  super([spec])
121
122
  end
@@ -123,9 +124,9 @@ module Muack
123
124
  def match actual_arg, spec=api_args.first
124
125
  case spec
125
126
  when Hash
126
- match_hash(actual_arg, spec)
127
+ actual_arg.kind_of?(Hash) && match_hash(actual_arg, spec)
127
128
  when Array
128
- match_array(actual_arg, spec)
129
+ actual_arg.kind_of?(Array) && match_array(actual_arg, spec)
129
130
  else
130
131
  raise UnknownSpec.new(spec)
131
132
  end
@@ -134,7 +135,7 @@ module Muack
134
135
  private
135
136
  def match_hash actual_arg, spec
136
137
  (spec.keys | actual_arg.keys).all? do |key|
137
- match_value(actual_arg[key], spec[key])
138
+ match_value(actual_arg, spec, key)
138
139
  end
139
140
  end
140
141
 
@@ -144,16 +145,24 @@ module Muack
144
145
  end
145
146
  end
146
147
 
147
- def match_value av, ev
148
- case ev
148
+ def match_value av, ev, key=None
149
+ if key == None
150
+ a, e = av, ev
151
+ elsif av.key?(key) && ev.key?(key)
152
+ a, e = av[key], ev[key]
153
+ else
154
+ return false
155
+ end
156
+
157
+ case e
149
158
  when Satisfying
150
- ev.match(av)
159
+ e.match(a)
151
160
  when Hash
152
- match_hash(av, ev)
161
+ a.kind_of?(Hash) && match_hash(a, e)
153
162
  when Array
154
- match_array(av, ev)
163
+ a.kind_of?(Array) && match_array(a, e)
155
164
  else
156
- ev == av
165
+ e == a
157
166
  end
158
167
  end
159
168
  end
@@ -166,7 +175,7 @@ module Muack
166
175
  private
167
176
  def match_hash actual_arg, subset
168
177
  subset.each_key.all? do |key|
169
- match_value(actual_arg[key], subset[key])
178
+ match_value(actual_arg, subset, key)
170
179
  end
171
180
  end
172
181
  end
@@ -179,7 +188,7 @@ module Muack
179
188
  private
180
189
  def match_hash actual_arg, superset
181
190
  actual_arg.each_key.all? do |key|
182
- match_value(actual_arg[key], superset[key])
191
+ match_value(actual_arg, superset, key)
183
192
  end
184
193
  end
185
194
  end
@@ -10,10 +10,8 @@ module Muack
10
10
 
11
11
  # used for Muack::Session#verify
12
12
  def __mock_verify
13
- @stub.__mock_disps.values.flatten.each do |defi|
14
- __mock_dispatch(defi.msg, defi.args) if __mock_defis.key?(defi.msg)
15
- end
16
- super # simulate dispatching before passing to mock to verify
13
+ __mock_dispatch_spy
14
+ super
17
15
  end
18
16
 
19
17
  # used for Muack::Session#reset, but spies never leave any track
@@ -21,5 +19,21 @@ module Muack
21
19
 
22
20
  private
23
21
  def __mock_inject_method defi; end # spies don't leave any track
22
+
23
+ # simulate dispatching before passing to mock to verify
24
+ def __mock_dispatch_spy
25
+ @stub.__mock_disps.values.flatten.each do |disp|
26
+ next unless __mock_defis.key?(disp.msg) # ignore undefined spies
27
+
28
+ defis = __mock_defis[disp.msg]
29
+ if idx = __mock_find_checked_difi(defis, disp, :index)
30
+ __mock_disps_push(defis.delete_at(idx)) # found, dispatch it
31
+ elsif defis.empty? # show called candidates
32
+ __mock_failed(disp)
33
+ else # show expected candidates
34
+ __mock_failed(disp, defis)
35
+ end
36
+ end
37
+ end
24
38
  end
25
39
  end
@@ -14,15 +14,16 @@ module Muack
14
14
  end
15
15
 
16
16
  # used for mocked object to dispatch mocked method
17
- def __mock_dispatch msg, actual_args
18
- if defi = __mock_defis[msg].find{ |d|
19
- __mock_check_args(d.args, actual_args) }
17
+ def __mock_dispatch actual_call
18
+ defis = __mock_defis[actual_call.msg]
19
+
20
+ if disp = __mock_find_checked_difi(defis, actual_call)
20
21
  # our spies are interested in this
21
- __mock_disps_push(Definition.new(msg, actual_args))
22
- defi
22
+ __mock_disps_push(actual_call)
23
+ disp
23
24
  else
24
25
  Mock.__send__(:raise, # Wrong argument
25
- Unexpected.new(object, __mock_defis[msg], msg, actual_args))
26
+ Unexpected.new(object, defis, actual_call))
26
27
  end
27
28
  end
28
29
  end
@@ -2,20 +2,51 @@
2
2
  require 'pork/auto'
3
3
  require 'muack'
4
4
 
5
- Pork::Executor.__send__(:include, Muack::API)
5
+ Pork::Suite.include(Muack::API)
6
6
 
7
- Obj = Object.new
8
- Str = 'Moo'
9
- def Obj.inspect
10
- 'obj'
11
- end
12
- def Obj.private
13
- 'pri'
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
- def Obj.aloha a=0, b=1
16
- [a, b]
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|
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '1.3.0'
3
+ VERSION = '1.5.1'
4
4
  end
@@ -1,62 +1,72 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: muack 1.3.0 ruby lib
2
+ # stub: muack 1.5.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "muack"
6
- s.version = "1.3.0"
5
+ s.name = "muack".freeze
6
+ s.version = "1.5.1"
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 = "2015-05-24"
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-12-06"
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/coat.rb",
27
- "lib/muack/definition.rb",
28
- "lib/muack/error.rb",
29
- "lib/muack/failure.rb",
30
- "lib/muack/mock.rb",
31
- "lib/muack/modifier.rb",
32
- "lib/muack/satisfying.rb",
33
- "lib/muack/session.rb",
34
- "lib/muack/spy.rb",
35
- "lib/muack/stub.rb",
36
- "lib/muack/test.rb",
37
- "lib/muack/version.rb",
38
- "muack.gemspec",
39
- "task/README.md",
40
- "task/gemgem.rb",
41
- "test/test_any_instance_of.rb",
42
- "test/test_coat.rb",
43
- "test/test_from_readme.rb",
44
- "test/test_mock.rb",
45
- "test/test_modifier.rb",
46
- "test/test_proxy.rb",
47
- "test/test_satisfying.rb",
48
- "test/test_stub.rb"]
49
- s.homepage = "https://github.com/godfat/muack"
50
- s.licenses = ["Apache License 2.0"]
51
- s.rubygems_version = "2.4.7"
52
- s.summary = "Muack -- A fast, small, yet powerful mocking library."
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
53
59
  s.test_files = [
54
- "test/test_any_instance_of.rb",
55
- "test/test_coat.rb",
56
- "test/test_from_readme.rb",
57
- "test/test_mock.rb",
58
- "test/test_modifier.rb",
59
- "test/test_proxy.rb",
60
- "test/test_satisfying.rb",
61
- "test/test_stub.rb"]
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]
62
72
  end
@@ -4,16 +4,16 @@
4
4
 
5
5
  Provided tasks:
6
6
 
7
- rake clean # Remove ignored files
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 in memory
12
+ rake test # Run tests
13
13
 
14
14
  ## REQUIREMENTS:
15
15
 
16
- * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
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 "#{dir = File.dirname(__FILE__)}/task/gemgem"
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(dir) do |s|
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-2013, Lin Jen-Shin (godfat)
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.
@@ -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 = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
31
+ s.license = license
30
32
 
31
33
  s.date = Time.now.strftime('%Y-%m-%d')
32
34
  s.files = gem_files
@@ -79,6 +81,11 @@ module Gemgem
79
81
  end
80
82
 
81
83
  def gem_check
84
+ unless git('status', '--porcelain').empty?
85
+ puts("\e[35mWorking copy is not clean.\e[0m")
86
+ exit(3)
87
+ end
88
+
82
89
  ver = spec.version.to_s
83
90
 
84
91
  if ENV['VERSION'].nil?
@@ -110,6 +117,7 @@ module Gemgem
110
117
  SimpleCov.start do
111
118
  add_filter('test/')
112
119
  add_filter('test.rb')
120
+ submodules_libs.each(&method(:add_filter))
113
121
  end
114
122
  end
115
123
 
@@ -154,11 +162,15 @@ module Gemgem
154
162
  end
155
163
 
156
164
  def strip_home_path path
157
- path.sub(ENV['HOME'], '~')
165
+ path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
158
166
  end
159
167
 
160
168
  def strip_cwd_path path
161
- 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" }
162
174
  end
163
175
 
164
176
  def git *args
@@ -196,6 +208,11 @@ module Gemgem
196
208
  @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
197
209
  end
198
210
 
211
+ def license
212
+ readme['LICENSE'].sub(/.+\n\n/, '').lines.first.
213
+ split(/[()]/).map(&:strip).reject(&:empty?).last
214
+ end
215
+
199
216
  def all_files
200
217
  @all_files ||= fold_files(glob).sort
201
218
  end
@@ -216,7 +233,8 @@ module Gemgem
216
233
 
217
234
  def gem_files
218
235
  @gem_files ||= all_files.reject{ |f|
219
- f =~ ignored_pattern && !git_files.include?(f)
236
+ f =~ submodules_pattern ||
237
+ (f =~ ignored_pattern && !git_files.include?(f))
220
238
  }
221
239
  end
222
240
 
@@ -248,6 +266,15 @@ module Gemgem
248
266
  end
249
267
  end
250
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
+
251
278
  def expand_patterns pathes
252
279
  # http://git-scm.com/docs/gitignore
253
280
  pathes.flat_map{ |path|