rspec-support 3.8.0 → 3.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 631283161faf72604c2081235f9acbbda6ea980f
4
- data.tar.gz: 99170c1beccff1f998787873e0bd156af46ca9ef
2
+ SHA256:
3
+ metadata.gz: cd43ff0da6f307b7e9ccc56ceb9e3fdd972f27b7d160b8ba860c6625bb62f39b
4
+ data.tar.gz: a0c09feee171d7a1b02793888c995d9dd42f20660b6449db9c79eeed4a297b3f
5
5
  SHA512:
6
- metadata.gz: 23464780384e45e24c4a8a8255dce0f78d0afd406723d817d68ef66d20a8c0d973d40bdc6bee54188e9714c6ffb20b116045a08bb9c90aa11cb2ec2bdea453a6
7
- data.tar.gz: 4b08b17ebd14c92b615d9d6838d1be78c32b9e695933c895bb99710693bec391736ce26864f139c0e22f794e085367aa5cf0081b659068994cffddbfea23f0bc
6
+ metadata.gz: 247e3e818ef3c367c1ecbc4938dca5a0ca7c9b185c1b608900461e146ea1f8c5053e0d97adc692cd0871debeb764407a3403682ce425aebf1de6511f17f366fc
7
+ data.tar.gz: b3b600ca9061f37b529af60308df73b4c9724de1d173ee01eda44c0f61404396d8f2af7a52b071db93299bb607905e8b1aa3ddac29cc364ef41136a1815735d1
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,133 @@
1
+ ### Development
2
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.12.1...3-12-maintenance)
3
+
4
+ ### 3.12.1 / 2023-06-26
5
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.12.0...v3.12.1)
6
+
7
+ Bug Fixes:
8
+
9
+ * Fix `RSpec::Support.thread_local_data` to be Thread local but not Fiber local.
10
+ (Jon Rowe, #581)
11
+
12
+ ### 3.12.0 / 2022-10-26
13
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.11.1...v3.12.0)
14
+ Enhancements:
15
+
16
+ * Add `RSpec::Support::RubyFeatures.distincts_kw_args_from_positional_hash?`
17
+ (Jean byroot Boussier, #535)
18
+
19
+ ### 3.11.1 / 2022-09-12
20
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.11.0...v3.11.1)
21
+
22
+ Bug Fixes:
23
+
24
+ * Fix ripper detection on TruffleRuby. (Brandon Fish, #541)
25
+
26
+ ### 3.11.0 / 2022-02-09
27
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.3...v3.11.0)
28
+
29
+ No changes. Released to support other RSpec releases.
30
+
31
+ ### 3.10.3 / 2021-11-03
32
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.2...v3.10.3)
33
+
34
+ Bug Fixes:
35
+
36
+ * Use `Mutex#owned?` to allow `RSpec::Support::ReentrantMutex` to work in
37
+ nested Fibers on Ruby 3.0 and later. (Benoit Daloze, #503, #504)
38
+ * Support `end`-less methods in `RSpec::Support::Source::Token`
39
+ so that RSpec won't hang when an `end`-less method raises an error. (Yuji Nakayama, #505)
40
+
41
+ ### 3.10.2 / 2021-01-28
42
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.1...v3.10.2)
43
+
44
+ Bug Fixes:
45
+
46
+ * Fix issue with `RSpec::Support.define_optimized_require_for_rspec` on JRuby
47
+ 9.1.17.0 (Jon Rowe, #492)
48
+
49
+ ### 3.10.1 / 2020-12-27
50
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.10.0...v3.10.1)
51
+
52
+ Bug Fixes:
53
+
54
+ * Fix deprecation expectations to fail correctly when
55
+ asserting on messages. (Phil Pirozhkov, #453)
56
+
57
+ ### 3.10.0 / 2020-10-30
58
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.4...v3.10.0)
59
+
60
+ No changes. Released to support other RSpec releases.
61
+
62
+ ### 3.9.4 / 2020-10-23
63
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.3...v3.9.4)
64
+
65
+ Bug Fixes:
66
+
67
+ * Flag ripper as supported on Truffle Ruby. (Brandon Fish, #427)
68
+ * Prevent stubbing `File.read` from breaking source extraction.
69
+ (Jon Rowe, #431)
70
+
71
+ ### 3.9.3 / 2020-05-02
72
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.2...v3.9.3)
73
+
74
+ Bug Fixes:
75
+
76
+ * Mark ripper as unsupported on Truffle Ruby. (Brandon Fish, #395)
77
+ * Mark ripper as unsupported on JRuby 9.2.0.0. (Brian Hawley, #400)
78
+ * Capture `Mutex.new` for our `RSpec::Support:Mutex` in order to
79
+ allow stubbing `Mutex.new`. (Jon Rowe, #411)
80
+
81
+ ### 3.9.2 / 2019-12-30
82
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.1...v3.9.2)
83
+
84
+ Bug Fixes:
85
+
86
+ * Remove unneeded eval. (Matijs van Zuijlen, #394)
87
+
88
+ ### 3.9.1 / 2019-12-28
89
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.9.0...v3.9.1)
90
+
91
+ Bug Fixes:
92
+
93
+ * Remove warning caused by keyword arguments on Ruby 2.7.0.
94
+ (Jon Rowe, #392)
95
+
96
+ ### 3.9.0 / 2019-10-07
97
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.3...v3.9.0)
98
+
99
+ *NO CHANGES*
100
+
101
+ Version 3.9.0 was released to allow other RSpec gems to release 3.9.0.
102
+
103
+ ### 3.8.3 / 2019-10-02
104
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.2...v3.8.3)
105
+
106
+ Bug Fixes:
107
+
108
+ * Escape \r when outputting strings inside arrays.
109
+ (Tomita Masahiro, Jon Rowe, #378)
110
+ * Ensure that optional hash arguments are recognised correctly vs keyword
111
+ arguments. (Evgeni Dzhelyov, #366)
112
+
113
+ ### 3.8.2 / 2019-06-10
114
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.1...v3.8.2)
115
+
116
+ Bug Fixes:
117
+
118
+ * Ensure that an empty hash is recognised as empty keyword arguments when
119
+ applicable. (Thomas Walpole, #375)
120
+ * Ensure that diffing truthy values produce diffs consistently.
121
+ (Lucas Nestor, #377)
122
+
123
+ ### 3.8.1 / 2019-03-03
124
+ [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.8.0...v3.8.1)
125
+
126
+ Bug Fixes:
127
+
128
+ * Ensure that inspecting a `SimpleDelegator` based object works regardless of
129
+ visibilty of the `__getobj__` method. (Jon Rowe, #369)
130
+
1
131
  ### 3.8.0 / 2018-08-04
2
132
  [Full Changelog](http://github.com/rspec/rspec-support/compare/v3.7.1...v3.8.0)
3
133
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RSpec::Support
1
+ # RSpec::Support [![Build Status](https://github.com/rspec/rspec-support/workflows/RSpec%20CI/badge.svg)](https://github.com/rspec/rspec-support/actions)
2
2
 
3
3
  `RSpec::Support` provides common functionality to `RSpec::Core`,
4
4
  `RSpec::Expectations` and `RSpec::Mocks`. It is considered
@@ -8,12 +8,12 @@ suitable for internal use only at this time.
8
8
 
9
9
  Install one or more of the `RSpec` gems.
10
10
 
11
- Want to run against the `master` branch? You'll need to include the dependent
11
+ Want to run against the `main` branch? You'll need to include the dependent
12
12
  RSpec repos as well. Add the following to your `Gemfile`:
13
13
 
14
14
  ```ruby
15
15
  %w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
16
- gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
16
+ gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'main'
17
17
  end
18
18
  ```
19
19
 
@@ -25,7 +25,7 @@ module RSpec
25
25
  # when `CallerFilter.first_non_rspec_line` is called from the top level of a required
26
26
  # file, but it depends on if rubygems is loaded or not. We don't want to have to deal
27
27
  # with this complexity in our `RSpec.deprecate` calls, so we ignore it here.
28
- IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb")
28
+ IGNORE_REGEX = Regexp.union(LIB_REGEX, "rubygems/core_ext/kernel_require.rb", "<internal:")
29
29
 
30
30
  if RSpec::Support::RubyFeatures.caller_locations_supported?
31
31
  # This supports args because it's more efficient when the caller specifies
@@ -34,7 +34,7 @@ module RSpec
34
34
  # be found in a small number of stack frames from `skip_frames`.
35
35
  #
36
36
  # Note that there is a risk to passing a `skip_frames` value that is too high:
37
- # If it skippped the first non-rspec line, then this method would return the
37
+ # If it skipped the first non-rspec line, then this method would return the
38
38
  # 2nd or 3rd (or whatever) non-rspec line. Thus, you generally shouldn't pass
39
39
  # values for these parameters, particularly since most places that use this are
40
40
  # not hot spots (generally it gets used for deprecation warnings). However,
@@ -69,7 +69,7 @@ module RSpec
69
69
  return line.to_s if line
70
70
 
71
71
  skip_frames += increment
72
- increment *= 2 # The choice of two here is arbitrary.
72
+ increment *= 2 # The choice of two here is arbitrary.
73
73
  end
74
74
  end
75
75
  else
@@ -6,12 +6,12 @@ require 'pp'
6
6
 
7
7
  module RSpec
8
8
  module Support
9
- # rubocop:disable ClassLength
9
+ # rubocop:disable Metrics/ClassLength
10
10
  class Differ
11
11
  def diff(actual, expected)
12
12
  diff = ""
13
13
 
14
- if actual && expected
14
+ unless actual.nil? || expected.nil?
15
15
  if all_strings?(actual, expected)
16
16
  if any_multiline_strings?(actual, expected)
17
17
  diff = diff_as_string(coerce_to_string(actual), coerce_to_string(expected))
@@ -24,7 +24,7 @@ module RSpec
24
24
  diff.to_s
25
25
  end
26
26
 
27
- # rubocop:disable MethodLength
27
+ # rubocop:disable Metrics/MethodLength
28
28
  def diff_as_string(actual, expected)
29
29
  encoding = EncodedString.pick_encoding(actual, expected)
30
30
 
@@ -52,7 +52,7 @@ module RSpec
52
52
  rescue Encoding::CompatibilityError
53
53
  handle_encoding_errors(actual, expected)
54
54
  end
55
- # rubocop:enable MethodLength
55
+ # rubocop:enable Metrics/MethodLength
56
56
 
57
57
  def diff_as_object(actual, expected)
58
58
  actual_as_string = object_to_string(actual)
@@ -97,7 +97,7 @@ module RSpec
97
97
  if Array === entry
98
98
  entry.inspect
99
99
  else
100
- entry.to_s.gsub("\n", "\\n")
100
+ entry.to_s.gsub("\n", "\\n").gsub("\r", "\\r")
101
101
  end
102
102
  end
103
103
  end
@@ -210,6 +210,6 @@ module RSpec
210
210
  end
211
211
  end
212
212
  end
213
- # rubocop:enable ClassLength
213
+ # rubocop:enable Metrics/ClassLength
214
214
  end
215
215
  end
@@ -5,31 +5,11 @@ module RSpec
5
5
  # Reduce allocations by storing constants.
6
6
  UTF_8 = "UTF-8"
7
7
  US_ASCII = "US-ASCII"
8
- #
9
- # In MRI 2.1 'invalid: :replace' changed to also replace an invalid byte sequence
10
- # see https://github.com/ruby/ruby/blob/v2_1_0/NEWS#L176
11
- # https://www.ruby-forum.com/topic/6861247
12
- # https://twitter.com/nalsh/status/553413844685438976
13
- #
14
- # For example, given:
15
- # "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a
16
- #
17
- # On MRI 2.1 or above: 63 # '?'
18
- # else : 128 # "\x80"
19
- #
8
+
20
9
  # Ruby's default replacement string is:
21
10
  # U+FFFD ("\xEF\xBF\xBD"), for Unicode encoding forms, else
22
11
  # ? ("\x3F")
23
12
  REPLACE = "?"
24
- ENCODE_UNCONVERTABLE_BYTES = {
25
- :invalid => :replace,
26
- :undef => :replace,
27
- :replace => REPLACE
28
- }
29
- ENCODE_NO_CONVERTER = {
30
- :invalid => :replace,
31
- :replace => REPLACE
32
- }
33
13
 
34
14
  def initialize(string, encoding=nil)
35
15
  @encoding = encoding
@@ -80,7 +60,7 @@ module RSpec
80
60
  # vs "\x80".encode('UTF-8','ASCII-8BIT', undef: :replace, replace: '<undef>')
81
61
  # # => '<undef>'
82
62
  # Encoding::CompatibilityError
83
- # when Encoding.compatibile?(str1, str2) is nil
63
+ # when Encoding.compatible?(str1, str2) is nil
84
64
  # e.g. utf_16le_emoji_string.split("\n")
85
65
  # e.g. valid_unicode_string.encode(utf8_encoding) << ascii_string
86
66
  # Encoding::InvalidByteSequenceError:
@@ -112,9 +92,25 @@ module RSpec
112
92
  string = remove_invalid_bytes(string)
113
93
  string.encode(@encoding)
114
94
  rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
115
- string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
95
+ # Originally defined as a constant to avoid unneeded allocations, this hash must
96
+ # be defined inline (without {}) to avoid warnings on Ruby 2.7
97
+ #
98
+ # In MRI 2.1 'invalid: :replace' changed to also replace an invalid byte sequence
99
+ # see https://github.com/ruby/ruby/blob/v2_1_0/NEWS#L176
100
+ # https://www.ruby-forum.com/topic/6861247
101
+ # https://twitter.com/nalsh/status/553413844685438976
102
+ #
103
+ # For example, given:
104
+ # "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a
105
+ #
106
+ # On MRI 2.1 or above: 63 # '?'
107
+ # else : 128 # "\x80"
108
+ #
109
+ string.encode(@encoding, :invalid => :replace, :undef => :replace, :replace => REPLACE)
116
110
  rescue Encoding::ConverterNotFoundError
117
- string.dup.force_encoding(@encoding).encode(ENCODE_NO_CONVERTER)
111
+ # Originally defined as a constant to avoid unneeded allocations, this hash must
112
+ # be defined inline (without {}) to avoid warnings on Ruby 2.7
113
+ string.dup.force_encoding(@encoding).encode(:invalid => :replace, :replace => REPLACE)
118
114
  end
119
115
 
120
116
  # Prevents raising ArgumentError
@@ -8,7 +8,7 @@ module RSpec
8
8
  # keyword args of a given method.
9
9
  #
10
10
  # @private
11
- class MethodSignature # rubocop:disable ClassLength
11
+ class MethodSignature # rubocop:disable Metrics/ClassLength
12
12
  attr_reader :min_non_kw_args, :max_non_kw_args, :optional_kw_args, :required_kw_args
13
13
 
14
14
  def initialize(method)
@@ -77,14 +77,19 @@ module RSpec
77
77
  given_kw_args - @allowed_kw_args
78
78
  end
79
79
 
80
+ # If the last argument is Hash, Ruby will treat only symbol keys as keyword arguments
81
+ # the rest will be grouped in another Hash and passed as positional argument.
80
82
  def has_kw_args_in?(args)
81
- Hash === args.last && could_contain_kw_args?(args)
83
+ Hash === args.last &&
84
+ could_contain_kw_args?(args) &&
85
+ (args.last.empty? || args.last.keys.any? { |x| x.is_a?(Symbol) })
82
86
  end
83
87
 
84
88
  # Without considering what the last arg is, could it
85
89
  # contain keyword arguments?
86
90
  def could_contain_kw_args?(args)
87
91
  return false if args.count <= min_non_kw_args
92
+
88
93
  @allows_any_kw_args || @allowed_kw_args.any?
89
94
  end
90
95
 
@@ -117,7 +122,7 @@ module RSpec
117
122
  end
118
123
  end
119
124
 
120
- @max_non_kw_args = @min_non_kw_args + optional_non_kw_args
125
+ @max_non_kw_args = @min_non_kw_args + optional_non_kw_args
121
126
  @allowed_kw_args = @required_kw_args + @optional_kw_args
122
127
  end
123
128
  else
@@ -280,7 +285,7 @@ module RSpec
280
285
  @arbitrary_kw_args = @unlimited_args = false
281
286
  end
282
287
 
283
- def with_expectation(expectation) # rubocop:disable MethodLength
288
+ def with_expectation(expectation) # rubocop:disable Metrics/MethodLength
284
289
  return self unless MethodSignatureExpectation === expectation
285
290
 
286
291
  if expectation.empty?
@@ -357,7 +362,14 @@ module RSpec
357
362
 
358
363
  def split_args(*args)
359
364
  kw_args = if @signature.has_kw_args_in?(args)
360
- args.pop.keys
365
+ last = args.pop
366
+ non_kw_args = last.reject { |k, _| k.is_a?(Symbol) }
367
+ if non_kw_args.empty?
368
+ last.keys
369
+ else
370
+ args << non_kw_args
371
+ last.select { |k, _| k.is_a?(Symbol) }.keys
372
+ end
361
373
  else
362
374
  []
363
375
  end
@@ -9,7 +9,7 @@ module RSpec
9
9
  # Some methods we don't need are deleted. Anything I don't
10
10
  # understand (there's quite a bit, actually) is left in.
11
11
  #
12
- # Some formating changes are made to appease the robot overlord:
12
+ # Some formatting changes are made to appease the robot overlord:
13
13
  # https://travis-ci.org/rspec/rspec-core/jobs/54410874
14
14
  # @private
15
15
  class Mutex
@@ -225,7 +225,7 @@ module RSpec
225
225
  end
226
226
 
227
227
  def inspect
228
- "#<#{object.class}(#{formatter.format(object.__getobj__)})>"
228
+ "#<#{object.class}(#{formatter.format(object.send(:__getobj__))})>"
229
229
  end
230
230
  end
231
231
 
@@ -27,23 +27,48 @@ module RSpec
27
27
 
28
28
  private
29
29
 
30
- def enter
31
- @mutex.lock if @owner != Thread.current
32
- @owner = Thread.current
33
- @count += 1
34
- end
30
+ # This is fixing a bug #501 that is specific to Ruby 3.0. The new implementation
31
+ # depends on `owned?` that was introduced in Ruby 2.0, so both should work for Ruby 2.x.
32
+ if RUBY_VERSION.to_f >= 3.0
33
+ def enter
34
+ @mutex.lock unless @mutex.owned?
35
+ @count += 1
36
+ end
35
37
 
36
- def exit
37
- @count -= 1
38
- return unless @count == 0
39
- @owner = nil
40
- @mutex.unlock
38
+ def exit
39
+ unless @mutex.owned?
40
+ raise ThreadError, "Attempt to unlock a mutex which is locked by another thread/fiber"
41
+ end
42
+ @count -= 1
43
+ @mutex.unlock if @count == 0
44
+ end
45
+ else
46
+ def enter
47
+ @mutex.lock if @owner != Thread.current
48
+ @owner = Thread.current
49
+ @count += 1
50
+ end
51
+
52
+ def exit
53
+ @count -= 1
54
+ return unless @count == 0
55
+ @owner = nil
56
+ @mutex.unlock
57
+ end
41
58
  end
42
59
  end
43
60
 
44
61
  if defined? ::Mutex
45
62
  # On 1.9 and up, this is in core, so we just use the real one
46
- Mutex = ::Mutex
63
+ class Mutex < ::Mutex
64
+ # If you mock Mutex.new you break our usage of Mutex, so
65
+ # instead we capture the original method to return Mutexs.
66
+ NEW_MUTEX_METHOD = Mutex.method(:new)
67
+
68
+ def self.new
69
+ NEW_MUTEX_METHOD.call
70
+ end
71
+ end
47
72
  else # For 1.8.7
48
73
  # :nocov:
49
74
  RSpec::Support.require_rspec_support "mutex"
@@ -7,7 +7,7 @@ module RSpec
7
7
  #
8
8
  # Provides query methods for different OS or OS features.
9
9
  module OS
10
- module_function
10
+ module_function
11
11
 
12
12
  def windows?
13
13
  !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
@@ -22,7 +22,7 @@ module RSpec
22
22
  #
23
23
  # Provides query methods for different rubies
24
24
  module Ruby
25
- module_function
25
+ module_function
26
26
 
27
27
  def jruby?
28
28
  RUBY_PLATFORM == 'java'
@@ -47,6 +47,10 @@ module RSpec
47
47
  def mri?
48
48
  !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
49
49
  end
50
+
51
+ def truffleruby?
52
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby'
53
+ end
50
54
  end
51
55
 
52
56
  # @api private
@@ -54,9 +58,9 @@ module RSpec
54
58
  # Provides query methods for ruby features that differ among
55
59
  # implementations.
56
60
  module RubyFeatures
57
- module_function
61
+ module_function
58
62
 
59
- if Ruby.jruby?
63
+ if Ruby.jruby? && RUBY_VERSION.to_f < 1.9
60
64
  # On JRuby 1.7 `--1.8` mode, `Process.respond_to?(:fork)` returns true,
61
65
  # but when you try to fork, it raises an error:
62
66
  # NotImplementedError: fork is not available on this platform
@@ -90,6 +94,15 @@ module RSpec
90
94
  end
91
95
  end
92
96
 
97
+ if RUBY_VERSION.to_f >= 2.7
98
+ def supports_taint?
99
+ false
100
+ end
101
+ else
102
+ def supports_taint?
103
+ true
104
+ end
105
+ end
93
106
  ripper_requirements = [ComparableVersion.new(RUBY_VERSION) >= '1.9.2']
94
107
 
95
108
  ripper_requirements.push(false) if Ruby.rbx?
@@ -98,9 +111,14 @@ module RSpec
98
111
  ripper_requirements.push(Ruby.jruby_version >= '1.7.5')
99
112
  # Ripper on JRuby 9.0.0.0.rc1 - 9.1.8.0 reports wrong line number
100
113
  # or cannot parse source including `:if`.
101
- ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.1.8.0'))
114
+ # Ripper on JRuby 9.x.x.x < 9.1.17.0 can't handle keyword arguments
115
+ # Neither can JRuby 9.2, e.g. < 9.2.1.0
116
+ ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.2.0.0'))
102
117
  end
103
118
 
119
+ # TruffleRuby disables ripper due to low performance
120
+ ripper_requirements.push(false) if Ruby.truffleruby?
121
+
104
122
  if ripper_requirements.all?
105
123
  def ripper_supported?
106
124
  true
@@ -111,6 +129,10 @@ module RSpec
111
129
  end
112
130
  end
113
131
 
132
+ def distincts_kw_args_from_positional_hash?
133
+ RUBY_VERSION >= '3.0.0'
134
+ end
135
+
114
136
  if Ruby.mri?
115
137
  def kw_args_supported?
116
138
  RUBY_VERSION >= '2.0.0'
@@ -54,12 +54,16 @@ module RSpec
54
54
  type == :on_kw
55
55
  end
56
56
 
57
+ def equals_operator?
58
+ type == :on_op && string == '='
59
+ end
60
+
57
61
  def opening?
58
62
  opening_delimiter? || opening_keyword?
59
63
  end
60
64
 
61
65
  def closed_by?(other)
62
- closed_by_delimiter?(other) || closed_by_keyword?(other)
66
+ delimiter_closed_by?(other) || keyword_closed_by?(other)
63
67
  end
64
68
 
65
69
  private
@@ -73,13 +77,16 @@ module RSpec
73
77
  CLOSING_KEYWORDS_BY_OPENING_KEYWORD.key?(string)
74
78
  end
75
79
 
76
- def closed_by_delimiter?(other)
80
+ def delimiter_closed_by?(other)
77
81
  other.type == CLOSING_TYPES_BY_OPENING_TYPE[type]
78
82
  end
79
83
 
80
- def closed_by_keyword?(other)
81
- return false unless other.keyword?
82
- other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string]
84
+ def keyword_closed_by?(other)
85
+ return false unless keyword?
86
+ return true if other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string]
87
+
88
+ # Ruby 3's `end`-less method definition: `def method_name = body`
89
+ string == 'def' && other.equals_operator? && location.line == other.location.line
83
90
  end
84
91
  end
85
92
  end
@@ -8,6 +8,16 @@ module RSpec
8
8
  class Source
9
9
  attr_reader :source, :path
10
10
 
11
+ # This class protects us against having File read and expand_path
12
+ # stubbed out within tests.
13
+ class File
14
+ class << self
15
+ [:read, :expand_path].each do |method_name|
16
+ define_method(method_name, &::File.method(method_name))
17
+ end
18
+ end
19
+ end
20
+
11
21
  def self.from_file(path)
12
22
  source = File.read(path)
13
23
  new(source, path)
@@ -1,35 +1,22 @@
1
1
  module RSpecHelpers
2
- def expect_no_deprecation
3
- expect(RSpec.configuration.reporter).not_to receive(:deprecation)
4
- end
5
-
6
2
  def expect_deprecation_with_call_site(file, line, snippet=//)
7
- expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
8
- expect(options[:call_site]).to include([file, line].join(':'))
9
- expect(options[:deprecated]).to match(snippet)
10
- end
3
+ expect(RSpec.configuration.reporter).to receive(:deprecation).
4
+ with(include(:deprecated => match(snippet), :call_site => include([file, line].join(':'))))
11
5
  end
12
6
 
13
7
  def expect_deprecation_without_call_site(snippet=//)
14
- expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
15
- expect(options[:call_site]).to eq nil
16
- expect(options[:deprecated]).to match(snippet)
17
- end
8
+ expect(RSpec.configuration.reporter).to receive(:deprecation).
9
+ with(include(:deprecated => match(snippet), :call_site => eq(nil)))
18
10
  end
19
11
 
20
12
  def expect_warn_deprecation_with_call_site(file, line, snippet=//)
21
- expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
22
- message = options[:message]
23
- expect(message).to match(snippet)
24
- expect(message).to include([file, line].join(':'))
25
- end
13
+ expect(RSpec.configuration.reporter).to receive(:deprecation).
14
+ with(include(:message => match(snippet), :call_site => include([file, line].join(':'))))
26
15
  end
27
16
 
28
17
  def expect_warn_deprecation(snippet=//)
29
- expect(RSpec.configuration.reporter).to receive(:deprecation) do |options|
30
- message = options[:message]
31
- expect(message).to match(snippet)
32
- end
18
+ expect(RSpec.configuration.reporter).to receive(:deprecation).
19
+ with(include(:message => match(snippet)))
33
20
  end
34
21
 
35
22
  def allow_deprecation
@@ -39,19 +26,16 @@ module RSpecHelpers
39
26
  def expect_no_deprecations
40
27
  expect(RSpec.configuration.reporter).not_to receive(:deprecation)
41
28
  end
29
+ alias expect_no_deprecation expect_no_deprecations
42
30
 
43
31
  def expect_warning_without_call_site(expected=//)
44
- expect(::Kernel).to receive(:warn) do |message|
45
- expect(message).to match expected
46
- expect(message).to_not match(/Called from/)
47
- end
32
+ expect(::Kernel).to receive(:warn).
33
+ with(match(expected).and(satisfy { |message| !(/Called from/ =~ message) }))
48
34
  end
49
35
 
50
36
  def expect_warning_with_call_site(file, line, expected=//)
51
- expect(::Kernel).to receive(:warn) do |message|
52
- expect(message).to match expected
53
- expect(message).to match(/Called from #{file}:#{line}/)
54
- end
37
+ expect(::Kernel).to receive(:warn).
38
+ with(match(expected).and(match(/Called from #{file}:#{line}/)))
55
39
  end
56
40
 
57
41
  def expect_no_warnings
@@ -0,0 +1,31 @@
1
+ require 'diff/lcs'
2
+
3
+ module RSpec
4
+ module Support
5
+ module Spec
6
+ module DiffHelpers
7
+ # In the updated version of diff-lcs several diff headers change format slightly
8
+ # compensate for this and change minimum version in RSpec 4
9
+ if ::Diff::LCS::VERSION.to_f < 1.4
10
+ def one_line_header(line_number=2)
11
+ "-1,#{line_number} +1,#{line_number}"
12
+ end
13
+ else
14
+ def one_line_header(_=2)
15
+ "-1 +1"
16
+ end
17
+ end
18
+
19
+ if Diff::LCS::VERSION.to_f < 1.4 || Diff::LCS::VERSION >= "1.4.4"
20
+ def removing_two_line_header
21
+ "-1,3 +1"
22
+ end
23
+ else
24
+ def removing_two_line_header
25
+ "-1,3 +1,5"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -7,8 +7,7 @@ module RSpec
7
7
 
8
8
  # Useful as a way to isolate a global change to a subprocess.
9
9
 
10
- # rubocop:disable MethodLength
11
- def in_sub_process(prevent_warnings=true)
10
+ def in_sub_process(prevent_warnings=true) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
11
  exception_reader, exception_writer = IO.pipe
13
12
  result_reader, result_writer = IO.pipe
14
13
 
@@ -46,7 +45,6 @@ module RSpec
46
45
  result_reader.close
47
46
  result
48
47
  end
49
- # rubocop:enable MethodLength
50
48
  alias :in_sub_process_if_possible :in_sub_process
51
49
 
52
50
  def marshal_dump_with_unmarshable_object_handling(object)
@@ -53,16 +53,40 @@ module RSpec
53
53
  end
54
54
  end
55
55
 
56
- def strip_known_warnings(input)
57
- input.split("\n").reject do |l|
56
+ LINES_TO_IGNORE =
57
+ [
58
58
  # Ignore bundler warning.
59
- l =~ %r{bundler/source/rubygems} ||
59
+ %r{bundler/source/rubygems},
60
60
  # Ignore bundler + rubygems warning.
61
- l =~ %r{site_ruby/\d\.\d\.\d/rubygems} ||
61
+ %r{site_ruby/\d\.\d\.\d/rubygems},
62
+ %r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/rubygems},
62
63
  # This is required for windows for some reason
63
- l =~ %r{lib/bundler/rubygems} ||
64
+ %r{lib/bundler/rubygems},
64
65
  # This is a JRuby file that generates warnings on 9.0.3.0
65
- l =~ %r{lib/ruby/stdlib/jar}
66
+ %r{lib/ruby/stdlib/jar},
67
+ # This is a JRuby file that generates warnings on 9.1.7.0
68
+ %r{org/jruby/RubyKernel\.java},
69
+ # This is a JRuby gem that generates warnings on 9.1.7.0
70
+ %r{ffi-1\.13\.\d+-java},
71
+ %r{uninitialized constant FFI},
72
+ # These are related to the above, there is a warning about io from FFI
73
+ %r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/io},
74
+ %r{io/console on JRuby shells out to stty for most operations},
75
+ # This is a JRuby 9.1.17.0 error on Github Actions
76
+ %r{io/console not supported; tty will not be manipulated},
77
+ # This is a JRuby 9.2.1.x error
78
+ %r{jruby/kernel/gem_prelude},
79
+ %r{lib/jruby\.jar!/jruby/preludes},
80
+ # Ignore some JRuby errors for gems
81
+ %r{jruby/\d\.\d(\.\d)?/gems/aruba},
82
+ %r{jruby/\d\.\d(\.\d)?/gems/ffi},
83
+ ]
84
+
85
+ def strip_known_warnings(input)
86
+ input.split("\n").reject do |l|
87
+ LINES_TO_IGNORE.any? { |to_ignore| l =~ to_ignore } ||
88
+ # Remove blank lines
89
+ l == "" || l.nil?
66
90
  end.join("\n")
67
91
  end
68
92
 
@@ -71,7 +95,7 @@ module RSpec
71
95
  if Ruby.jruby?
72
96
  def filter(output)
73
97
  output.each_line.reject do |line|
74
- line.include?("lib/ruby/shared/rubygems/defaults/jruby")
98
+ line.include?("lib/ruby/shared/rubygems")
75
99
  end.join($/)
76
100
  end
77
101
  else
@@ -6,6 +6,7 @@ module RSpec
6
6
  def initialize(original)
7
7
  @orig_stderr = original
8
8
  @output_tracker = ::StringIO.new
9
+ @last_line = nil
9
10
  end
10
11
 
11
12
  respond_to_name = (::RUBY_VERSION.to_f < 1.9) ? :respond_to? : :respond_to_missing?
@@ -38,8 +39,19 @@ module RSpec
38
39
  def write(line)
39
40
  return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG
40
41
 
42
+ # Ruby 2.7.0 warnings from keyword arguments span multiple lines, extend check above
43
+ # to look for the next line.
44
+ return if @last_line =~ %r{^\S+/gems/\S+:\d+: warning:} &&
45
+ line =~ %r{warning: The called method .* is defined here}
46
+
47
+ # Ruby 2.7.0 complains about hashes used in place of keyword arguments
48
+ # Aruba 0.14.2 uses this internally triggering that here
49
+ return if line =~ %r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:}
50
+
41
51
  @orig_stderr.write(line)
42
52
  @output_tracker.write(line)
53
+ ensure
54
+ @last_line = line
43
55
  end
44
56
 
45
57
  def has_output?
@@ -4,7 +4,6 @@ require 'rspec/matchers'
4
4
  # which also relies on EncodedString. Instead, confirm the
5
5
  # strings have the same bytes.
6
6
  RSpec::Matchers.define :be_identical_string do |expected|
7
-
8
7
  if String.method_defined?(:encoding)
9
8
  match do
10
9
  expected_encoding? &&
@@ -2,6 +2,7 @@ require 'rspec/support'
2
2
  require 'rspec/support/spec/in_sub_process'
3
3
 
4
4
  RSpec::Support.require_rspec_support "spec/deprecation_helpers"
5
+ RSpec::Support.require_rspec_support "spec/diff_helpers"
5
6
  RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
6
7
  RSpec::Support.require_rspec_support "spec/stderr_splitter"
7
8
  RSpec::Support.require_rspec_support "spec/formatting_support"
@@ -35,9 +36,9 @@ RSpec.configure do |c|
35
36
 
36
37
  c.example_status_persistence_file_path = "./spec/examples.txt"
37
38
 
38
- c.define_derived_metadata :failing_on_appveyor do |meta|
39
- meta[:pending] ||= "This spec fails on AppVeyor and needs someone to fix it."
40
- end if ENV['APPVEYOR']
39
+ c.define_derived_metadata :failing_on_windows_ci do |meta|
40
+ meta[:pending] ||= "This spec fails on Windows CI and needs someone to fix it."
41
+ end if RSpec::Support::OS.windows? && ENV['CI']
41
42
  end
42
43
 
43
44
  module RSpec
@@ -64,8 +65,8 @@ module RSpec
64
65
 
65
66
  def self.start_simplecov(&block)
66
67
  SimpleCov.start do
67
- add_filter "./bundle/"
68
- add_filter "./tmp/"
68
+ add_filter "bundle/"
69
+ add_filter "tmp/"
69
70
  add_filter do |source_file|
70
71
  # Filter out `spec` directory except when it is under `lib`
71
72
  # (as is the case in rspec-support)
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Support
3
3
  module Version
4
- STRING = '3.8.0'
4
+ STRING = '3.12.1'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,33 @@
1
+ RSpec::Support.require_rspec_support("method_signature_verifier")
2
+
3
+ module RSpec
4
+ module Support
5
+ module WithKeywordsWhenNeeded
6
+ # This module adds keyword sensitive support for core ruby methods
7
+ # where we cannot use `ruby2_keywords` directly.
8
+
9
+ module_function
10
+
11
+ if RSpec::Support::RubyFeatures.kw_args_supported?
12
+ # Remove this in RSpec 4 in favour of explicitly passed in kwargs where
13
+ # this is used. Works around a warning in Ruby 2.7
14
+
15
+ def class_exec(klass, *args, &block)
16
+ if MethodSignature.new(block).has_kw_args_in?(args)
17
+ binding.eval(<<-CODE, __FILE__, __LINE__)
18
+ kwargs = args.pop
19
+ klass.class_exec(*args, **kwargs, &block)
20
+ CODE
21
+ else
22
+ klass.class_exec(*args, &block)
23
+ end
24
+ end
25
+ ruby2_keywords :class_exec if respond_to?(:ruby2_keywords, true)
26
+ else
27
+ def class_exec(klass, *args, &block)
28
+ klass.class_exec(*args, &block)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/rspec/support.rb CHANGED
@@ -14,7 +14,12 @@ module RSpec
14
14
  def self.define_optimized_require_for_rspec(lib, &require_relative)
15
15
  name = "require_rspec_#{lib}"
16
16
 
17
- if Kernel.respond_to?(:require_relative)
17
+ if RUBY_PLATFORM == 'java' && !Kernel.respond_to?(:require)
18
+ # JRuby 9.1.17.0 has developed a regression for require
19
+ (class << self; self; end).__send__(:define_method, name) do |f|
20
+ Kernel.send(:require, "rspec/#{lib}/#{f}")
21
+ end
22
+ elsif Kernel.respond_to?(:require_relative)
18
23
  (class << self; self; end).__send__(:define_method, name) do |f|
19
24
  require_relative.call("#{lib}/#{f}")
20
25
  end
@@ -84,8 +89,14 @@ module RSpec
84
89
  end
85
90
 
86
91
  # A single thread local variable so we don't excessively pollute that namespace.
87
- def self.thread_local_data
88
- Thread.current[:__rspec] ||= {}
92
+ if RUBY_VERSION.to_f >= 2
93
+ def self.thread_local_data
94
+ Thread.current.thread_variable_get(:__rspec) || Thread.current.thread_variable_set(:__rspec, {})
95
+ end
96
+ else
97
+ def self.thread_local_data
98
+ Thread.current[:__rspec] ||= {}
99
+ end
89
100
  end
90
101
 
91
102
  # @api private
@@ -139,7 +150,7 @@ module RSpec
139
150
  end
140
151
  end
141
152
 
142
- # The Differ is only needed when a a spec fails with a diffable failure.
153
+ # The Differ is only needed when a spec fails with a diffable failure.
143
154
  # In the more common case of all specs passing or the only failures being
144
155
  # non-diffable, we can avoid the extra cost of loading the differ, diff-lcs,
145
156
  # pp, etc by avoiding an unnecessary require. Instead, autoload will take
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 3.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chelimsky
@@ -10,7 +10,7 @@ authors:
10
10
  - Sam Phippen
11
11
  - Xaviery Shay
12
12
  - Bradley Schaefer
13
- autorequire:
13
+ autorequire:
14
14
  bindir: bin
15
15
  cert_chain:
16
16
  - |
@@ -48,34 +48,20 @@ cert_chain:
48
48
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
49
49
  F3MdtaDehhjC
50
50
  -----END CERTIFICATE-----
51
- date: 2018-08-04 00:00:00.000000000 Z
51
+ date: 2023-06-26 00:00:00.000000000 Z
52
52
  dependencies:
53
- - !ruby/object:Gem::Dependency
54
- name: bundler
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.3'
60
- type: :development
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '1.3'
67
53
  - !ruby/object:Gem::Dependency
68
54
  name: rake
69
55
  requirement: !ruby/object:Gem::Requirement
70
56
  requirements:
71
- - - "~>"
57
+ - - ">"
72
58
  - !ruby/object:Gem::Version
73
59
  version: 10.0.0
74
60
  type: :development
75
61
  prerelease: false
76
62
  version_requirements: !ruby/object:Gem::Requirement
77
63
  requirements:
78
- - - "~>"
64
+ - - ">"
79
65
  - !ruby/object:Gem::Version
80
66
  version: 10.0.0
81
67
  - !ruby/object:Gem::Dependency
@@ -122,6 +108,7 @@ files:
122
108
  - lib/rspec/support/source/token.rb
123
109
  - lib/rspec/support/spec.rb
124
110
  - lib/rspec/support/spec/deprecation_helpers.rb
111
+ - lib/rspec/support/spec/diff_helpers.rb
125
112
  - lib/rspec/support/spec/formatting_support.rb
126
113
  - lib/rspec/support/spec/in_sub_process.rb
127
114
  - lib/rspec/support/spec/library_wide_checks.rb
@@ -132,11 +119,17 @@ files:
132
119
  - lib/rspec/support/spec/with_isolated_stderr.rb
133
120
  - lib/rspec/support/version.rb
134
121
  - lib/rspec/support/warnings.rb
122
+ - lib/rspec/support/with_keywords_when_needed.rb
135
123
  homepage: https://github.com/rspec/rspec-support
136
124
  licenses:
137
125
  - MIT
138
- metadata: {}
139
- post_install_message:
126
+ metadata:
127
+ bug_tracker_uri: https://github.com/rspec/rspec-support/issues
128
+ changelog_uri: https://github.com/rspec/rspec-support/blob/v3.12.1/Changelog.md
129
+ documentation_uri: https://rspec.info/documentation/
130
+ mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
131
+ source_code_uri: https://github.com/rspec/rspec-support
132
+ post_install_message:
140
133
  rdoc_options:
141
134
  - "--charset=UTF-8"
142
135
  require_paths:
@@ -152,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
145
  - !ruby/object:Gem::Version
153
146
  version: '0'
154
147
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.6.13
157
- signing_key:
148
+ rubygems_version: 3.4.1
149
+ signing_key:
158
150
  specification_version: 4
159
- summary: rspec-support-3.8.0
151
+ summary: rspec-support-3.12.1
160
152
  test_files: []
metadata.gz.sig CHANGED
Binary file