rr 3.0.4 → 3.0.8

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: 303d118de2a2762d0b82b84ce5074540e77008a95805fb0b3b8df64872e3bb26
4
- data.tar.gz: 84a6e68fae515e2c5c1e6bed26dd55cbfba98e846e54d03b353266acb681a056
3
+ metadata.gz: 7450b7a3e656ff288e54d65cd2c9b899229706d72637a6e7b6944451b311bbe2
4
+ data.tar.gz: 44d9fa9e2e2f39809320e5d93819df20261dc6ad4ee83ec7e3fba9c81a03aa7f
5
5
  SHA512:
6
- metadata.gz: c5b89becb9e9df041c472826206c92e0c9b9b6755246ce8e0c6bd84b81b5cb498c77222aaf22dbaa20f55b3315483dff85dd3b910f2ef16a0b4405d51c697dc9
7
- data.tar.gz: f590f980d6fb93a5c173efe8a0f85676402262bd4fcec944e9804602f2372426b2a78cd9e2120569520667e9eaf213e72cb70c5db08d62373bee831a2f75387e
6
+ metadata.gz: ce0dc401f91fd48daeace9aabcc745e9d8f99a27362a82c890cfef326b21f465c826fcad5990f5f4b9f7a1757d5634431b2bdf71c9c6d02d319fc4ca3f9c2c99
7
+ data.tar.gz: acc8046b8610d2b35571414f736d58ba2e9dcfecf0b59da715c50f972bafbe839c4b627cee6e5d42fa023dd6ab7b2d7b645384f33a4f45c70af79f4e5fc64150
data/CHANGES.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.8 - 2021-10-17
4
+
5
+ ### Fixes
6
+
7
+ * Minitest integration: Fixed a bug that `NameError` is raised.
8
+ [GitHub#88][Reported by Matijs van Zuijlen]
9
+
10
+ ### Thanks
11
+
12
+ * Matijs van Zuijlen
13
+
14
+ ## 3.0.7 - 2021-08-17
15
+
16
+ ### Fixes
17
+
18
+ * Minitest + Active Support integration: Fixed a bug that `stub` in
19
+ `setup {...}` is ignored.
20
+ [GitHub#87][Reported by Boris]
21
+
22
+ ### Thanks
23
+
24
+ * Boris
25
+
26
+ ## 3.0.6 - 2021-08-07
27
+
28
+ ### Improvements
29
+
30
+ * `assert_received`: Added support for keyword arguments.
31
+ [GitHub#86][Reported by imadoki]
32
+
33
+ ### Thanks
34
+
35
+ * imadoki
36
+
37
+ ## 3.0.5 - 2021-06-26
38
+
39
+ ### Improvements
40
+
41
+ * Improved keyword arguments support on Ruby 2.7.
42
+ [GitHub#85][Patch by akira yamada]
43
+
44
+ ### Thanks
45
+
46
+ * akira yamada
47
+
3
48
  ## 3.0.4 - 2021-06-23
4
49
 
5
50
  ### Fixes
data/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ case ENV["RR_INTEGRATION"]
6
+ when "minitest"
7
+ gem "minitest"
8
+ when "minitest-active-support"
9
+ gem "activesupport"
10
+ end
@@ -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
+ target.is_a?(::ActiveSupport::TestCase)
45
+ end
46
+ else
47
+ is_active_support_test_case = lambda do |target|
48
+ false
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 if 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 unless 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.4'.freeze
2
+ VERSION = '3.0.8'.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.4
4
+ version: 3.0.8
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-23 00:00:00.000000000 Z
13
+ date: 2021-10-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler