This commit is contained in:
Benoit Daloze 2021-09-07 19:01:07 +02:00
Родитель a375640ea5
Коммит 258661409e
17 изменённых файлов: 163 добавлений и 7 удалений

Просмотреть файл

@ -28,6 +28,7 @@ ruby/spec is known to be tested in these implementations for every commit:
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
ruby/spec describes the behavior of Ruby 2.6 and more recent Ruby versions.
More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (2.6.x, 2.7.x, 3.0.x, etc), and those are tested in CI.

Просмотреть файл

@ -0,0 +1,17 @@
require_relative '../../spec_helper'
describe 'Array#intersect?' do
ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198
describe 'when at least one element in two Arrays is the same' do
it 'returns true' do
[1, 2].intersect?([2, 3]).should == true
end
end
describe 'when there are no elements in common between two Arrays' do
it 'returns false' do
[1, 2].intersect?([3, 4]).should == false
end
end
end
end

Просмотреть файл

@ -81,6 +81,7 @@ module DirSpecs
special/}
special/test{1}/file[1]
special/{}/special
]
platform_is_not :windows do

Просмотреть файл

@ -80,6 +80,7 @@ describe "Dir.glob" do
nested/.dotsubir/
special/
special/test{1}/
special/{}/
subdir_one/
subdir_two/
]
@ -130,6 +131,7 @@ describe "Dir.glob" do
./nested/.dotsubir/
./special/
./special/test{1}/
./special/{}/
./subdir_one/
./subdir_two/
]

Просмотреть файл

@ -64,6 +64,10 @@ describe :dir_glob, shared: true do
Dir.send(@method, 'special/+').should == ['special/+']
end
it "matches directories with special characters when escaped" do
Dir.send(@method, 'special/\{}/special').should == ["special/{}/special"]
end
platform_is_not :windows do
it "matches regexp special *" do
Dir.send(@method, 'special/\*').should == ['special/*']
@ -191,6 +195,7 @@ describe :dir_glob, shared: true do
nested/
special/
special/test{1}/
special/{}/
subdir_one/
subdir_two/
]

Просмотреть файл

@ -51,7 +51,7 @@ ruby_version_is "3.1" do
enum.tally(hash).should equal(hash)
end
it "raises a FrozenError and does not udpate the given hash when the hash is frozen" do
it "raises a FrozenError and does not update the given hash when the hash is frozen" do
enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
hash = { 'foo' => 1 }.freeze
-> { enum.tally(hash) }.should raise_error(FrozenError)

Просмотреть файл

@ -14,6 +14,9 @@ describe "Float#<=>" do
it "returns nil when the given argument is not a Float" do
(1.0 <=> "1").should be_nil
(1.0 <=> "1".freeze).should be_nil
(1.0 <=> :one).should be_nil
(1.0 <=> true).should be_nil
end
it "compares using #coerce when argument is not a Float" do

Просмотреть файл

@ -1,6 +1,12 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#nil?" do
it "needs to be reviewed for spec completeness"
describe 'Kernel#nil?' do
it 'returns false' do
Object.should_not.nil?
Object.new.should_not.nil?
''.should_not.nil?
[].should_not.nil?
{}.should_not.nil?
end
end

Просмотреть файл

@ -350,6 +350,14 @@ describe "Module#define_method" do
object2.other_cool_method.should == "data is foo"
end
it "accepts a proc from a Symbol" do
symbol_proc = :+.to_proc
klass = Class.new do
define_method :foo, &symbol_proc
end
klass.new.foo(1, 2).should == 3
end
it "maintains the Proc's scope" do
class DefineMethodByProcClass
in_scope = true
@ -715,3 +723,46 @@ describe "Method#define_method when passed a Proc object" do
end
end
end
describe "Method#define_method when passed a block" do
describe "behaves exactly like a lambda" do
it "for return" do
Class.new do
define_method(:foo) do
return 42
end
end.new.foo.should == 42
end
it "for break" do
Class.new do
define_method(:foo) do
break 42
end
end.new.foo.should == 42
end
it "for next" do
Class.new do
define_method(:foo) do
next 42
end
end.new.foo.should == 42
end
it "for redo" do
Class.new do
result = []
define_method(:foo) do
if result.empty?
result << :first
redo
else
result << :second
result
end
end
end.new.foo.should == [:first, :second]
end
end
end

Просмотреть файл

