Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Ruby 2.7 support #392

Merged
merged 4 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_rspec_base.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# This file contains defaults for RSpec projects. Individual projects
Expand Down
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# In order to install old Rubies, we need to use old Ubuntu distibution.
Expand All @@ -22,9 +22,10 @@ rvm:
- 2.1
- 2.2.10
- 2.3.8
- 2.4.6
- 2.5.5
- 2.6.2
- 2.4.9
- 2.5.7
- 2.6.5
- 2.7.0
- ruby-head
- ree
- rbx-3
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

version: "{build}"
Expand Down
33 changes: 31 additions & 2 deletions lib/rspec/support/encoded_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,40 @@ def matching_encoding(string)
string = remove_invalid_bytes(string)
string.encode(@encoding)
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
encode_unconvertable_bytes(string)
rescue Encoding::ConverterNotFoundError
string.dup.force_encoding(@encoding).encode(ENCODE_NO_CONVERTER)
encode_no_converter(string.dup.force_encoding(@encoding))
end

private

# On Ruby 2.7.0 keyword arguments mixed with conventional cause a warning to
# be issued requiring us to be explicit by using a ** to pass the hash as
# keyword arguments. Any keyword argument supporting Ruby supports this.
if RubyFeatures.kw_args_supported?
# Note on non keyword supporting Ruby ** causes a syntax error hence
# we must use eval. To be removed in RSpec 4.
binding.eval(<<-CODE, __FILE__, __LINE__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jon for the patch.
That's sad we have to do that to deal with Ruby 2.7.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can't think of another away around it except having an extra file thats not required by the older build... I'm unsure if I like that less...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes me too. The comments help for this part.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While fixing 2.7 compatibility for aruba, I found you can still pass the keyword arguments as a 1.8-style hash literal. This would allow getting rid of the eval. You would also lose the constants though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvz I think that depends on the API in use, I tried the hash directly with String#encode and it still produces the warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonRowe I'm not sure how that happened, but I just had to try as well and it seems to work here too: #394.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂

2.7.0 > "abc".encode("UTF-8", {:invalid => :replace})
(irb):2: warning: Using the last argument as keyword parameters is deprecated
 => "abc"
2.7.0 > "abc".encode("UTF-8", :invalid => :replace)
 => "abc"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂

def encode_unconvertable_bytes(string)
string.encode(@encoding, **ENCODE_UNCONVERTABLE_BYTES)
end

def encode_no_converter(string)
string.encode(**ENCODE_NO_CONVERTER)
end
CODE
else
def encode_unconvertable_bytes(string)
string.encode(@encoding, ENCODE_UNCONVERTABLE_BYTES)
end

def encode_no_converter(string)
string.encode(ENCODE_NO_CONVERTER)
end
end

public

# Prevents raising ArgumentError
if String.method_defined?(:scrub)
# https://github.com/ruby/ruby/blob/eeb05e8c11/doc/NEWS-2.1.0#L120-L123
Expand Down
9 changes: 9 additions & 0 deletions lib/rspec/support/ruby_features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def supports_exception_cause?
end
end

if RUBY_VERSION.to_f >= 2.7
def supports_taint?
false
end
else
def supports_taint?
true
end
end
ripper_requirements = [ComparableVersion.new(RUBY_VERSION) >= '1.9.2']

ripper_requirements.push(false) if Ruby.rbx?
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/support/spec/stderr_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def to_io
def write(line)
return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG

# Ruby 2.7.0 complains about hashes used in place of keyword arguments
# Aruba 0.14.2 uses this internally triggering that here
return if line =~ %r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvz you might be interested

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pirj. This is fixed in Aruba 0.14.14.


@orig_stderr.write(line)
@output_tracker.write(line)
end
Expand Down
2 changes: 1 addition & 1 deletion script/clone_all_rspec_repos
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

set -e
Expand Down
2 changes: 1 addition & 1 deletion script/functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Expand Down
2 changes: 1 addition & 1 deletion script/predicate_functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

function is_mri {
Expand Down
2 changes: 1 addition & 1 deletion script/run_build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

set -e
Expand Down
2 changes: 1 addition & 1 deletion script/travis_functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# Taken from:
Expand Down
2 changes: 1 addition & 1 deletion script/update_rubygems_and_install_bundler
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# This file was generated on 2019-12-18T14:01:39+00:00 from the rspec-dev repo.
# This file was generated on 2019-12-26T17:20:33+00:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

set -e
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec/support/ruby_features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ module Support
RubyFeatures.supports_rebinding_module_methods?
end

specify "#supports_taint?" do
RubyFeatures.supports_taint?
end

specify "#caller_locations_supported? exists" do
RubyFeatures.caller_locations_supported?
if Ruby.mri?
Expand Down