rspec-support 3.13.6 → 4.0.0.beta1

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.
@@ -18,6 +18,14 @@ module RSpec
18
18
  def windows_file_path?
19
19
  ::File::ALT_SEPARATOR == '\\'
20
20
  end
21
+
22
+ def macos?
23
+ !!(RbConfig::CONFIG['host_os']&.downcase =~ /darwin/)
24
+ end
25
+
26
+ def apple_silicon?
27
+ macos? && !!(RbConfig::CONFIG['host_cpu'] =~ /arm64|aarch64/)
28
+ end
21
29
  end
22
30
 
23
31
  # @api private
@@ -34,16 +42,8 @@ module RSpec
34
42
  @jruby_version ||= ComparableVersion.new(JRUBY_VERSION)
35
43
  end
36
44
 
37
- def jruby_9000?
38
- jruby? && JRUBY_VERSION >= '9.0.0.0'
39
- end
40
-
41
45
  def rbx?
42
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
43
- end
44
-
45
- def non_mri?
46
- !mri?
46
+ !!defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
47
47
  end
48
48
 
49
49
  def mri?
@@ -51,7 +51,7 @@ module RSpec
51
51
  end
52
52
 
53
53
  def truffleruby?
54
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby'
54
+ !!defined?(RUBY_ENGINE) && RUBY_ENGINE == 'truffleruby'
55
55
  end
56
56
  end
57
57
 
@@ -62,36 +62,16 @@ module RSpec
62
62
  module RubyFeatures
63
63
  module_function
64
64
 
65
- if Ruby.jruby? && RUBY_VERSION.to_f < 1.9
66
- # On JRuby 1.7 `--1.8` mode, `Process.respond_to?(:fork)` returns true,
67
- # but when you try to fork, it raises an error:
68
- # NotImplementedError: fork is not available on this platform
69
- #
70
- # When we drop support for JRuby 1.7 and/or Ruby 1.8, we can drop
71
- # this special case.
72
- def fork_supported?
73
- false
74
- end
75
- else
76
- def fork_supported?
77
- Process.respond_to?(:fork)
78
- end
65
+ def fork_supported?
66
+ Process.respond_to?(:fork)
79
67
  end
80
68
 
81
- def optional_and_splat_args_supported?
82
- Method.method_defined?(:parameters)
83
- end
84
-
85
- def caller_locations_supported?
86
- respond_to?(:caller_locations, true)
87
- end
88
-
89
- if Exception.method_defined?(:cause)
90
- def supports_exception_cause?
69
+ if Exception.method_defined?(:detailed_message)
70
+ def supports_exception_detailed_message?
91
71
  true
92
72
  end
93
73
  else
94
- def supports_exception_cause?
74
+ def supports_exception_detailed_message?
95
75
  false
96
76
  end
97
77
  end
@@ -106,116 +86,16 @@ module RSpec
106
86
  end
107
87
  end
108
88
 
109
- if RUBY_VERSION.to_f >= 3.0
110
- # https://rubyreferences.github.io/rubychanges/3.0.html#keyword-arguments-are-now-fully-separated-from-positional-arguments
111
- def kw_arg_separation?
112
- true
113
- end
114
- else
115
- def kw_arg_separation?
116
- false
117
- end
118
- end
119
-
120
- if RUBY_VERSION.to_f >= 2.7
121
- def supports_taint?
122
- false
123
- end
124
- else
125
- def supports_taint?
126
- true
127
- end
128
- end
129
- ripper_requirements = [ComparableVersion.new(RUBY_VERSION) >= '1.9.2']
130
-
131
- ripper_requirements.push(false) if Ruby.rbx?
132
-
133
- if Ruby.jruby?
134
- ripper_requirements.push(Ruby.jruby_version >= '1.7.5')
135
- # Ripper on JRuby 9.0.0.0.rc1 - 9.1.8.0 reports wrong line number
136
- # or cannot parse source including `:if`.
137
- # Ripper on JRuby 9.x.x.x < 9.1.17.0 can't handle keyword arguments
138
- # Neither can JRuby 9.2, e.g. < 9.2.1.0
139
- ripper_requirements.push(!Ruby.jruby_version.between?('9.0.0.0.rc1', '9.2.0.0'))
140
- end
141
-
142
89
  # TruffleRuby disables ripper due to low performance
