Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with Ruby 3.4.0-preview1 #2028

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- ruby3.1
- ruby3.2
- ruby3.3
- ruby3.4.0-preview1
compiler:
- gcc
- clang
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ end

def ruby_version_string
string = ENV['RUBY'] || DEFAULT_HOST_RUBY_VERSION
raise 'must be in the format rubyX.Y' unless string =~ /^ruby\d\.\d$/
raise 'must be in the format rubyX.Y' unless string =~ /^ruby\d\.\d(?:\.\d-preview\d)?$/
string
end

Expand Down
2 changes: 1 addition & 1 deletion test/natalie/backtrace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Baz < Buz # Buz is undefined
end
end
}.should raise_error(NameError) { |e| bt = e.backtrace }
bt.filter_map { |l| l.match(/<[^>]+>/)&.to_s }.grep_v(/<top \(required\)>/).uniq.should == %w[
bt.filter_map { |l| l.match(/<[^>]+>/)&.to_s }.grep_v(/<top \(required\)>/).grep_v(/<internal:.*>/).uniq.should == %w[
<class:Bar>
<module:Foo>
<main>
Expand Down
12 changes: 10 additions & 2 deletions test/natalie/enumerator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,16 @@ def to_ary
(1...3).step(0.1).last(2).should == [2.8, 2.9]
end

it 'raises if size is bignum and n is bignum' do
-> { (1..bignum_value).step.last(bignum_value) }.should raise_error(RangeError, "bignum too big to convert into `long'")
ruby_version_is ''...'3.4' do
it 'raises if size is bignum and n is bignum' do
-> { (1..bignum_value).step.last(bignum_value) }.should raise_error(RangeError, "bignum too big to convert into `long'")
end
end

ruby_version_is '3.4' do
it 'raises if size is bignum and n is bignum' do
-> { (1..bignum_value).step.last(bignum_value) }.should raise_error(RangeError, "bignum too big to convert into 'long'")
end
end

it 'raises ArgumentError if n is negative' do
Expand Down
36 changes: 35 additions & 1 deletion test/natalie/method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ module Baz
end
end

ruby_version_is '3.3' do
ruby_version_is '3.3'...'3.4' do
it 'raises an error when the method is not defined' do
class Foo
end
Expand Down Expand Up @@ -604,6 +604,40 @@ module Baz
-> { not_a_method() }.should raise_error(NoMethodError, "undefined method `not_a_method' for main")
end
end

ruby_version_is '3.4' do
it 'raises an error when the method is not defined' do
class Foo
end
-> { Foo.new.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for an instance of Foo")
end

it 'does not loop infinitely when trying to call inspect on BasicObject' do
-> { BasicObject.new.inspect }.should raise_error(
NoMethodError,
"undefined method 'inspect' for an instance of BasicObject",
)
end

it 'raises an error when the class method is not defined' do
class Foo
end
-> { Foo.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for class Foo")
end

it 'raises an error when the module method is not defined' do
module Baz
end
-> { Baz.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for module Baz")
end

it 'raises an error when the method of a singleton object is not defined' do
-> { true.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for true")
-> { false.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for false")
-> { nil.not_a_method }.should raise_error(NoMethodError, "undefined method 'not_a_method' for nil")
-> { not_a_method() }.should raise_error(NoMethodError, "undefined method 'not_a_method' for main")
end
end
end

def returns_arg(arg)
Expand Down
26 changes: 24 additions & 2 deletions test/natalie/method_visibility_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def public_bar_calling_private_foo_on_another_object
end
end

ruby_version_is '3.3' do
ruby_version_is '3.3'...'3.4' do
it 'is not visible outside the class' do
-> { Foo.new.private_foo }.should raise_error(
NoMethodError,
Expand All @@ -109,6 +109,19 @@ def public_bar_calling_private_foo_on_another_object
end
end

ruby_version_is '3.4' do
it 'is not visible outside the class' do
-> { Foo.new.private_foo }.should raise_error(
NoMethodError,
"private method 'private_foo' called for an instance of Foo",
)
-> { Foo.new.private_foo2 }.should raise_error(
NoMethodError,
"private method 'private_foo2' called for an instance of Foo",
)
end
end

it 'is visible inside the class' do
Foo.new.public_foo_calling_private_foo.should == 'private'
end
Expand Down Expand Up @@ -136,7 +149,7 @@ def public_bar_calling_private_foo_on_another_object
end
end

ruby_version_is '3.3' do
ruby_version_is '3.3'...'3.4' do
it 'is not visible outside the class' do
-> { Foo.new.protected_foo }.should raise_error(
NoMethodError,
Expand All @@ -145,6 +158,15 @@ def public_bar_calling_private_foo_on_another_object
end
end

ruby_version_is '3.4' do
it 'is not visible outside the class' do
-> { Foo.new.protected_foo }.should raise_error(
NoMethodError,
"protected method 'protected_foo' called for an instance of Foo",
)
end
end

it 'is visible inside the class' do
Foo.new.public_foo_calling_protected_foo.should == 'protected'
end
Expand Down
1 change: 1 addition & 0 deletions test/natalie/string_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: false
# encoding: utf-8

require_relative '../spec_helper'
Expand Down
2 changes: 2 additions & 0 deletions test/support/spec_helpers/tmp.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#frozen_string_literal: false

=begin
Copyright (c) 2008 Engine Yard, Inc. All rights reserved.

Expand Down
Loading