@ -212,6 +212,26 @@ describe "Process.spawn" do
end.should output_to_fd("nil\n")
end
platform_is_not :windows do
it "uses the passed env['PATH'] to search the executable" do
dir = tmp("spawn_path_dir")
mkdir_p dir
begin
exe = 'process-spawn-executable-in-path'
path = "#{dir}/#{exe}"
File.write(path, "#!/bin/sh\necho $1")
File.chmod(0755, path)
env = { "PATH" => "#{dir}#{File::PATH_SEPARATOR}#{ENV['PATH']}" }
Process.wait Process.spawn(env, exe, 'OK', out: @name)
$?.should.success?
File.read(@name).should == "OK\n"
ensure
rm_r dir
end
end
end
it "calls #to_hash to convert the environment" do
o = mock("to_hash")
o.should_receive(:to_hash).and_return({"FOO" => "BAR"})

Просмотреть файл

@ -4,4 +4,8 @@ describe "Rational" do
it "includes Comparable" do
Rational.include?(Comparable).should == true
end
it "does not respond to new" do
-> { Rational.new(1) }.should raise_error(NoMethodError)
end
end

Просмотреть файл

@ -64,13 +64,12 @@ describe 'TracePoint#inspect' do
it 'returns a String showing the event, method, path and line for a :c_call event' do
inspect = nil
line = nil
tp = TracePoint.new(:c_call) { |tp|
tracepoint = TracePoint.new(:c_call) { |tp|
next unless TracePointSpec.target_thread?
inspect ||= tp.inspect
}
line = __LINE__ + 2
tp.enable do
tracepoint.enable do
[0, 1].max
end

Просмотреть файл

@ -32,4 +32,32 @@ describe "Regexps with grouping" do
b # there is no capture group on this line (not even here)
$/x.match("ab").to_a.should == [ "ab", "a" ]
end
it "does not consider # inside a character class as a comment" do
# From https://github.com/rubocop/rubocop/blob/39fcf1c568/lib/rubocop/cop/utils/format_string.rb#L18
regexp = /
% (?<type>%) # line comment
| % (?<flags>(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?#group comment)
(?:
(?: (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?<name>\w+)>)?
| (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?<name>\w+)>) (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))?
| (?-mix:<(?<name>\w+)>) (?<more_flags>(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))?
) (?-mix:(?<type>[bBdiouxXeEfgGaAcps]))
| (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\{(?<name>\w+)\})
)
/x
regexp.named_captures.should == {
"type" => [1, 13],
"flags" => [2],
"width" => [3, 6, 11, 14],
"precision" => [4, 8, 12, 15],
"name" => [5, 7, 9, 16],
"more_flags" => [10]
}
match = regexp.match("%6.3f")
match[:width].should == '6'
match[:precision].should == '3'
match[:type].should == 'f'
match.to_a.should == [ "%6.3f", nil, "", "6", "3"] + [nil] * 8 + ["f"] + [nil] * 3
end
end

Просмотреть файл

@ -22,4 +22,8 @@ describe "Base64#decode64" do
it "returns a binary encoded string" do
Base64.decode64("SEk=").encoding.should == Encoding::BINARY
end
it "decodes without padding suffix ==" do
Base64.decode64("eyJrZXkiOnsibiI6InR0dCJ9fQ").should == "{\"key\":{\"n\":\"ttt\"}}"
end
end

Просмотреть файл

@ -26,7 +26,7 @@ describe 'RbConfig::CONFIG' do
it "['sitelibdir'] is set and is part of $LOAD_PATH" do
sitelibdir = RbConfig::CONFIG['sitelibdir']
sitelibdir.should be_kind_of String
$LOAD_PATH.should.include? sitelibdir
$LOAD_PATH.map{|path| File.realpath(path) rescue path }.should.include? sitelibdir
end
end

Просмотреть файл

@ -527,6 +527,10 @@ static VALUE string_spec_rb_str_vcatf(VALUE self, VALUE mesg) {
return call_rb_str_vcatf(mesg, "fmt %d %d number", 42, 7);
}
static VALUE string_spec_rb_str_catf(VALUE self, VALUE mesg) {
return rb_str_catf(mesg, "fmt %d %d number", 41, 6);
}
void Init_string_spec(void) {
VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject);
rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2);
@ -617,6 +621,7 @@ void Init_string_spec(void) {
rb_define_method(cls, "rb_utf8_str_new", string_spec_rb_utf8_str_new, 0);
rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0);
rb_define_method(cls, "rb_str_vcatf", string_spec_rb_str_vcatf, 1);
rb_define_method(cls, "rb_str_catf", string_spec_rb_str_catf, 1);
}
#ifdef __cplusplus

Просмотреть файл

@ -1154,4 +1154,14 @@ end
str.should == "test fmt 42 7 number"
end
end
describe "rb_str_catf" do
it "appends the message to the string" do
@s.rb_str_catf("").should == "fmt 41 6 number"
str = "test "
@s.rb_str_catf(str)
str.should == "test fmt 41 6 number"
end
end
end