143
- ripper_requirements.push(false) if Ruby.truffleruby?
144
-
145
- if ripper_requirements.all?
146
- def ripper_supported?
147
- true
148
- end
149
- else
90
+ if Ruby.rbx? || Ruby.truffleruby?
150
91
  def ripper_supported?
151
92
  false
152
93
  end
153
- end
154
-
155
- def distincts_kw_args_from_positional_hash?
156
- RUBY_VERSION >= '3.0.0'
157
- end
158
-
159
- if Ruby.mri?
160
- def kw_args_supported?
161
- RUBY_VERSION >= '2.0.0'
162
- end
163
-
164
- def required_kw_args_supported?
165
- RUBY_VERSION >= '2.1.0'
166
- end
167
-
168
- def supports_rebinding_module_methods?
169
- RUBY_VERSION.to_i >= 2
170
- end
171
94
  else
172
- # RBX / JRuby et al support is unknown for keyword arguments
173
- begin
174
- eval("o = Object.new; def o.m(a: 1); end;"\
175
- " raise SyntaxError unless o.method(:m).parameters.include?([:key, :a])")
176
-
177
- def kw_args_supported?
178
- true
179
- end
180
- rescue SyntaxError
181
- def kw_args_supported?
182
- false
183
- end
184
- end
185
-
186
- begin
187
- eval("o = Object.new; def o.m(a: ); end;"\
188
- "raise SyntaxError unless o.method(:m).parameters.include?([:keyreq, :a])")
189
-
190
- def required_kw_args_supported?
191
- true
192
- end
193
- rescue SyntaxError
194
- def required_kw_args_supported?
195
- false
196
- end
197
- end
198
-
199
- begin
200
- Module.new { def foo; end }.instance_method(:foo).bind(Object.new)
201
-
202
- def supports_rebinding_module_methods?
203
- true
204
- end
205
- rescue TypeError
206
- def supports_rebinding_module_methods?
207
- false
208
- end
95
+ def ripper_supported?
96
+ true
209
97
  end
210
98
  end
211
-
212
- def module_refinement_supported?
213
- Module.method_defined?(:refine) || Module.private_method_defined?(:refine)
214
- end
215
-
216
- def module_prepends_supported?
217
- Module.method_defined?(:prepend) || Module.private_method_defined?(:prepend)
218
- end
219
99
  end
220
100
  end
221
101
  end
@@ -25,18 +25,9 @@ module RSpec
25
25
  new(source, path)
26
26
  end
27
27
 
28
- if String.method_defined?(:encoding)
29
- def initialize(source_string, path=nil)
30
- @source = RSpec::Support::EncodedString.new(source_string, Encoding.default_external)
31
- @path = path ? File.expand_path(path) : '(string)'
32
- end
33
- else # for 1.8.7
34
- # :nocov:
35
- def initialize(source_string, path=nil)
36
- @source = RSpec::Support::EncodedString.new(source_string)
37
- @path = path ? File.expand_path(path) : '(string)'
38
- end
39
- # :nocov:
28
+ def initialize(source_string, path=nil)
29
+ @source = RSpec::Support::EncodedString.new(source_string, Encoding.default_external)
30
+ @path = path ? File.expand_path(path) : '(string)'
40
31
  end
41
32
 
