rr 3.0.3 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ae999de4b35d2e97dd9805d858a1b573cf8201e8bc4a72c57ab2277ba30400e
4
- data.tar.gz: 807039ad92e52e43aaad160042ef82e4513ef79d4eb6724c0c4a6c29ffc22b93
3
+ metadata.gz: 7690f50ed3d2cb136611f0fe21955d6b29fc8a58be9dabcb7e342034dad13b66
4
+ data.tar.gz: c3ec0e439daecf5d736042cdd78e550c8e178fd3160bde8d47a1109c9552a68d
5
5
  SHA512:
6
- metadata.gz: 20c952e868437e27e4904e8e1297844e7f6c301f30ae5b8e8ed22915c5eca4817dec14dd2a8185ed3e154a83b89f3f0789baba6edd38d42a3889bfb2f45bd46c
7
- data.tar.gz: f8750bae03dd96e49c7b0d129685ea9c2be4a35d4dee7cdebf6054c6ba99917eed9ba93fe504c2c0241d37c4b8eb2fd37d91afe76d2b3cd9290868f8ee58b9db
6
+ metadata.gz: ccc4cab0df8cc92fd7e568ed36b392244ede5ef8ec908b01b15ac2d41eaf7d5cd3a8bb9c63f394894e43697d3baf6f326e643337b0286b3b0f02fcd38c11e2e7
7
+ data.tar.gz: ec16ec1798ed218454263a8bdb3facc5b2b66270ac35aaec3ef683d64cfb58350e223274a938c970a296719c05d163041bf8627651b95268f7cf52dc956792f7
data/CHANGES.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.7 - 2021-08-17
4
+
5
+ ### Fixes
6
+
7
+ * Minitest + Active Support integration: Fixed a bug that `stub` in
8
+ `setup {...}` is ignored.
9
+ [GitHub#87][Reported by Boris]
10
+
11
+ ### Thanks
12
+
13
+ * Boris
14
+
15
+ ## 3.0.6 - 2021-08-07
16
+
17
+ ### Improvements
18
+
19
+ * `assert_received`: Added support for keyword arguments.
20
+ [GitHub#86][Reported by imadoki]
21
+
22
+ ### Thanks
23
+
24
+ * imadoki
25
+
26
+ ## 3.0.5 - 2021-06-26
27
+
28
+ ### Improvements
29
+
30
+ * Improved keyword arguments support on Ruby 2.7.
31
+ [GitHub#85][Patch by akira yamada]
32
+
33
+ ### Thanks
34
+
35
+ * akira yamada
36
+
37
+ ## 3.0.4 - 2021-06-23
38
+
39
+ ### Fixes
40
+
41
+ * Fix inverted condition in keyword arguments related code.
42
+ [GitHub#84][Patch by akira yamada]
43
+
44
+ ### Thanks
45
+
46
+ * akira yamada
47
+
3
48
  ## 3.0.3 - 2021-06-22
4
49
 
5
50
  ### Improvements
@@ -22,6 +22,7 @@ module RR
22
22
  def method_missing(method_name, *args, &block)
23
23
  @double_definition_create.call(method_name, args, {}, &block)
24
24
  end
25
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
25
26
  end
26
27
 
27
28
  def __double_definition_create__
@@ -36,8 +36,6 @@ module RR
36
36
  def permissive_argument
37
37
  if args.empty? and kwargs.empty?
38
38
  definition.with_any_args
39
- elsif kwargs.empty?
40
- definition.with(*args)
41
39
  else
42
40
  definition.with(*args, **kwargs)
43
41
  end
@@ -137,25 +137,15 @@ module RR
137
137
  id = BoundObjects.size
138
138
  BoundObjects[id] = subject_class
139
139
 
140
- if KeywordArguments.fully_supported? && KeywordArguments.accept_kwargs?(subject_class, method_name)
141
- subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
142
- def #{method_name}(*args, **kwargs, &block)
143
- ::RR::Injections::DoubleInjection::BoundObjects[#{id}].class_eval do
144
- remove_method(:#{method_name})
145
- end
146
- method_missing(:#{method_name}, *args, **kwargs, &block)
147
- end
148
- RUBY
149
- else
150
- subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
151
- def #{method_name}(*args, &block)
152
- ::RR::Injections::DoubleInjection::BoundObjects[#{id}].class_eval do
153
- remove_method(:#{method_name})
154
- end
155
- method_missing(:#{method_name}, *args, &block)
140
+ subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
141
+ def #{method_name}(*args, &block)
142
+ ::RR::Injections::DoubleInjection::BoundObjects[#{id}].class_eval do
143
+ remove_method(:#{method_name})
156
144
  end
157
- RUBY
158
- end
145
+ method_missing(:#{method_name}, *args, &block)
146
+ end
147
+ ruby2_keywords(:#{method_name}) if respond_to?(:ruby2_keywords, true)
148
+ RUBY
159
149
  self
160
150
  end
161
151
 
@@ -163,7 +153,7 @@ module RR
163
153
  id = BoundObjects.size
164
154
  BoundObjects[id] = subject_class
165
155
 
166
- if KeywordArguments.fully_supported? && KeywordArguments.accept_kwargs?(subject_class, method_name)
156
+ if KeywordArguments.fully_supported?
167
157
  subject_class.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
168
158
  def #{method_name}(*args, **kwargs, &block)
169
159
  arguments = MethodArguments.new(args, kwargs, block)
@@ -192,6 +182,7 @@ module RR
192
182
  arguments.block
193
183
  )
194
184
  end
185
+ ruby2_keywords(:#{method_name}) if respond_to?(:ruby2_keywords, true)
195
186
  RUBY
196
187
  end
197
188
  self
@@ -106,6 +106,7 @@ module RR
106
106
  ).call
107
107
  end
108
108
  end
109
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
109
110
  METHOD
110
111
  end
111
112
  end
@@ -39,10 +39,21 @@ module RR
39
39
  include RR::DSL
40
40
  include Mixin
41
41
 
42
+ if defined?(::ActiveSupport::TestCase)
43
+ is_active_support_test_case = lambda do |target|
44
+ false
45
+ end
46
+ else
47
+ is_active_support_test_case = lambda do |target|
48
+ target.is_a?(::ActiveSupport::TestCase)
49
+ end
50
+ end
51
+
42
52
  unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
43
53
  alias_method :setup_without_rr, :setup
44
54
  define_method(:setup_with_rr) do
45
55
  setup_without_rr
56
+ return is_active_support_test_case.call(self)
46
57
  RR.reset
47
58
  RR.trim_backtrace = true
48
59
  RR.overridden_error_class = assertion_error_class
@@ -52,7 +63,7 @@ module RR
52
63
  alias_method :teardown_without_rr, :teardown
53
64
  define_method(:teardown_with_rr) do
54
65
  begin
55
- RR.verify
66
+ RR.verify if is_active_support_test_case.call(self)
56
67
  ensure
57
68
  teardown_without_rr
58
69
  end
@@ -1,7 +1,7 @@
1
1
  module RR
2
2
  module KeywordArguments
3
3
  class << self
4
- if (RUBY_VERSION <=> "2.7.0") >= 0
4
+ if (RUBY_VERSION <=> "3.0.0") >= 0
5
5
  def fully_supported?
6
6
  true
7
7
  end
@@ -10,12 +10,6 @@ module RR
10
10
  false
11
11
  end
12
12
  end
13
-
14
- def accept_kwargs?(subject_class, method_name)
15
- subject_class.instance_method(method_name).parameters.any? { |t, _| t == :key || t == :keyrest }
16
- rescue NameError
17
- true
18
- end
19
13
  end
20
14
  end
21
15
  end
@@ -31,7 +31,7 @@ module RR
31
31
 
32
32
  def call_original_method
33
33
  if subject_has_original_method?
34
- if KeywordArguments.fully_supported? && !kwargs.empty?
34
+ if KeywordArguments.fully_supported?
35
35
  subject.__send__(original_method_alias_name, *args, **kwargs, &block)
36
36
  else
37
37
  subject.__send__(original_method_alias_name, *args, &block)
@@ -53,7 +53,7 @@ module RR
53
53
  call_original_method
54
54
  else
55
55
  if implementation
56
- if KeywordArguments.fully_supported? && kwargs.empty?
56
+ if KeywordArguments.fully_supported?
57
57
  implementation.call(*args, **kwargs, &block)
58
58
  else
59
59
  implementation.call(*args, &block)
@@ -52,7 +52,7 @@ module RR
52
52
  if double_injection = Injections::DoubleInjection.find(subject_class, method_name)
53
53
  double_injection.bind_method
54
54
  # The DoubleInjection takes care of calling double.method_call
55
- if KeywordArguments.fully_supported? && !kwargs.empty?
55
+ if KeywordArguments.fully_supported?
56
56
  subject.__send__(method_name, *args, **kwargs, &block)
57
57
  else
58
58
  subject.__send__(method_name, *args, &block)
data/lib/rr/space.rb CHANGED
@@ -22,6 +22,7 @@ module RR
22
22
  def method_missing(method_name, *args, &block)
23
23
  instance.__send__(method_name, *args, &block)
24
24
  end
25
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
25
26
  end
26
27
  end
27
28
 
@@ -1,9 +1,9 @@
1
1
  module RR
2
2
  class SpyVerification
3
- def initialize(subject, method_name, args)
3
+ def initialize(subject, method_name, args, kwargs)
4
4
  @subject = subject
5
5
  @method_name = method_name.to_sym
6
- set_argument_expectation_for_args(args)
6
+ set_argument_expectation_for_args(args, kwargs)
7
7
  @ordered = false
8
8
  once
9
9
  end
@@ -44,9 +44,17 @@ module RR
44
44
  protected
45
45
  attr_writer :times_matcher
46
46
 
47
- def set_argument_expectation_for_args(args)
48
- # with_no_args and with actually set @argument_expectation
49
- args.empty? ? with_no_args : with(*args)
47
+ def set_argument_expectation_for_args(args, kwargs)
48
+ if args.empty? and kwargs.empty?
49
+ # with_no_args and with actually set @argument_expectation
50
+ with_no_args
51
+ else
52
+ if KeywordArguments.fully_supported?
53
+ with(*args, **kwargs)
54
+ else
55
+ with(*args)
56
+ end
57
+ end
50
58
  end
51
59
 
52
60
  def install_method_callback(return_value_block)
@@ -5,9 +5,16 @@ module RR
5
5
  def initialize(subject)
6
6
  @subject = subject
7
7
  end
8
-
9
- def method_missing(method_name, *args, &block)
10
- SpyVerification.new(@subject, method_name, args)
11
- end
8
+
9
+ if KeywordArguments.fully_supported?
10
+ def method_missing(method_name, *args, **kwargs, &block)
11
+ SpyVerification.new(@subject, method_name, args, kwargs)
12
+ end
13
+ else
14
+ def method_missing(method_name, *args, &block)
15
+ SpyVerification.new(@subject, method_name, args, {})
16
+ end
17
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
18
+ end
12
19
  end
13
- end
20
+ end
data/lib/rr/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module RR
2
- VERSION = '3.0.3'.freeze
2
+ VERSION = '3.0.7'.freeze
3
3
  def self.version; VERSION; end
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rr
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-06-22 00:00:00.000000000 Z
13
+ date: 2021-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler