1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-04-28 19:50:06 +00:00
parent b864bd05bf
commit 4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions

View file

@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-12-15 22:14:22 +0900 using RuboCop version 0.52.0.
# on 2018-04-03 22:23:59 +0900 using RuboCop version 0.54.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@ -20,11 +20,6 @@ Lint/DuplicateMethods:
- 'core/unboundmethod/fixtures/classes.rb'
- 'fixtures/class.rb'
# Offense count: 4
Lint/EmptyWhen:
Exclude:
- 'language/case_spec.rb'
# Offense count: 5
Lint/EnsureReturn:
Exclude:
@ -43,7 +38,7 @@ Lint/FormatParameterMismatch:
- 'core/kernel/shared/sprintf.rb'
- 'core/string/modulo_spec.rb'
# Offense count: 28
# Offense count: 29
Lint/HandleExceptions:
Enabled: false
@ -59,7 +54,7 @@ Lint/IneffectiveAccessModifier:
- 'core/module/fixtures/classes.rb'
- 'language/fixtures/private.rb'
# Offense count: 5
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: runtime_error, standard_error
@ -69,13 +64,13 @@ Lint/InheritException:
- 'core/exception/fixtures/common.rb'
- 'core/module/fixtures/autoload_ex1.rb'
# Offense count: 3
# Offense count: 5
# Cop supports --auto-correct.
Lint/LiteralInInterpolation:
Exclude:
- 'core/module/refine_spec.rb'
- 'language/defined_spec.rb'
- 'language/fixtures/squiggly_heredoc.rb'
- 'core/module/refine_spec.rb'
# Offense count: 16
Lint/Loop:
@ -105,7 +100,7 @@ Lint/RedundantWithIndex:
Exclude:
- 'core/enumerator/with_index_spec.rb'
# Offense count: 24
# Offense count: 26
Lint/RescueException:
Exclude:
- 'command_line/fixtures/debug_info.rb'
@ -200,3 +195,9 @@ Lint/UselessAccessModifier:
- 'core/module/module_function_spec.rb'
- 'core/module/private_class_method_spec.rb'
- 'language/fixtures/send.rb'
# Offense count: 6186
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 588

View file

@ -6,18 +6,17 @@ script:
- ../mspec/bin/mspec $MSPEC_OPTS
matrix:
include:
- rvm: 2.5.0
- rvm: 2.5.1
env: MSPEC_OPTS="-R2 -ff"
- rvm: 2.2.9
- rvm: 2.3.6
- rvm: 2.4.3
- rvm: 2.5.0
- rvm: 2.3.7
- rvm: 2.4.4
- rvm: 2.5.1
env: CHECK_LEAKS=true
- rvm: ruby-head
- env: RUBOCOP=true
rvm: 2.4.3
rvm: 2.4.4
script:
- gem install rubocop -v 0.52.0
- gem install rubocop -v 0.54.0
- rubocop
allow_failures:
- rvm: ruby-head

View file

@ -25,16 +25,20 @@ The language specs are grouped by keyword while the core and standard library sp
ruby/spec is known to be tested in these implementations for every commit:
* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
* [TruffleRuby](https://github.com/oracle/truffleruby)
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)
ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions.
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
Each of these repositories has a full copy of the files to ease editing specs.
ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
(latest 2.2.x, 2.3.x, 2.4.x, etc).
(2.3.x, 2.4.x, 2.5.x, etc).
For older specs try these commits:
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed)
* Ruby 2.2.10 - [Suite](https://github.com/ruby/spec/commit/cbaa0e412270c944df0c2532fc500c920dba0e92) using [MSpec](https://github.com/ruby/mspec/commit/d84d7668449e96856c5f6bac8cb1526b6d357ce3)
### Running the specs

View file

@ -8,4 +8,42 @@ describe "The -I command line option" do
it "adds the path to the load path ($:)" do
ruby_exe(@script, options: "-I fixtures").should include("fixtures")
end
it "adds the path at the front of $LOAD_PATH" do
lines = ruby_exe(@script, options: "-I fixtures").lines
if File.basename(ruby_exe[0]) == "miniruby"
# In a MRI checkout, $PWD ends up as the first entry in $LOAD_PATH.
# So just assert that it's at the beginning.
idx = lines.index { |l| l.include?("fixtures") }
idx.should < 2
idx.should < lines.size-1
else
lines[0].should include("fixtures")
end
end
it "adds the path expanded from CWD to $LOAD_PATH" do
ruby_exe(@script, options: "-I fixtures").lines.should include "#{Dir.pwd}/fixtures\n"
end
it "expands a path from CWD even if it does not exist" do
ruby_exe(@script, options: "-I not_exist/not_exist").lines.should include "#{Dir.pwd}/not_exist/not_exist\n"
end
end
describe "The -I command line option" do
before :each do
@script = fixture __FILE__, "loadpath.rb"
@fixtures = File.dirname(@script)
@symlink = tmp("loadpath_symlink")
File.symlink(@fixtures, @symlink)
end
after :each do
rm_r @symlink
end
it "does not expand symlinks" do
ruby_exe(@script, options: "-I #{@symlink}").lines.should include "#{@symlink}\n"
end
end

View file

@ -1,6 +1,5 @@
require_relative '../spec_helper'
ruby_version_is "2.3" do
describe "The --enable-frozen-string-literal flag causes string literals to" do
it "produce the same object each time" do
@ -27,4 +26,3 @@ ruby_version_is "2.3" do
error_str.should include("command_line/fixtures/debug_info.rb:2")
end
end
end

View file

@ -20,16 +20,6 @@ describe "ARGF.close" do
end
end
ruby_version_is ""..."2.3" do
it "raises an IOError if called on a closed stream" do
argf [@file1_name] do
lambda { @argf.close }.should_not raise_error
lambda { @argf.close }.should raise_error(IOError)
end
end
end
ruby_version_is "2.3" do
it "doesn't raise an IOError if called on a closed stream" do
argf [@file1_name] do
lambda { @argf.close }.should_not raise_error
@ -37,7 +27,6 @@ describe "ARGF.close" do
end
end
end
end
describe "ARGF.close" do
it "does not close STDIN" do

View file

@ -70,7 +70,6 @@ platform_is_not :windows do
end
end
ruby_version_is "2.3" do
it 'returns :wait_readable when the :exception is set to false' do
argf ['-'] do
@argf.read_nonblock(4, nil, exception: false).should == :wait_readable
@ -79,4 +78,3 @@ platform_is_not :windows do
end
end
end
end

View file

@ -54,7 +54,6 @@ describe "ARGF.readpartial" do
end
end
ruby_version_is "2.3" do
it "raises an EOFError if the exception was raised while reading the last file" do
argf [@file1_name, @file2_name] do
@argf.readpartial(@file1.size)
@ -64,7 +63,6 @@ describe "ARGF.readpartial" do
lambda { @argf.readpartial(1) }.should raise_error(EOFError)
end
end
end
it "raises an EOFError if the exception was raised while reading STDIN" do
ruby_str = <<-STR

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative '../enumerable/shared/enumeratorized'
ruby_version_is "2.3" do
describe "Array#bsearch_index" do
context "when not passed a block" do
before :each do
@ -84,4 +83,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is '2.3' do
describe "Array#dig" do
it "returns #at with one arg" do
@ -51,4 +50,3 @@ ruby_version_is '2.3' do
end
end
end

View file

@ -69,13 +69,11 @@ describe "Array#flatten" do
[1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6]
end
ruby_version_is "2.3" do
it "does not call #to_ary on elements beyond the given level" do
obj = mock("1")
obj.should_not_receive(:to_ary)
[[obj]].flatten(1)
end
end
it "returns subclass instance for Array subclasses" do
ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray)

View file

@ -4,7 +4,6 @@ require_relative 'shared/basic'
require_relative 'shared/numeric_basic'
require_relative 'shared/integer'
ruby_version_is '2.3' do
platform_is pointer_size: 64 do
describe "Array#pack with format 'J'" do
it_behaves_like :array_pack_basic, 'J'
@ -216,4 +215,3 @@ ruby_version_is '2.3' do
end
end
end
end

View file

@ -3,7 +3,6 @@ describe :delete_if, shared: true do
@object = [1,2,3]
end
ruby_version_is "2.3" do
it "updates the receiver after all blocks" do
@object.send(@method) do |e|
@object.length.should == 3
@ -12,16 +11,3 @@ describe :delete_if, shared: true do
@object.length.should == 0
end
end
ruby_version_is ""..."2.3" do
it "updates the receiver after each true block" do
count = 0
@object.send(@method) do |e|
@object.length.should == (3 - count)
count += 1
true
end
@object.length.should == 0
end
end
end

View file

@ -121,18 +121,6 @@ describe :array_inspect, shared: true do
array.send(@method).encoding.name.should == "US-ASCII"
end
ruby_version_is ''...'2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
lambda {
[utf_16be].send(@method)
}.should raise_error(Encoding::CompatibilityError)
end
end
ruby_version_is '2.3' do
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
@ -141,4 +129,3 @@ describe :array_inspect, shared: true do
end
end
end
end

View file

@ -48,18 +48,10 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_return("abc")
end
ruby_version_is ""..."2.3" do
it "returns false" do
(a == b).should be_false
end
end
ruby_version_is "2.3" do
it "raises an ArgumentError" do
lambda { (a == b) }.should raise_error(ArgumentError)
end
end
end
context "when #<=> raises an exception" do
context "if it is a StandardError" do
@ -67,19 +59,10 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_raise(StandardError)
end
ruby_version_is ""..."2.3" do
# Behaviour confirmed by MRI test suite
it "returns false" do
(a == b).should be_false
end
end
ruby_version_is "2.3" do
it "lets it go through" do
lambda { (a == b) }.should raise_error(StandardError)
end
end
end
context "if it is a subclass of StandardError" do
# TypeError < StandardError
@ -87,18 +70,10 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_raise(TypeError)
end
ruby_version_is ""..."2.3" do
it "returns false" do
(a == b).should be_false
end
end
ruby_version_is "2.3" do
it "lets it go through" do
lambda { (a == b) }.should raise_error(TypeError)
end
end
end
it "lets it go through if it is not a StandardError" do
a.should_receive(:<=>).once.and_raise(Exception)

View file

@ -1,9 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
ruby_version_is ''...'2.3' do
require_relative 'shared/closed'
end
describe "Dir#close" do
before :all do
DirSpecs.create_mock_dirs
@ -13,11 +9,6 @@ describe "Dir#close" do
DirSpecs.delete_mock_dirs
end
ruby_version_is ''...'2.3' do
it_behaves_like :dir_closed, :close
end
ruby_version_is '2.3' do
it "does not raise an IOError even if the Dir instance is closed" do
dir = Dir.open DirSpecs.mock_dir
dir.close
@ -26,4 +17,3 @@ describe "Dir#close" do
}.should_not raise_error(IOError)
end
end
end

View file

@ -32,6 +32,15 @@ describe :dir_glob, shared: true do
end
end
ruby_version_is "2.6" do
it "splits the string on \\0 if there is only one string given and warns" do
-> {
Dir.send(@method, "file_o*\0file_t*").should ==
%w!file_one.ext file_two.ext!
}.should complain(/warning: use glob patterns list instead of nul-separated patterns/)
end
end
it "matches non-dotfiles with '*'" do
expected = %w[
brace

View file

@ -62,35 +62,12 @@ describe "Enumerable#chunk" do
lambda { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError)
end
ruby_version_is ""..."2.3" do
describe "with [initial_state]" do
it "yields an element and an object value-equal but not identical to the object passed to #chunk" do
e = EnumerableSpecs::Numerous.new(1)
value = "value"
e.chunk(value) do |x, v|
x.should == 1
v.should == value
v.should_not equal(value)
end.to_a
end
it "does not yield the object passed to #chunk if it is nil" do
e = EnumerableSpecs::Numerous.new(1)
e.chunk(nil) { |*x| ScratchPad << x }.to_a
ScratchPad.recorded.should == [[1]]
end
end
end
ruby_version_is "2.3" do
it "does not accept arguments" do
e = EnumerableSpecs::Numerous.new(1, 2, 3)
lambda {
e.chunk(1) {}
}.should raise_error(ArgumentError)
end
end
it 'returned Enumerator size returns nil' do
e = EnumerableSpecs::NumerousWithSize.new(1, 2, 3, 2, 1)

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Enumerable#chunk_while" do
before :each do
ary = [10, 9, 7, 6, 4, 3, 2, 1]
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Enumerable#grep_v" do
before :each do
@numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
@ -40,4 +39,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -40,35 +40,12 @@ describe "Enumerable#slice_before" do
end
end
ruby_version_is ""..."2.3" do
describe "and an argument" do
it "calls the block with a copy of that argument" do
arg = [:foo]
first = nil
e = @enum.slice_before(arg) do |i, init|
init.should == arg
init.should_not equal(arg)
first = init
i == 6 || i == 2
end
e.should be_an_instance_of(Enumerator)
e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]]
e = @enum.slice_before(arg) do |i, init|
init.should_not equal(first)
end
e.to_a
end
end
end
ruby_version_is "2.3" do
it "does not accept arguments" do
lambda {
@enum.slice_before(1) {}
}.should raise_error(ArgumentError)
end
end
end
it "raises an ArgumentError when given an incorrect number of arguments" do
lambda { @enum.slice_before("one", "two") }.should raise_error(ArgumentError)

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Enumerator::Lazy#grep_v" do
before(:each) do
@yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy
@ -83,4 +82,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -13,7 +13,7 @@ ruby_version_is '2.4' do
@lazy.force.should == [0, 1]
end
ruby_bug "#14495", "2.4"..."2.5.1" do
ruby_bug "#14495", "2.4"..."2.5.2" do
it 'return same value after rewind' do
@lazy.force.should == [0, 1]
@lazy.force.should == [0, 1]
@ -35,7 +35,7 @@ ruby_version_is '2.4' do
@lazy.force.should == [0, 1]
end
ruby_bug "#14495", "2.4"..."2.5.1" do
ruby_bug "#14495", "2.4"..."2.5.2" do
it 'return same value after rewind' do
@lazy.force.should == [0, 1]
@lazy.force.should == [0, 1]
@ -60,7 +60,7 @@ ruby_version_is '2.4' do
@lazy = enum.lazy
end
ruby_bug "#14495", "2.4"..."2.5.1" do
ruby_bug "#14495", "2.4"..."2.5.2" do
it 'return same value after rewind' do
enum = @lazy.uniq { |_, label| label.downcase }
enum.force.should == [[0, 'foo'], [2, 'bar']]

View file

@ -0,0 +1,39 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
describe "Exception#backtrace_locations" do
before :each do
@backtrace = ExceptionSpecs::Backtrace.backtrace_locations
end
it "returns nil if no backtrace was set" do
Exception.new.backtrace_locations.should be_nil
end
it "returns an Array" do
@backtrace.should be_an_instance_of(Array)
end
it "sets each element to a Thread::Backtrace::Location" do
@backtrace.each {|l| l.should be_an_instance_of(Thread::Backtrace::Location)}
end
it "produces a backtrace for an exception captured using $!" do
exception = begin
raise
rescue RuntimeError
$!
end
exception.backtrace_locations.first.path.should =~ /backtrace_locations_spec/
end
it "returns an Array that can be updated" do
begin
raise
rescue RuntimeError => e
e.backtrace_locations.unshift "backtrace first"
e.backtrace_locations[0].should == "backtrace first"
end
end
end

View file

@ -4,11 +4,19 @@ module ExceptionSpecs
class Backtrace
def self.backtrace
begin
raise # Do not move this line or update backtrace_spec.rb
raise # If you move this line, update backtrace_spec.rb
rescue RuntimeError => e
e.backtrace
end
end
def self.backtrace_locations
begin
raise
rescue RuntimeError => e
e.backtrace_locations
end
end
end
class UnExceptional < Exception

View file

@ -0,0 +1,38 @@
require_relative '../../spec_helper'
ruby_version_is "2.5" do
describe "Exception#full_message" do
it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do
e = RuntimeError.new("Some runtime error")
e.set_backtrace(["a.rb:1", "b.rb:2"])
full_message = e.full_message
full_message.should include "RuntimeError"
full_message.should include "Some runtime error"
full_message.should include "a.rb:1"
full_message.should include "b.rb:2"
end
ruby_version_is "2.5.1" do
it "supports :highlight option and adds escape sequences to highlight some strings" do
e = RuntimeError.new("Some runtime error")
full_message = e.full_message(highlight: true, order: :bottom)
full_message.should include "\e[1mTraceback\e[m (most recent call last)"
full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
full_message = e.full_message(highlight: false, order: :bottom)
full_message.should include "Traceback (most recent call last)"
full_message.should include "Some runtime error (RuntimeError)"
end
it "supports :order option and places the error message and the backtrace at the top or the bottom" do
e = RuntimeError.new("Some runtime error")
e.set_backtrace(["a.rb:1", "b.rb:2"])
e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
end
end
end
end

View file

@ -27,21 +27,6 @@ describe "NameError#name" do
}.should raise_error(NameError) { |e| e.name.should == :@@doesnt_exist }
end
ruby_version_is ""..."2.3" do
it "always returns a symbol when a NameError is raised from #instance_variable_get" do
-> {
Object.new.instance_variable_get("invalid_ivar_name")
}.should raise_error(NameError) { |e| e.name.should == :invalid_ivar_name }
end
it "always returns a symbol when a NameError is raised from #class_variable_get" do
-> {
Object.class_variable_get("invalid_cvar_name")
}.should raise_error(NameError) { |e| e.name.should == :invalid_cvar_name }
end
end
ruby_version_is "2.3" do
it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do
invalid_ivar_name = "invalid_ivar_name"
@ -58,4 +43,3 @@ describe "NameError#name" do
}.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) }
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
ruby_version_is "2.3" do
describe "NameError#receiver" do
class ::ReceiverClass
def call_undefined_class_variable; @@doesnt_exist end
@ -59,4 +58,3 @@ ruby_version_is "2.3" do
-> { NameError.new.receiver }.should raise_error(ArgumentError)
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe "File.mkfifo" do
platform_is_not :windows do
before do
@ -50,4 +49,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -524,7 +524,6 @@ describe "File.open" do
File.size(@file).should == 0
end
ruby_version_is "2.3" do
platform_is :linux do
guard -> { defined?(File::TMPFILE) } do
it "creates an unnamed temporary file with File::TMPFILE" do
@ -549,7 +548,6 @@ describe "File.open" do
end
end
end
end
it "raises a TypeError if passed a filename that is not a String or Integer type" do
lambda { File.open(true) }.should raise_error(TypeError)
@ -586,7 +584,6 @@ describe "File.open" do
@fh = File.open(@file, options)
end
ruby_version_is "2.3" do
it "accepts extra flags as a keyword argument and combine with a string mode" do
lambda {
File.open(@file, "w", flags: File::EXCL) { }
@ -602,7 +599,6 @@ describe "File.open" do
File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { }
}.should raise_error(Errno::EEXIST)
end
end
platform_is_not :windows do
describe "on a FIFO" do

View file

@ -48,7 +48,6 @@ describe :file_unlink, shared: true do
File.send(@method, mock_to_path(@file1)).should == 1
end
ruby_version_is "2.3" do
platform_is :windows do
it "allows deleting an open file with File::SHARE_DELETE" do
path = tmp("share_delete.txt")
@ -60,4 +59,3 @@ describe :file_unlink, shared: true do
end
end
end
end

View file

@ -19,15 +19,6 @@ describe "File::Stat#ino" do
end
platform_is :windows do
ruby_version_is ""..."2.3" do
it "returns 0" do
st = File.stat(@file)
st.ino.should be_kind_of(Integer)
st.ino.should == 0
end
end
ruby_version_is "2.3" do
it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do
st = File.stat(@file)
st.ino.should be_kind_of(Integer)
@ -35,4 +26,3 @@ describe "File::Stat#ino" do
end
end
end
end

View file

@ -108,7 +108,7 @@ describe "Hash#compare_by_identity" do
@idh.keys.first.should equal foo
end
ruby_bug "#12855", "2.2.0"..."2.4.1" do
ruby_bug "#12855", ""..."2.4.1" do
it "gives different identity for string literals" do
@idh['foo'] = 1
@idh['foo'] = 2

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is '2.3' do
describe "Hash#dig" do
it "returns #[] with one arg" do
@ -65,4 +64,3 @@ ruby_version_is '2.3' do
h.dig(:foo, :bar).should == 42
end
end
end

View file

@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative '../../shared/hash/key_error'
ruby_version_is "2.3" do
describe "Hash#fetch_values" do
before :each do
@hash = { a: 1, b: 2, c: 3 }
@ -30,4 +29,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -17,6 +17,13 @@ module HashSpecs
end
end
class SubHashSettingInInitialize < Hash
def initialize(*args, &block)
self[:foo] = :bar
super(*args, &block)
end
end
class DefaultHash < Hash
def default(key)
100

View file

@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require_relative 'shared/comparison'
require_relative 'shared/greater_than'
ruby_version_is "2.3" do
describe "Hash#>" do
it_behaves_like :hash_comparison, :>
it_behaves_like :hash_greater_than, :>
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
(@similar > @hash).should == false
end
end
end

View file

@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require_relative 'shared/comparison'
require_relative 'shared/greater_than'
ruby_version_is "2.3" do
describe "Hash#>=" do
it_behaves_like :hash_comparison, :>=
it_behaves_like :hash_greater_than, :>=
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
(@similar >= @hash).should == false
end
end
end

View file

@ -9,16 +9,37 @@ describe "Hash#initialize" do
it "can be used to reset default_proc" do
h = { "foo" => 1, "bar" => 2 }
h.default_proc.should == nil
h.instance_eval { initialize { |_, k| k * 2 } }
h.send(:initialize) { |_, k| k * 2 }
h.default_proc.should_not == nil
h["a"].should == "aa"
end
it "can be used to reset the default value" do
h = {}
h.default = 42
h.default.should == 42
h.send(:initialize, 1)
h.default.should == 1
h.send(:initialize)
h.default.should == nil
end
it "receives the arguments passed to Hash#new" do
HashSpecs::NewHash.new(:one, :two)[0].should == :one
HashSpecs::NewHash.new(:one, :two)[1].should == :two
end
it "does not change the storage, only the default value or proc" do
h = HashSpecs::SubHashSettingInInitialize.new
h.to_a.should == [[:foo, :bar]]
h = HashSpecs::SubHashSettingInInitialize.new(:default)
h.to_a.should == [[:foo, :bar]]
h = HashSpecs::SubHashSettingInInitialize.new { :default_block }
h.to_a.should == [[:foo, :bar]]
end
it "returns self" do
h = Hash.new
h.send(:initialize).should equal(h)

View file

@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require_relative 'shared/comparison'
require_relative 'shared/less_than'
ruby_version_is "2.3" do
describe "Hash#<" do
it_behaves_like :hash_comparison, :<
it_behaves_like :hash_less_than, :<
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
(@similar < @hash).should == false
end
end
end

View file

@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require_relative 'shared/comparison'
require_relative 'shared/less_than'
ruby_version_is "2.3" do
describe "Hash#<=" do
it_behaves_like :hash_comparison, :<=
it_behaves_like :hash_less_than, :<=
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
(@similar <= @hash).should == false
end
end
end

View file

@ -87,18 +87,6 @@ describe :hash_to_s, shared: true do
{ nil => nil }.untrust.send(@method).untrusted?.should be_true
end
ruby_version_is ''...'2.3' do
it "raises if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
lambda {
{a: utf_16be}.send(@method)
}.should raise_error(Encoding::CompatibilityError)
end
end
ruby_version_is '2.3' do
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
@ -106,4 +94,3 @@ describe :hash_to_s, shared: true do
{a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Hash#to_proc" do
before :each do
@key = Object.new
@ -86,4 +85,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -41,9 +41,7 @@ describe "IO.binread" do
lambda { IO.binread @fname, -1 }.should raise_error(ArgumentError)
end
ruby_version_is "2.3" do # MRI leaks the fd on older versions
it "raises an Errno::EINVAL when not passed a valid offset" do
lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL)
end
end
end

View file

@ -11,17 +11,7 @@ describe "IO#close_on_exec=" do
rm_r @name
end
guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec=).should be_false
end
it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError)
end
end
guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
guard -> { platform_is_not :windows } do
it "sets the close-on-exec flag if true" do
@io.close_on_exec = true
@io.close_on_exec?.should == true
@ -72,17 +62,7 @@ describe "IO#close_on_exec?" do
rm_r @name
end
guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
it "returns false from #respond_to?" do
@io.respond_to?(:close_on_exec?).should be_false
end
it "raises a NotImplementedError when called" do
lambda { @io.close_on_exec? }.should raise_error(NotImplementedError)
end
end
guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
guard -> { platform_is_not :windows } do
it "returns true by default" do
@io.close_on_exec?.should == true
end

View file

@ -19,21 +19,11 @@ describe "IO#close_read" do
lambda { @io.read }.should raise_error(IOError)
end
ruby_version_is ''...'2.3' do
it "raises an IOError on subsequent invocations" do
@io.close_read
lambda { @io.close_read }.should raise_error(IOError)
end
end
ruby_version_is '2.3' do
it "does nothing on subsequent invocations" do
@io.close_read
@io.close_read.should be_nil
end
end
it "allows subsequent invocation of close" do
@io.close_read
@ -62,19 +52,9 @@ describe "IO#close_read" do
io.closed?.should == true
end
ruby_version_is ''...'2.3' do
it "raises IOError on closed stream" do
@io.close
lambda { @io.close_read }.should raise_error(IOError)
end
end
ruby_version_is '2.3' do
it "does nothing on closed stream" do
@io.close
@io.close_read.should be_nil
end
end
end

View file

@ -38,20 +38,11 @@ describe "IO#close" do
lambda { @io.write "data" }.should_not raise_error(IOError)
end
ruby_version_is ''...'2.3' do
it "raises an IOError if closed" do
@io.close
lambda { @io.close }.should raise_error(IOError)
end
end
ruby_version_is "2.3" do
it "does nothing if already closed" do
@io.close
@io.close.should be_nil
end
end
ruby_version_is '2.5' do
it 'raises an IOError with a clear message' do

View file

@ -18,21 +18,11 @@ describe "IO#close_write" do
lambda { @io.write "attempt to write" }.should raise_error(IOError)
end
ruby_version_is ''...'2.3' do
it "raises an IOError on subsequent invocations" do
@io.close_write
lambda { @io.close_write }.should raise_error(IOError)
end
end
ruby_version_is '2.3' do
it "does nothing on subsequent invocations" do
@io.close_write
@io.close_write.should be_nil
end
end
it "allows subsequent invocation of close" do
@io.close_write
@ -66,19 +56,9 @@ describe "IO#close_write" do
@io.read.should == "12345\n"
end
ruby_version_is ''...'2.3' do
it "raises IOError on closed stream" do
@io.close
lambda { @io.close_write }.should raise_error(IOError)
end
end
ruby_version_is '2.3' do
it "does nothing on closed stream" do
@io.close
@io.close_write.should be_nil
end
end
end

View file

@ -37,9 +37,7 @@ describe "IO#each_codepoint" do
@io.close if @io
end
ruby_version_is "2.3" do # earlier versions stay blocked
it "raises an exception at incomplete character before EOF when conversion takes place" do
lambda { @io.each_codepoint {} }.should raise_error(ArgumentError)
end
end
end

View file

@ -22,7 +22,6 @@ describe "IO#read_nonblock" do
}
end
ruby_version_is "2.3" do
context "when exception option is set to false" do
context "when there is no data" do
it "returns :wait_readable" do
@ -41,7 +40,6 @@ describe "IO#read_nonblock" do
end
end
end
end
platform_is_not :windows do
it 'sets the IO in nonblock mode' do

View file

@ -66,14 +66,12 @@ describe 'IO#write_nonblock' do
}
end
ruby_version_is "2.3" do
context "when exception option is set to false" do
it "returns :wait_writable when the operation would block" do
loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable }
1.should == 1
end
end
end
platform_is_not :windows do
it 'sets the IO in nonblock mode' do

View file

@ -86,7 +86,6 @@ describe "Kernel#define_singleton_method" do
}.should raise_error(ArgumentError)
end
ruby_version_is "2.3" do
it "does not use the caller block when no block is given" do
o = Object.new
def o.define(name)
@ -98,4 +97,3 @@ describe "Kernel#define_singleton_method" do
}.should raise_error(ArgumentError)
end
end
end

View file

@ -58,7 +58,6 @@ describe "Kernel.loop" do
lambda{ loop do raise StandardError end }.should raise_error( StandardError )
end
ruby_version_is "2.3" do
it "returns StopIteration#result, the result value of a finished iterator" do
e = Enumerator.new { |y|
y << 1
@ -67,7 +66,6 @@ describe "Kernel.loop" do
}
loop { e.next }.should == :stopped
end
end
describe "when no block is given" do
describe "returned Enumerator" do

View file

@ -40,6 +40,48 @@ describe "Kernel#require_relative with a relative path" do
ScratchPad.recorded.should == [:loaded]
end
describe "in an #instance_eval with a" do
it "synthetic file base name loads a file base name relative to the working directory" do
Dir.chdir @abs_dir do
Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "foo.rb").should be_true
end
ScratchPad.recorded.should == [:loaded]
end
it "synthetic file path loads a relative path relative to the working directory plus the directory of the synthetic path" do
Dir.chdir @abs_dir do
Object.new.instance_eval("require_relative(File.join('..', #{File.basename(@path).inspect}))", "bar/foo.rb").should be_true
end
ScratchPad.recorded.should == [:loaded]
end
platform_is_not :windows do
it "synthetic relative file path with a Windows path separator specified loads a relative path relative to the working directory" do
Dir.chdir @abs_dir do
Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "bar\\foo.rb").should be_true
end
ScratchPad.recorded.should == [:loaded]
end
end
it "absolute file path loads a path relative to the absolute path" do
Object.new.instance_eval("require_relative(#{@path.inspect})", __FILE__).should be_true
ScratchPad.recorded.should == [:loaded]
end
it "absolute file path loads a path relative to the root directory" do
root = @abs_path
until File.dirname(root) == root
root = File.dirname(root)
end
root_relative = @abs_path[root.size..-1]
Object.new.instance_eval("require_relative(#{root_relative.inspect})", "/").should be_true
ScratchPad.recorded.should == [:loaded]
end
end
it "loads a file defining many methods" do
require_relative("#{@dir}/methods_fixture.rb").should be_true
ScratchPad.recorded.should == [:loaded]

View file

@ -454,21 +454,7 @@ describe :kernel_require, shared: true do
ScratchPad.recorded.should == []
end
ruby_version_is "2.2"..."2.3" do
it "complex, enumerator, rational and unicode_normalize are already required" do
provided = %w[complex enumerator rational unicode_normalize]
features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
provided.each { |feature|
features.should =~ /\b#{feature}\.(rb|so)$/
}
code = provided.map { |f| "puts require #{f.inspect}\n" }.join
required = ruby_exe(code, options: '--disable-gems')
required.should == "false\n" * provided.size
end
end
ruby_version_is "2.3"..."2.5" do
ruby_version_is ""..."2.5" do
it "complex, enumerator, rational, thread and unicode_normalize are already required" do
provided = %w[complex enumerator rational thread unicode_normalize]
features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')

View file

@ -1,6 +1,4 @@
require_relative '../../spec_helper'
ruby_version_is "2.0.0" do
require_relative 'fixtures/classes'
describe "main.using" do
@ -132,4 +130,3 @@ ruby_version_is "2.0.0" do
x.call_bar(cls2.new).should == 'bar'
end
end
end

View file

@ -400,7 +400,7 @@ describe "Module#autoload" do
ModuleSpecs::Autoload.send(:remove_const, :Concur)
end
ruby_bug "#10892", ""..."2.3" do
# https://bugs.ruby-lang.org/issues/10892
it "blocks others threads while doing an autoload" do
file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb")
autoload_path = file_path.sub(/\.rb\Z/, '')
@ -447,7 +447,6 @@ describe "Module#autoload" do
Object.send(:remove_const, mod_name)
end
end
end
it "raises a NameError in each thread if the constant is not set" do
file = fixture(__FILE__, "autoload_never_set.rb")

View file

@ -222,7 +222,6 @@ describe "Module#define_method" do
}.should raise_error(ArgumentError)
end
ruby_version_is "2.3" do
it "does not use the caller block when no block is given" do
o = Object.new
def o.define(name)
@ -235,7 +234,6 @@ describe "Module#define_method" do
o.define(:foo) { raise "not used" }
}.should raise_error(ArgumentError)
end
end
it "does not change the arity check style of the original proc" do
class DefineMethodSpecClass

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe "Module#deprecate_constant" do
before :each do
@module = Module.new
@ -49,4 +48,3 @@ ruby_version_is "2.3" do
lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError)
end
end
end

View file

@ -110,13 +110,11 @@ describe "Module#prepend" do
c.instance_method(:alias).owner.should == c
end
ruby_version_is "2.3" do
it "reports the class for the owner of a method aliased from the prepended module" do
m = Module.new { def meth; :m end }
c = Class.new { prepend(m); alias_method :alias, :meth }
c.instance_method(:alias).owner.should == c
end
end
it "sees an instance of a prepended class as kind of the prepended module" do
m = Module.new

View file

@ -52,8 +52,7 @@ describe "Module#private" do
end.should raise_error(NameError)
end
ruby_version_is "2.3" do
ruby_bug "#14604", "2.3"..."2.5.1" do
ruby_bug "#14604", ""..."2.5.1" do
it "only makes the method private in the class it is called on" do
base = Class.new do
def wrapped
@ -94,4 +93,3 @@ describe "Module#private" do
end
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Numeric#negative?" do
describe "on positive numbers" do
it "returns false" do
@ -40,4 +39,3 @@ ruby_version_is "2.3" do
@obj.negative?.should == false
end
end
end

View file

@ -1,7 +1,6 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
ruby_version_is "2.3" do
describe "Numeric#positive?" do
describe "on positive numbers" do
it "returns true" do
@ -40,4 +39,3 @@ ruby_version_is "2.3" do
@obj.positive?.should == false
end
end
end

View file

@ -184,20 +184,11 @@ describe "ObjectSpace.each_object" do
hidden.should == nil
end
ruby_version_is ""..."2.3" do
it "does not walk singleton classes" do
@sclass.should be_kind_of(@meta)
ObjectSpace.each_object(@meta).to_a.should_not include(@sclass)
end
end
ruby_version_is "2.3" do
it "walks singleton classes" do
@sclass.should be_kind_of(@meta)
ObjectSpace.each_object(@meta).to_a.should include(@sclass)
end
end
end
it "walks a class and its normal descendants when passed the class's singleton class" do
a = Class.new
@ -211,10 +202,8 @@ describe "ObjectSpace.each_object" do
expected = [ a, b, c, d ]
# singleton classes should be walked only on >= 2.3
ruby_version_is "2.3" do
expected << c_sclass
c_sclass.should be_kind_of(a.singleton_class)
end
b.extend Enumerable # included modules should not be walked

View file

@ -1,7 +1,6 @@
require_relative '../../../spec_helper'
describe "Process::Status#exitstatus" do
before :each do
ruby_exe("exit(42)")
end
@ -10,4 +9,17 @@ describe "Process::Status#exitstatus" do
$?.exitstatus.should == 42
end
describe "for a child that raised SignalException" do
before :each do
ruby_exe("raise SignalException, 'SIGTERM'")
end
platform_is_not :windows do
# The exitstatus is not set in these cases. See the termsig_spec
# for info on where the signal number (SIGTERM) is available.
it "returns nil" do
$?.exitstatus.should == nil
end
end
end
end

View file

@ -13,6 +13,18 @@ describe "Process::Status#termsig" do
end
end
describe "for a child that raised SignalException" do
before :each do
ruby_exe("raise SignalException, 'SIGTERM'")
end
platform_is_not :windows do
it "returns the signal" do
$?.termsig.should == Signal.list["TERM"]
end
end
end
describe "for a child that was sent a signal" do
before :each do

View file

@ -2,7 +2,7 @@
require_relative '../../spec_helper'
require_relative 'shared/urandom'
ruby_version_is "2.3"..."2.5" do
ruby_version_is ""..."2.5" do
describe "Random.raw_seed" do
it_behaves_like :random_urandom, :raw_seed
end

View file

@ -5,17 +5,9 @@ describe "Signal.signame" do
Signal.signame(0).should == "EXIT"
end
ruby_version_is "2.0"..."2.3" do
it "raises an ArgumentError if the argument is an invalid signal number" do
lambda { Signal.signame(-1) }.should raise_error(ArgumentError)
end
end
ruby_version_is "2.3" do
it "returns nil if the argument is an invalid signal number" do
Signal.signame(-1).should == nil
end
end
it "raises a TypeError when the passed argument can't be coerced to Integer" do
lambda { Signal.signame("hello") }.should raise_error(TypeError)

View file

@ -36,11 +36,9 @@ describe "String#crypt" do
lambda { "hello".crypt("a\x00") }.should raise_error(ArgumentError)
end
ruby_version_is "2.3" do
it "raises an ArgumentError when the string contains NUL character" do
lambda { "poison\0null".crypt("aa") }.should raise_error(ArgumentError)
end
end
it "calls #to_str to converts the salt arg to a String" do
obj = mock('aa')

View file

@ -7,13 +7,11 @@ describe "String.new" do
str.should be_an_instance_of(String)
end
ruby_version_is "2.3" do
it "accepts an encoding argument" do
xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding 'utf-8'
str = String.new(xA4xA2, encoding: 'euc-jp')
str.encoding.should == Encoding::EUC_JP
end
end
ruby_version_is "2.4" do
it "accepts a capacity argument" do

View file

@ -51,9 +51,8 @@ describe :string_each_line, shared: true do
end
end
quarantine! do # Currently fails on Travis
ruby_version_is '2.5' do
it "yields paragraphs (broken by 2 or more successive newlines) when passed ''" do
it "yields paragraphs (broken by 2 or more successive newlines) when passed '' and replaces multiple newlines with only two ones" do
a = []
"hello\nworld\n\n\nand\nuniverse\n\n\n\n\n".send(@method, '') { |s| a << s }
a.should == ["hello\nworld\n\n", "and\nuniverse\n\n"]
@ -63,7 +62,6 @@ quarantine! do # Currently fails on Travis
a.should == ["hello\nworld\n\n", "and\nuniverse\n\n", "dog"]
end
end
end
describe "uses $/" do
before :each do
@ -136,7 +134,7 @@ end
ruby_version_is '2.4' do
context "when `chomp` keyword argument is passed" do
it "removes new line characters" do
it "removes new line characters when separator is not specified" do
a = []
"hello \nworld\n".send(@method, chomp: true) { |s| a << s }
a.should == ["hello ", "world"]
@ -145,6 +143,23 @@ end
"hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
a.should == ["hello ", "world"]
end
it "removes only specified separator" do
a = []
"hello world".send(@method, ' ', chomp: true) { |s| a << s }
a.should == ["hello", "world"]
end
# https://bugs.ruby-lang.org/issues/14257
it "ignores new line characters when separator is specified" do
a = []
"hello\n world\n".send(@method, ' ', chomp: true) { |s| a << s }
a.should == ["hello\n", "world\n"]
a = []
"hello\r\n world\r\n".send(@method, ' ', chomp: true) { |s| a << s }
a.should == ["hello\r\n", "world\r\n"]
end
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe 'String#-@' do
it 'returns self if the String is frozen' do
input = 'foo'.freeze
@ -43,4 +42,3 @@ ruby_version_is "2.3" do
end
end
end
end

View file

@ -3,7 +3,6 @@ require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/integer'
ruby_version_is '2.3' do
platform_is pointer_size: 64 do
little_endian do
describe "String#unpack with format 'J'" do
@ -271,4 +270,3 @@ ruby_version_is '2.3' do
end
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe 'String#+@' do
it 'returns an unfrozen copy of a frozen String' do
input = 'foo'.freeze
@ -21,4 +20,3 @@ ruby_version_is "2.3" do
ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe "Struct#dig" do
before(:each) do
@klass = Struct.new(:a)
@ -41,4 +40,3 @@ ruby_version_is "2.3" do
instance.dig(:a, :bar, :baz).should == { dug: [:bar, :baz] }
end
end
end

View file

@ -1,6 +1,5 @@
require_relative '../../spec_helper'
ruby_version_is '2.3' do
describe "Thread#name" do
before :each do
@thread = Thread.new {}
@ -53,4 +52,3 @@ ruby_version_is '2.3' do
@thread.name.should == "a thread name"
end
end
end

View file

@ -34,7 +34,7 @@ describe "Time.at" do
describe "passed BigDecimal" do
it "doesn't round input value" do
require 'bigdecimal'
Time.at(BigDecimal.new('1.1')).to_f.should == 1.1
Time.at(BigDecimal('1.1')).to_f.should == 1.1
end
end
end

View file

@ -55,7 +55,7 @@ describe 'TracePoint#disable' do
end
end
ruby_bug "#14057", "2.0"..."2.5" do
ruby_bug "#14057", ""..."2.5" do
it 'can accept param within a block but it should not yield arguments' do
event_name = nil
trace = TracePoint.new(:line) {}

View file

@ -62,7 +62,7 @@ describe 'TracePoint#enable' do
end.enable { event_name.should equal(:line) }
end
ruby_bug "#14057", "2.0"..."2.5" do
ruby_bug "#14057", ""..."2.5" do
it 'can accept arguments within a block but it should not yield arguments' do
event_name = nil
trace = TracePoint.new(:line) { |tp| event_name = tp.event }

View file

@ -56,7 +56,7 @@ describe 'TracePoint.new' do
-> { TracePoint.new(o) {}}.should raise_error(TypeError)
end
ruby_bug "#140740", "2.0"..."2.5" do
ruby_bug "#140740", ""..."2.5" do
it 'expects to be called with a block' do
-> { TracePoint.new(:line) }.should raise_error(ArgumentError)
end

View file

@ -62,7 +62,6 @@ describe "A block yielded a single" do
result.should == [{"a" => 1}, b: 2]
end
ruby_version_is "2.2.1" do # SEGV on MRI 2.2.0
it "calls #to_hash on the argument but does not use the result when no keywords are present" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
@ -70,7 +69,6 @@ describe "A block yielded a single" do
result = m([obj]) { |a=nil, **b| [a, b] }
result.should == [{"a" => 1, "b" => 2}, {}]
end
end
it "assigns non-symbol keys to non-keyword arguments" do
result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }

View file

@ -13,13 +13,11 @@ describe "The class keyword" do
ClassSpecsKeywordWithSemicolon.should be_an_instance_of(Class)
end
ruby_version_is "2.3" do
it "does not raise a SyntaxError when opening a class without a semicolon" do
eval "class ClassSpecsKeywordWithoutSemicolon end"
ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
end
end
end
describe "A class definition" do
it "creates a new class" do

View file

@ -404,7 +404,6 @@ describe "Constant resolution within a singleton class (class << obj)" do
ConstantSpecs::CS_SINGLETON1.foo.should == 1
end
ruby_version_is "2.3" do
it "uses its own namespace for each object" do
a = ConstantSpecs::CS_SINGLETON2[0].foo
b = ConstantSpecs::CS_SINGLETON2[1].foo
@ -423,7 +422,6 @@ describe "Constant resolution within a singleton class (class << obj)" do
[a.foo, b.foo].should == [1, 2]
end
end
end
describe "top-level constant lookup" do
context "on a class" do

View file

@ -66,6 +66,18 @@ describe "An ensure block inside a begin block" do
:ensure
end.should == :begin
end
it "sets exception cause if raises exception in block and in ensure" do
-> {
begin
raise "from block"
ensure
raise "from ensure"
end
}.should raise_error(RuntimeError, "from ensure") do |e|
e.cause.message.should == "from block"
end
end
end
describe "The value of an ensure expression," do
@ -117,6 +129,34 @@ describe "An ensure block inside a method" do
it "has an impact on the method's explicit return value" do
@obj.explicit_return_in_method_with_ensure.should == :ensure
end
it "has an impact on the method's explicit return value from rescue if returns explicitly" do
@obj.explicit_return_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
end
it "has no impact on the method's explicit return value from rescue if returns implicitly" do
@obj.explicit_return_in_rescue_and_implicit_return_in_ensure.should == "returned in rescue"
end
it "suppresses exception raised in method if returns value explicitly" do
@obj.raise_and_explicit_return_in_ensure.should == "returned in ensure"
end
it "suppresses exception raised in rescue if returns value explicitly" do
@obj.raise_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
end
it "overrides exception raised in rescue if raises exception itself" do
-> {
@obj.raise_in_rescue_and_raise_in_ensure
}.should raise_error(RuntimeError, "raised in ensure")
end
it "suppresses exception raised in method if raises exception itself" do
-> {
@obj.raise_in_method_and_raise_in_ensure
}.should raise_error(RuntimeError, "raised in ensure")
end
end
describe "An ensure block inside a class" do

View file

@ -40,6 +40,50 @@ module EnsureSpec
ensure
return :ensure
end
def explicit_return_in_rescue_and_explicit_return_in_ensure
raise
rescue
return 2
ensure
return "returned in ensure"
end
def explicit_return_in_rescue_and_implicit_return_in_ensure
raise
rescue
return "returned in rescue"
ensure
3
end
def raise_and_explicit_return_in_ensure
raise
ensure
return "returned in ensure"
end
def raise_in_rescue_and_explicit_return_in_ensure
raise
rescue
raise
ensure
return "returned in ensure"
end
def raise_in_rescue_and_raise_in_ensure
raise
rescue
raise "raised in rescue"
ensure
raise "raised in ensure"
end
def raise_in_method_and_raise_in_ensure
raise
ensure
raise "raised in ensure"
end
end
end

View file

@ -455,6 +455,38 @@ module Super
end
end
module ZSuperWithRestReassigned
class A
def a(*args)
args
end
end
class B < A
def a(*args)
args = ["foo"]
super
end
end
end
module ZSuperWithRestReassignedWithScalar
class A
def a(*args)
args
end
end
class B < A
def a(*args)
args = "foo"
super
end
end
end
module ZSuperWithUnderscores
class A
def m(*args)

View file

@ -53,7 +53,6 @@ HERE
s.should == ' foo bar#{@ip}' + "\n"
end
ruby_version_is "2.3" do
it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
require_relative 'fixtures/squiggly_heredoc'
SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n"
@ -84,4 +83,3 @@ HERE
SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
end
end
end

View file

@ -181,6 +181,52 @@ describe 'Optional variable assignments' do
@a.b.should == 20
end
end
describe 'using a #[]' do
before do
@a = {}
end
it 'leaves new variable unassigned' do
@a[:k] &&= 10
@a.key?(:k).should == false
end
it 'leaves false' do
@a[:k] = false
@a[:k] &&= 10
@a[:k].should == false
end
it 'leaves nil' do
@a[:k] = nil
@a[:k] &&= 10
@a[:k].should == nil
end
it 'does not evaluate the right side when not needed' do
@a[:k] = nil
@a[:k] &&= raise('should not be executed')
@a[:k].should == nil
end
it 'does re-assign a variable with a truthy value' do
@a[:k] = 10
@a[:k] &&= 20
@a[:k].should == 20
end
it 'does re-assign a variable with a truthy value when using an inline rescue' do
@a[:k] = 10
@a[:k] &&= 20 rescue 30
@a[:k].should == 20
end
end
end
describe 'using compunded constants' do

View file

@ -0,0 +1,4 @@
p TOPLEVEL_BINDING.local_variables.sort
TOPLEVEL_BINDING.local_variable_set(:dynamic_set_main, 2)
p TOPLEVEL_BINDING.local_variables.sort
main_script = 3

View file

@ -0,0 +1,2 @@
TOPLEVEL_BINDING.local_variable_set(:dynamic_set_required, 1)
p TOPLEVEL_BINDING.local_variables

View file

@ -0,0 +1,4 @@
a = TOPLEVEL_BINDING.object_id
require_relative 'toplevel_binding_id_required'
c = eval('TOPLEVEL_BINDING.object_id')
p [a, $b, c].uniq.size

View file

@ -0,0 +1 @@
$b = TOPLEVEL_BINDING.object_id

View file

@ -0,0 +1,2 @@
required = true
p [:required_before, TOPLEVEL_BINDING.local_variables]

View file

@ -0,0 +1,9 @@
p TOPLEVEL_BINDING.local_variable_get(:a)
p TOPLEVEL_BINDING.local_variable_get(:b)
a = 1
p TOPLEVEL_BINDING.local_variable_get(:a)
p TOPLEVEL_BINDING.local_variable_get(:b)
b = 2
a = 3
p TOPLEVEL_BINDING.local_variable_get(:a)
p TOPLEVEL_BINDING.local_variable_get(:b)

View file

@ -0,0 +1,4 @@
main_script = 1
require_relative 'toplevel_binding_variables_required'
eval('eval_var = 3')
p TOPLEVEL_BINDING.local_variables

View file

@ -0,0 +1,2 @@
required = 2
p [:required_after, TOPLEVEL_BINDING.local_variables]

View file

@ -0,0 +1,34 @@
require_relative '../../spec_helper'
describe "The TOPLEVEL_BINDING constant" do
it "only includes local variables defined in the main script, not in required files or eval" do
binding_toplevel_variables = ruby_exe(fixture(__FILE__, "toplevel_binding_variables.rb"))
binding_toplevel_variables.should == "[:required_after, [:main_script]]\n[:main_script]\n"
end
it "has no local variables in files required before the main script" do
required = fixture(__FILE__, 'toplevel_binding_required_before.rb')
out = ruby_exe("a=1; p TOPLEVEL_BINDING.local_variables.sort; b=2", options: "-r#{required}")
out.should == "[:required_before, []]\n[:a, :b]\n"
end
it "merges local variables of the main script with dynamically-defined Binding variables" do
required = fixture(__FILE__, 'toplevel_binding_dynamic_required.rb')
out = ruby_exe(fixture(__FILE__, 'toplevel_binding_dynamic.rb'), options: "-r#{required}")
out.should == <<EOS
[:dynamic_set_required]
[:dynamic_set_required, :main_script]
[:dynamic_set_main, :dynamic_set_required, :main_script]
EOS
end
it "gets updated variables values as they are defined and set" do
out = ruby_exe(fixture(__FILE__, "toplevel_binding_values.rb"))
out.should == "nil\nnil\n1\nnil\n3\n2\n"
end
it "is always the same object for all top levels" do
binding_toplevel_id = ruby_exe(fixture(__FILE__, "toplevel_binding_id.rb"))
binding_toplevel_id.should == "1\n"
end
end

View file

@ -371,11 +371,23 @@ describe "The rescue keyword" do
end
it "evaluates rescue expressions only when needed" do
invalid_rescuer = Object.new
begin
:foo
rescue invalid_rescuer
end.should == :foo
ScratchPad << :foo
rescue -> { ScratchPad << :bar; StandardError }.call
end
ScratchPad.recorded.should == [:foo]
end
it "suppresses exception from block when raises one from rescue expression" do
-> {
begin
raise "from block"
rescue (raise "from rescue expression")
end
}.should raise_error(RuntimeError, "from rescue expression") do |e|
e.cause.message.should == "from block"
end
end
it "should splat the handling Error classes" do

View file

@ -1,6 +1,5 @@
require_relative '../spec_helper'
ruby_version_is "2.3" do
describe "Safe navigator" do
it "requires a method name to be provided" do
lambda { eval("obj&. {}") }.should raise_error(SyntaxError)
@ -98,4 +97,3 @@ ruby_version_is "2.3" do
}
end
end
end

View file

@ -233,7 +233,6 @@ describe "Ruby String literals" do
long_string_literals.should == "Beautiful is better than ugly.Explicit is better than implicit."
end
ruby_version_is "2.3" do
describe "with a magic frozen comment" do
it "produce the same object each time" do
ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true"
@ -255,7 +254,6 @@ describe "Ruby String literals" do
ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true"
end
end
end
end

Some files were not shown because too many files have changed in this diff Show more