muack 1.6.0 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 012f658496e2711ec98bf468ffbb58ddfe339eafe03c4618e3cc9b91025b0b03
4
- data.tar.gz: 505dbe6462efb20502468cf75f23459afa4589a8cd9d5f5ebc24eaf9a4d004ea
3
+ metadata.gz: 87b3de29deb805feea133c6e8fc7b3fc2720334df701a59452acc3141fd63509
4
+ data.tar.gz: aeb2e74419effc23ca0d1b51de935308242fd0fa12e9dae6be064dc11cc7e8ea
5
5
  SHA512:
6
- metadata.gz: 9b538db391549b7da213ab0be7af6f58f71682277e897aae341285daecb47aad5bedfee581e0602908df4a5be55e5faa471d4bf8127a5cd68190058e22dc422c
7
- data.tar.gz: 2d3ca26974fa4b73f2dd394ccf0323ebb720a40f3f6c30c72736680f4399f714a4a141998abf799dc846c4f1e0d2d4e3716fb719a256cfd2dd3618a57572be27
6
+ metadata.gz: 0d67d586cb7005f3ec8fae297cf6e9bc7f669cc1853dc5c293b28858fb3b7f6134c7e373399f5135fb88ab3879122e8f6c61a653925a456bab3a53715549a3de
7
+ data.tar.gz: a6387f685b6db8c25e447027698de5f47cc8aea2abef864552bc2d3010e5c5f92e637df9dd08ab6bdb3692e40c598ad6c01b1c7fae4d4e59672e9f66eae6fcf9
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,40 @@
1
+
2
+ stages:
3
+ - test
4
+
5
+ .test:
6
+ stage: test
7
+ image: ruby:${RUBY_VERSION}-bullseye
8
+ variables:
9
+ GIT_DEPTH: "1"
10
+ GIT_SUBMODULE_STRATEGY: recursive
11
+ GIT_SUBMODULE_PATHS: task
12
+ RUBYOPT: --enable-frozen-string-literal
13
+ before_script:
14
+ - bundle install --retry=3
15
+ - unset CI # Coverage doesn't work well with frozen literal
16
+ script:
17
+ - ruby -vr bundler/setup -S rake test
18
+
19
+ ruby:3.0:
20
+ extends:
21
+ - .test
22
+ variables:
23
+ RUBY_VERSION: '3.0'
24
+
25
+ ruby:3.1:
26
+ extends:
27
+ - .test
28
+ variables:
29
+ RUBY_VERSION: '3.1'
30
+
31
+ ruby:3.2:
32
+ extends:
33
+ - .test
34
+ variables:
35
+ RUBY_VERSION: '3.2'
36
+
37
+ jruby:latest:
38
+ extends:
39
+ - .test
40
+ image: jruby:latest
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "task"]
2
2
  path = task
3
- url = git://github.com/godfat/gemgem.git
3
+ url = https://github.com/godfat/gemgem.git
data/CHANGES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGES
2
2
 
3
+ ## Muack 1.7.0 -- 2022-12-29
4
+
5
+ ### Incompatible changes
6
+
7
+ * Drop support for Ruby 2.6-
8
+
9
+ ### Bugs fixed
10
+
11
+ * Fixed stubbed instance method not following the original visibility.
12
+ It's always public before this fix.
13
+ * Worked around a few JRuby 9.4 compatibility issues. Note that there are
14
+ still some issues due to JRuby bugs. Those tests are currently skipped.
15
+
3
16
  ## Muack 1.6.0 -- 2020-12-06
4
17
 
5
18
  ### Enhancement
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Muack [![Build Status](https://secure.travis-ci.org/godfat/muack.png?branch=master)](http://travis-ci.org/godfat/muack) [![Coverage Status](https://coveralls.io/repos/github/godfat/muack/badge.png)](https://coveralls.io/github/godfat/muack) [![Join the chat at https://gitter.im/godfat/muack](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/muack)
1
+ # Muack [![Pipeline status](https://gitlab.com/godfat/muack/badges/master/pipeline.svg)](https://gitlab.com/godfat/muack/-/pipelines)
2
2
 
3
3
  by Lin Jen-Shin ([godfat](http://godfat.org))
4
4
 
@@ -1221,7 +1221,7 @@ Or, I am happy to break legacy.
1221
1221
 
1222
1222
  Apache License 2.0 (Apache-2.0)
1223
1223
 
1224
- Copyright (c) 2013-2020, Lin Jen-Shin (godfat)
1224
+ Copyright (c) 2013-2022, Lin Jen-Shin (godfat)
1225
1225
 
1226
1226
  Licensed under the Apache License, Version 2.0 (the "License");
1227
1227
  you may not use this file except in compliance with the License.
data/lib/muack/block.rb CHANGED
@@ -1,6 +1,16 @@
1
1
 
2
- if RUBY_VERSION < '2.7'
3
- require 'muack/block_26'
4
- else
5
- require 'muack/block_27'
2
+ module Muack
3
+ class Block < Struct.new(:block, :context)
4
+ def initialize block, context=nil
5
+ super
6
+ end
7
+
8
+ def call(...)
9
+ if context
10
+ context.instance_exec(...)
11
+ else
12
+ block.call(...)
13
+ end
14
+ end
15
+ end
6
16
  end
data/lib/muack/mock.rb CHANGED
@@ -131,36 +131,18 @@ module Muack
131
131
  end
132
132
  end
133
133
 
134
- if ::Class.instance_method(:method_defined?).arity == 1 # Ruby 2.5-
135
- def self.direct_method_defined? mod, msg
136
- mod.public_instance_methods(false).include?(msg) ||
137
- mod.protected_instance_methods(false).include?(msg) ||
138
- mod.private_instance_methods(false).include?(msg)
139
- end
140
-
141
- def self.method_visibility mod, msg
142
- if mod.public_instance_methods(false).include?(msg)
143
- :public
144
- elsif mod.protected_instance_methods(false).include?(msg)
145
- :protected
146
- elsif mod.private_instance_methods(false).include?(msg)
147
- :private
148
- end
149
- end
150
- else # Ruby 2.6+
151
- def self.direct_method_defined? mod, msg
152
- mod.method_defined?(msg, false) || # this doesn't cover private method
153
- mod.private_method_defined?(msg, false)
154
- end
134
+ def self.direct_method_defined? mod, msg
135
+ mod.method_defined?(msg, false) || # this doesn't cover private method
136
+ mod.private_method_defined?(msg, false)
137
+ end
155
138
 
156
- def self.method_visibility mod, msg
157
- if mod.public_method_defined?(msg, false)
158
- :public
159
- elsif mod.protected_method_defined?(msg, false)
160
- :protected
161
- elsif mod.private_method_defined?(msg, false)
162
- :private
163
- end
139
+ def self.method_visibility mod, msg, inherit=false
140
+ if mod.public_method_defined?(msg, inherit)
141
+ :public
142
+ elsif mod.protected_method_defined?(msg, inherit)
143
+ :protected
144
+ elsif mod.private_method_defined?(msg, inherit)
145
+ :private
164
146
  end
165
147
  end
166
148
 
@@ -191,11 +173,15 @@ module Muack
191
173
 
192
174
  def self.store_original_method mod, defi
193
175
  if visibility = method_visibility(mod, defi.msg)
176
+ # Defined in itself, we need to make alias
194
177
  original_method = find_new_name(mod, defi.msg)
195
178
  mod.__send__(:alias_method, original_method, defi.msg)
196
179
  defi.original_method = original_method
197
180
  defi.visibility = visibility
198
- else
181
+ elsif visibility = method_visibility(mod, defi.msg, true)
182
+ # Defined in parent, we can just override
183
+ defi.visibility = visibility
184
+ else # Not defined, pick a reasonable default
199
185
  defi.visibility = :public
200
186
  end
201
187
  end
@@ -292,12 +278,12 @@ module Muack
292
278
  ::Kernel.instance_method(:method).bind(object).call(method_name).
293
279
  super_method
294
280
 
295
- if super_method.owner == ::Class && super_method.name == :new
281
+ if super_method.owner.kind_of?(::Class) && super_method.name == :new
296
282
  initialize_method = ::Class.instance_method(:instance_method).
297
283
  bind(object).call(:initialize)
298
284
  __mock_block_with_kargs?(initialize_method)
299
285
  else
300
- super_method && __mock_block_with_kargs?(super_method)
286
+ __mock_block_with_kargs?(super_method)
301
287
  end
302
288
  end
303
289
 
data/lib/muack/session.rb CHANGED
@@ -22,6 +22,10 @@ module Muack
22
22
  def verify obj=nil
23
23
  if obj
24
24
  with(obj, :[]).all?(&:__mock_verify)
25
+ elsif RUBY_ENGINE == 'jruby'
26
+ # Workaround weird error:
27
+ # TypeError: Muack::Stub#to_ary should return Array
28
+ data.each_value.all?{ |v| v.__mock_verify }
25
29
  else
26
30
  data.each_value.all?(&:__mock_verify)
27
31
  end
data/lib/muack/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Muack
3
- VERSION = '1.6.0'
3
+ VERSION = '1.7.0'
4
4
  end
data/muack.gemspec CHANGED
@@ -1,20 +1,20 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: muack 1.6.0 ruby lib
2
+ # stub: muack 1.7.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "muack".freeze
6
- s.version = "1.6.0"
6
+ s.version = "1.7.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
- s.date = "2020-12-06"
11
+ s.date = "2022-12-29"
12
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
13
  s.email = ["godfat (XD) godfat.org".freeze]
14
14
  s.files = [
15
15
  ".gitignore".freeze,
16
+ ".gitlab-ci.yml".freeze,
16
17
  ".gitmodules".freeze,
17
- ".travis.yml".freeze,
18
18
  "CHANGES.md".freeze,
19
19
  "Gemfile".freeze,
20
20
  "LICENSE".freeze,
@@ -23,8 +23,6 @@ Gem::Specification.new do |s|
23
23
  "lib/muack.rb".freeze,
24
24
  "lib/muack/any_instance_of.rb".freeze,
25
25
  "lib/muack/block.rb".freeze,
26
- "lib/muack/block_26.rb".freeze,
27
- "lib/muack/block_27.rb".freeze,
28
26
  "lib/muack/coat.rb".freeze,
29
27
  "lib/muack/definition.rb".freeze,
30
28
  "lib/muack/error.rb".freeze,
@@ -54,7 +52,7 @@ Gem::Specification.new do |s|
54
52
  "test/test_visibility.rb".freeze]
55
53
  s.homepage = "https://github.com/godfat/muack".freeze
56
54
  s.licenses = ["Apache-2.0".freeze]
57
- s.rubygems_version = "3.1.4".freeze
55
+ s.rubygems_version = "3.4.1".freeze
58
56
  s.summary = "Muack -- A fast, small, yet powerful mocking library.".freeze
59
57
  s.test_files = [
60
58
  "test/test_any_instance_of.rb".freeze,
data/task/README.md CHANGED
@@ -39,7 +39,7 @@ end
39
39
 
40
40
  Apache License 2.0 (Apache-2.0)
41
41
 
42
- Copyright (c) 2011-2019, Lin Jen-Shin (godfat)
42
+ Copyright (c) 2011-2021, 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
@@ -42,6 +42,7 @@ module Gemgem
42
42
 
43
43
  def gem_install
44
44
  require 'rubygems/commands/install_command'
45
+ require 'rubygems/package'
45
46
  # read ~/.gemrc
46
47
  Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
47
48
  Gem::Command.extra_args = Gem.configuration[:gem]
@@ -51,7 +52,8 @@ module Gemgem
51
52
  cmd.handle_options([])
52
53
 
53
54
  # install
54
- install = Gem::Installer.new(gem_path, cmd.options)
55
+ gem_package = Gem::Package.new(gem_path)
56
+ install = Gem::Installer.new(gem_package, cmd.options)
55
57
  install.install
56
58
  puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
57
59
  end
@@ -113,6 +113,17 @@ describe Muack::AnyInstanceOf do
113
113
  obj.f.should.eq 0
114
114
  end
115
115
 
116
+ describe 'mock any_instance_of on a method defined higher up' do
117
+ methods_count = klass.instance_methods.size
118
+
119
+ would 'not store a backup method' do
120
+ any_instance_of(klass){ |inst| mock(inst).to_s{ 'to_s' } }
121
+
122
+ expect(klass.new.to_s).eq 'to_s'
123
+ expect(klass.instance_methods.size).eq methods_count
124
+ end
125
+ end
126
+
116
127
  # Brought from rspec-mocks and it's currently failing on rspec-mocks
117
128
  would 'stub any_instance_of on module extending it self' do
118
129
  mod = Module.new {
data/test/test_keyargs.rb CHANGED
@@ -50,6 +50,9 @@ describe Muack::Mock do
50
50
  end
51
51
 
52
52
  would 'instance method' do
53
+ # https://github.com/jruby/jruby/issues/7545
54
+ skip if RUBY_ENGINE == 'jruby' && obj.kind_of?(Muack::AnyInstanceOf)
55
+
53
56
  mock(obj).bonjour(a: 0, b: 1)
54
57
 
55
58
  expect(instance.bonjour(a: 0, b: 1)).eq([0, 1])
data/test/test_mock.rb CHANGED
@@ -244,12 +244,12 @@ describe Muack::Mock do
244
244
  end
245
245
 
246
246
  would 'any_instance_of m1' do
247
- skip
247
+ skip if RUBY_ENGINE == 'jruby'
248
248
 
249
249
  mock(any_instance_of(@m1)).f{:g}
250
250
 
251
251
  expect(@c0.f).eq :m0
252
- expect(@c1.f).eq :g # m1 does not know c1 thus no way to pass this
252
+ expect(@c1.f).eq :g
253
253
  end
254
254
 
255
255
  would 'any_instance_of c0.class' do
data/test/test_prepend.rb CHANGED
@@ -94,6 +94,35 @@ describe 'mock with prepend' do
94
94
  paste :test
95
95
  end
96
96
 
97
+ describe 'class with a chain of prepended modules' do
98
+ would 'not affect other modules' do
99
+ mod0 = Module.new{ def f; :m0; end }
100
+ mod1 = Module.new{ def f; :m1; end }
101
+ klass0 = Class.new{ prepend mod0 }
102
+ klass1 = Class.new{ prepend mod1 }
103
+ klass = Class.new{ prepend mod1; prepend mod0 }
104
+
105
+ mock(any_instance_of(klass)).f{:f}
106
+
107
+ expect(klass.new.f).eq :f
108
+ expect(klass0.new.f).eq :m0
109
+ expect(klass1.new.f).eq :m1
110
+ end
111
+ end
112
+
113
+ describe 'class and subclass' do
114
+ would 'work for prepended superclass' do
115
+ mod = Module.new{ def f; :f; end }
116
+ base = Class.new{ prepend mod }
117
+ sub = Class.new(base)
118
+
119
+ mock(any_instance_of(base)).f{:g}.times(2)
120
+
121
+ expect(base.new.f).eq :g
122
+ expect(sub.new.f).eq :g
123
+ end
124
+ end
125
+
97
126
  # Brought from rspec-mocks and it's currently failing on rspec-mocks
98
127
  # See https://github.com/rspec/rspec-mocks/pull/1218
99
128
  would "handle stubbing prepending methods that were only defined on the prepended module" do
@@ -18,17 +18,9 @@ describe 'retain visibility' do
18
18
  end
19
19
 
20
20
  def generate visibility
21
- klass = Class.new do
22
- def greet
23
- 'hi'
24
- end
25
- end
21
+ klass = Class.new
26
22
 
27
23
  mod = Module.new do
28
- def greet
29
- hello
30
- end
31
-
32
24
  def hello
33
25
  'hello'
34
26
  end
@@ -97,8 +89,54 @@ describe 'retain visibility' do
97
89
  paste :test
98
90
  end
99
91
 
92
+ describe 'set the same visibility from the original method' do
93
+ copy :test do
94
+ def find_visibilities
95
+ %i[public protected private].map do |v|
96
+ object.send("#{v}_methods").include?(:hello)
97
+ end
98
+ end
99
+
100
+ would do
101
+ current_visibilities = find_visibilities
102
+
103
+ stub(object).hello{ :stub }
104
+
105
+ expect(find_visibilities).eq current_visibilities
106
+ end
107
+ end
108
+
109
+ describe 'for instance method' do
110
+ def object
111
+ @object ||= Class.new do
112
+ private
113
+ def hello; :hello; end
114
+ end.new
115
+ end
116
+
117
+ paste :test
118
+ end
119
+
120
+ describe 'for singleton method' do
121
+ def object
122
+ @object ||= begin
123
+ ret = Object.new
124
+ def ret.hello; :hello; end
125
+ ret
126
+ end
127
+ end
128
+
129
+ paste :test
130
+ end
131
+ end
132
+
100
133
  # Brought from rspec-mocks
101
134
  would "correctly restore the visibility of methods whose visibility has been tweaked on the singleton class" do
135
+ # JRuby didn't store the visibility change on the singleton class,
136
+ # therefore it cannot be properly detected and visibility change
137
+ # will be lost upon reset.
138
+ skip if RUBY_ENGINE == 'jruby'
139
+
102
140
  # hello is a private method when mixed in, but public on the module
103
141
  # itself
104
142
  mod = Module.new do
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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-06 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Muack -- A fast, small, yet powerful mocking library.
@@ -25,8 +25,8 @@ extensions: []
25
25
  extra_rdoc_files: []
26
26
  files:
27
27
  - ".gitignore"
28
+ - ".gitlab-ci.yml"
28
29
  - ".gitmodules"
29
- - ".travis.yml"
30
30
  - CHANGES.md
31
31
  - Gemfile
32
32
  - LICENSE
@@ -35,8 +35,6 @@ 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
40
38
  - lib/muack/coat.rb
41
39
  - lib/muack/definition.rb
42
40
  - lib/muack/error.rb
@@ -83,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
81
  - !ruby/object:Gem::Version
84
82
  version: '0'
85
83
  requirements: []
86
- rubygems_version: 3.1.4
84
+ rubygems_version: 3.4.1
87
85
  signing_key:
88
86
  specification_version: 4
89
87
  summary: Muack -- A fast, small, yet powerful mocking library.
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- sudo: false
2
- language: ruby
3
-
4
- install: 'gem update --system; gem install bundler; bundle install --retry=3'
5
- before_script: unset CI
6
- script: 'ruby -vwr bundler/setup -S rake test'
7
-
8
- matrix:
9
- include:
10
- - rvm: 2.3
11
- - rvm: 2.4
12
- env: RUBYOPT=--enable-frozen-string-literal
13
- - rvm: 2.5
14
- env: RUBYOPT=--enable-frozen-string-literal
15
- - rvm: 2.6
16
- env: RUBYOPT=--enable-frozen-string-literal
17
- - rvm: 2.7
18
- env: RUBYOPT=--enable-frozen-string-literal
19
- - rvm: ruby-head
20
- env: RUBYOPT=--enable-frozen-string-literal
21
- - rvm: jruby-9.2
22
- env: RUBYOPT=--enable-frozen-string-literal
@@ -1,16 +0,0 @@
1
-
2
- module Muack
3
- class Block < Struct.new(:block, :context)
4
- def initialize block, context=nil
5
- super
6
- end
7
-
8
- def call(*args, &block)
9
- if context
10
- context.instance_exec(*args, &block)
11
- else
12
- block.call(*args, &block)
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
-
2
- module Muack
3
- class Block < Struct.new(:block, :context)
4
- def initialize block, context=nil
5
- super
6
- end
7
-
8
- def call(...)
9
- if context
10
- context.instance_exec(...)
11
- else
12
- block.call(...)
13
- end
14
- end
15
- end
16
- end