42
33
  def lines
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/support'
4
+
5
+ RSpec::Support.require_rspec_support "ruby_features"
6
+
7
+ module RSpec
8
+ module Support
9
+ module Spec
10
+ module Coverage
11
+ def self.setup(&block)
12
+ # Simplecov emits some ruby warnings when loaded, so silence them.
13
+ old_verbose, $VERBOSE = $VERBOSE, false
14
+
15
+ return if ENV['NO_COVERAGE']
16
+ return if RUBY_ENGINE != 'ruby' || RSpec::Support::OS.windows?
17
+
18
+ # Don't load it when we're running a single isolated
19
+ # test file rather than the whole suite.
20
+ #
21
+ # The extra defined check is so that script/rspec_with_simplecov can reuse
22
+ # this logic.
23
+ return if defined?(RSpec.configuration) && RSpec.configuration.files_to_run.one?
24
+
25
+ require 'simplecov'
26
+ start(&block)
27
+ rescue LoadError
28
+ warn "Simplecov could not be loaded"
29
+ ensure
30
+ $VERBOSE = old_verbose
31
+ end
32
+
33
+ def self.start(&block)
34
+ SimpleCov.start do
35
+ add_filter "bundle/"
36
+ add_filter "tmp/"
37
+ add_filter do |source_file|
38
+ # Filter out `spec` directory except when it is under `lib`
39
+ # (as is the case in rspec-support)
40
+ source_file.filename.include?('/spec/') && !source_file.filename.include?('/lib/')
41
+ end
42
+
43
+ instance_eval(&block) if block
44
+ end
45
+ end
46
+ private_class_method :start
47
+ end
48
+ end
49
+ end
50
+ end
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Support
5
5
  module InSubProcess
6
- if Process.respond_to?(:fork) && !(Ruby.jruby? && RUBY_VERSION == '1.8.7')
6
+ if Process.respond_to?(:fork)
7
7
 
8
8
  UnmarshableObject = Struct.new(:error)
9
9
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rspec/support/spec/shell_out'
4
+ RSpec::Support.require_rspec_support 'ruby_features'
4
5
 
5
6
  module RSpec
6
7
  module Support
@@ -10,7 +11,7 @@ module RSpec
10
11
  def check_for_tab_characters(filename)
11
12
  failing_lines = []
12
13
  File.readlines(filename).each_with_index do |line, number|
13
- failing_lines << number + 1 if line =~ /\t/
14
+ failing_lines << (number + 1) if line =~ /\t/
14
15
  end
15
16
 
16
17
  return if failing_lines.empty?
@@ -21,7 +22,7 @@ module RSpec
21
22
  failing_lines = []
22
23
  File.readlines(filename).each_with_index do |line, number|
23
24
  next if line =~ /^\s+#.*\s+\n$/
24
- failing_lines << number + 1 if line =~ /\s+\n$/
25
+ failing_lines << (number + 1) if line =~ /\s+\n$/
25
26
  end
26
27
 
27
28
  return if failing_lines.empty?
@@ -50,7 +51,7 @@ RSpec.shared_examples_for "library wide checks" do |lib, options|
50
51
  extract_regex = /#{Regexp.escape(directory) + File::SEPARATOR}(.+)\.rb$/
51
52
 
52
53
  # We sort to ensure the files are loaded in a consistent order, regardless
53
- # of OS. Otherwise, it could load in a different order on Travis than
54
+ # of OS. Otherwise, it could load in a different order on CI than
54
55
  # locally, and potentially trigger a "circular require considered harmful"
55
56
  # warning or similar.
56
57
  files.sort.map { |file| file[extract_regex, 1] }
@@ -66,7 +67,7 @@ RSpec.shared_examples_for "library wide checks" do |lib, options|
66
67
 
67
68
  stdout, stderr, status = with_env 'NO_COVERAGE' => '1' do
68
69
  options = %w[ -w ]
69
- options << "--disable=gem" if RUBY_VERSION.to_f >= 1.9 && RSpec::Support::Ruby.mri?
70
+ options << "--disable=gem" if RSpec::Support::Ruby.mri?
70
71
  run_ruby_with_current_load_path(command, *options)
71
72
  end
72
73
 
@@ -111,20 +112,16 @@ RSpec.shared_examples_for "library wide checks" do |lib, options|
111
112
  end
112
113
 
113
114
  it "issues no warnings when the spec files are loaded", :slow do
115
+ if RSpec::Support::Ruby.jruby? && RSpec::Support::OS.apple_silicon?
116
+ pending "JRuby on MacOS Apple Silicon outputs warnings due to lack of native console (and stty) support per https://github.com/jruby/jruby/issues/8271"
117
+ end
118
+
114
119
  expect(spec_file_results).to have_successful_no_warnings_output
115
120
  end
116
121
 
117
122
  it 'only loads a known set of stdlibs so gem authors are forced ' \
118
123
  'to load libs they use to have passing specs', :slow do
119
124
  loaded_features = @loaded_feature_lines.split("\n")
120
- if RUBY_VERSION == '1.8.7'
121
- # On 1.8.7, $" returns the relative require path if that was used
122
- # to require the file. LIB_REGEX will not match the relative version
123
- # since it has a `/lib` prefix. Here we deal with this by expanding
124
- # relative files relative to the $LOAD_PATH dir (lib).
125
- Dir.chdir("lib") { loaded_features.map! { |f| File.expand_path(f) } }
126
- end
127
-
128
125
  loaded_features.reject! { |feature| RSpec::CallerFilter::LIB_REGEX =~ feature }
129
126
  loaded_features.reject! { |feature| allowed_loaded_feature_regexps.any? { |r| r =~ feature } }
130
127
 
@@ -18,26 +18,9 @@ module RSpec
18
18
  end
19
19
  end
20
20
 
21
- if Open3.respond_to?(:capture3) # 1.9+
22
- def shell_out(*command)
23
- stdout, stderr, status = Open3.capture3(*command)
24
- return stdout, filter(stderr), status
25
- end
26
- else # 1.8.7
27
- # popen3 doesn't provide the exit status so we fake it out.
28
- FakeProcessStatus = Struct.new(:exitstatus)
29
-
30
- def shell_out(*command)
31
- stdout = stderr = nil
32
-
33
- Open3.popen3(*command) do |_in, out, err|
34
- stdout = out.read
35
- stderr = err.read
36
- end
37
-
38
- status = FakeProcessStatus.new(0)
39
- return stdout, filter(stderr), status
40
- end
21
+ def shell_out(*command)
22
+ stdout, stderr, status = Open3.capture3(*command)
23
+ return stdout, filter(stderr), status
41
24
  end
42
25
 
43
26
  def run_ruby_with_current_load_path(ruby_command, *flags)
@@ -61,13 +44,9 @@ module RSpec
61
44
  %r{bundler/source/rubygems},
62
45
  # Ignore bundler + rubygems warning.
63
46
  %r{site_ruby/\d\.\d\.\d/rubygems},
64
- %r{site_ruby/\d\.\d\.\d/bundler},
65
47
  %r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/rubygems},
66
- %r{lib/rubygems/custom_require},
67
48
  # This is required for windows for some reason
68
49
  %r{lib/bundler/rubygems},
69
- # This is a JRuby file that generates warnings on 9.0.3.0
70
- %r{lib/ruby/stdlib/jar},
71
50
  # This is a JRuby file that generates warnings on 9.1.7.0
72
51
  %r{org/jruby/RubyKernel\.java},
73
52
  # This is a JRuby gem that generates warnings on 9.1.7.0
@@ -84,7 +63,6 @@ module RSpec
84
63
  # Ignore some JRuby errors for gems
85
64
  %r{jruby/\d\.\d(\.\d)?/gems/aruba},
86
65
  %r{jruby/\d\.\d(\.\d)?/gems/ffi},
87
- %r{warning: encoding options not supported in 1\.8},
88
66
  # Ignore errors from asdf
89
67
  %r{\.asdf/installs},
90
68
  ]
@@ -11,9 +11,8 @@ module RSpec
11
11
  @last_line = nil
12
12
  end
13
13
 
14
- respond_to_name = (::RUBY_VERSION.to_f < 1.9) ? :respond_to? : :respond_to_missing?
15
- define_method respond_to_name do |*args|
16
- @orig_stderr.respond_to?(*args) || super(*args)
14
+ def respond_to_missing?(*args)
15
+ @orig_stderr.respond_to?(*args) || super
17
16
  end
18
17
 
19
18
  def method_missing(name, *args, &block)
@@ -21,6 +20,10 @@ module RSpec
21
20
  @orig_stderr.__send__(name, *args, &block)
22
21
  end
23
22
 
23
+ def clone
24
+ StdErrSplitter.new(@orig_stderr.clone)
25
+ end
26
+
24
27
  def ==(other)
25
28
  @orig_stderr == other
26
29
  end
@@ -30,26 +33,10 @@ module RSpec
30
33
  @orig_stderr.reopen(*args)
31
34
  end
32
35
 
33
- # To work around JRuby error:
34
- # can't convert RSpec::Support::StdErrSplitter into String
35
- def to_io
36
- @orig_stderr.to_io
37
- end
38
-
39
- # To work around JRuby error:
40
- # TypeError: $stderr must have write method, RSpec::StdErrSplitter given
41
36
  def write(line)
37
+ # Ignore warnings coming from gems, specifically Rails
42
38
  return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG
43
39
 
44
- # Ruby 2.7.0 warnings from keyword arguments span multiple lines, extend check above
45
- # to look for the next line.
46
- return if @last_line =~ %r{^\S+/gems/\S+:\d+: warning:} &&
47
- line =~ %r{warning: The called method .* is defined here}
48
-
49
- # Ruby 2.7.0 complains about hashes used in place of keyword arguments
50
- # Aruba 0.14.2 uses this internally triggering that here
51
- return if line =~ %r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:}
52
-
53
40
  @orig_stderr.write(line)
54
41
  @output_tracker.write(line)
55
42
  ensure
@@ -6,36 +6,26 @@ require 'rspec/matchers'
6
6
  # which also relies on EncodedString. Instead, confirm the
7
7
  # strings have the same bytes.
8
8
  RSpec::Matchers.define :be_identical_string do |expected|
9
- if String.method_defined?(:encoding)
10
- match do
11
- expected_encoding? &&
12
- actual.bytes.to_a == expected.bytes.to_a
13
- end
14
-
15
- failure_message do
16
- "expected\n#{actual.inspect} (#{actual.encoding.name}) to be identical to\n"\
17
- "#{expected.inspect} (#{expected.encoding.name})\n"\
18
- "The exact bytes are printed below for more detail:\n"\
19
- "#{actual.bytes.to_a}\n"\
20
- "#{expected.bytes.to_a}\n"\
21
- end
9
+ match do
10
+ expected_encoding? &&
11
+ actual.bytes.to_a == expected.bytes.to_a
12
+ end
22
13
 
23
- # Depends on chaining :with_same_encoding for it to
24
- # check for string encoding.
25
- def expected_encoding?
26
- if defined?(@expect_same_encoding) && @expect_same_encoding
27
- actual.encoding == expected.encoding
28
- else
29
- true
30
- end
31
- end
32
- else
33
- match do
34
- actual.split(//) == expected.split(//)
35
- end
14
+ failure_message do
15
+ "expected\n#{actual.inspect} (#{actual.encoding.name}) to be identical to\n" \
16
+ "#{expected.inspect} (#{expected.encoding.name})\n" \
17
+ "The exact bytes are printed below for more detail:\n" \
18
+ "#{actual.bytes.to_a}\n" \
19
+ "#{expected.bytes.to_a}\n" \
20
+ end
36
21
 
37
- failure_message do
38
- "expected\n#{actual.inspect} to be identical to\n#{expected.inspect}\n"
22
+ # Depends on chaining :with_same_encoding for it to
23
+ # check for string encoding.
24
+ def expected_encoding?
25
+ if defined?(@expect_same_encoding) && @expect_same_encoding
26
+ actual.encoding == expected.encoding
27
+ else
28
+ true
39
29
  end
40
30
  end
41
31
 
@@ -3,8 +3,8 @@
3
3
  require 'rspec/support'
4
4
  require 'rspec/support/spec/in_sub_process'
5
5
 
6
+ RSpec::Support.require_rspec_support "spec/coverage"
6
7
  RSpec::Support.require_rspec_support "spec/deprecation_helpers"
7
- RSpec::Support.require_rspec_support "spec/diff_helpers"
8
8
  RSpec::Support.require_rspec_support "spec/with_isolated_stderr"
9
9
  RSpec::Support.require_rspec_support "spec/stderr_splitter"
10
10
  RSpec::Support.require_rspec_support "spec/formatting_support"
@@ -19,6 +19,8 @@ RSpec.configure do |c|
19
19
  c.include RSpec::Support::FormattingSupport
20
20
  c.include RSpec::Support::InSubProcess
21
21
 
22
+ c.warnings = :all
23
+
22
24
  unless defined?(Debugger) # debugger causes warnings when used
23
25
  c.before do
24
26
  warning_preventer.reset!
@@ -42,43 +44,3 @@ RSpec.configure do |c|
42
44
  meta[:pending] ||= "This spec fails on Windows CI and needs someone to fix it."
43
45
  end if RSpec::Support::OS.windows? && ENV['CI']
44
46
  end
45
-
46
- module RSpec
47
- module Support
48
- module Spec
49
- def self.setup_simplecov(&block)
50
- # Simplecov emits some ruby warnings when loaded, so silence them.
51
- old_verbose, $VERBOSE = $VERBOSE, false
52
-
53
- return if ENV['NO_COVERAGE'] || RUBY_VERSION < '1.9.3'
54
- return if RUBY_ENGINE != 'ruby' || RSpec::Support::OS.windows?
55
-
56
- # Don't load it when we're running a single isolated
57
- # test file rather than the whole suite.
58
- return if RSpec.configuration.files_to_run.one?
59
-
60
- require 'simplecov'
61
- start_simplecov(&block)
62
- rescue LoadError
63
- warn "Simplecov could not be loaded"
64
- ensure
65
- $VERBOSE = old_verbose
66
- end
67
-
68
- def self.start_simplecov(&block)
69
- SimpleCov.start do
70
- add_filter "bundle/"
71
- add_filter "tmp/"
72
- add_filter do |source_file|
73
- # Filter out `spec` directory except when it is under `lib`
74
- # (as is the case in rspec-support)
75
- source_file.filename.include?('/spec/') && !source_file.filename.include?('/lib/')
76
- end
77
-
78
- instance_eval(&block) if block
79
- end
80
- end
81
- private_class_method :start_simplecov
82
- end
83
- end
84
- end
@@ -3,7 +3,7 @@
3
3
  module RSpec
4
4
  module Support
5
5
  module Version
6
- STRING = '3.13.6'
6
+ STRING = '4.0.0.beta1'
7
7
  end
8
8
  end
9
9
  end
@@ -10,26 +10,17 @@ module RSpec
10
10
 
11
11
  module_function
12
12
 
13
- if RSpec::Support::RubyFeatures.kw_args_supported?
14
- # Remove this in RSpec 4 in favour of explicitly passed in kwargs where
15
- # this is used. Works around a warning in Ruby 2.7
16
-
17
- def class_exec(klass, *args, &block)
18
- if MethodSignature.new(block).has_kw_args_in?(args)
19
- binding.eval(<<-CODE, __FILE__, __LINE__)
20
- kwargs = args.pop
21
- klass.class_exec(*args, **kwargs, &block)
22
- CODE
23
- else
24
- klass.class_exec(*args, &block)
25
- end
26
- end
27
- ruby2_keywords :class_exec if respond_to?(:ruby2_keywords, true)
28
- else
29
- def class_exec(klass, *args, &block)
13
+ # Remove this in RSpec 4 in favour of explicitly passed in kwargs where
14
+ # this is used. Works around a warning in Ruby 2.7
15
+ def class_exec(klass, *args, &block)
16
+ if MethodSignature.new(block).has_kw_args_in?(args)
17
+ kwargs = args.pop
18
+ klass.class_exec(*args, **kwargs, &block)
19
+ else
30
20
  klass.class_exec(*args, &block)
31
21
  end
32
22
  end
23
+ ruby2_keywords :class_exec if respond_to?(:ruby2_keywords, true)
33
24
  end
34
25
  end
35
26
  end