зеркало из https://github.com/github/ruby.git
Update to ruby/spec@96d1072
This commit is contained in:
Родитель
3504f928df
Коммит
0b5c61494e
|
@ -61,4 +61,7 @@ describe "Class#dup" do
|
|||
CoreClassSpecs::RecordCopy.name.should == "CoreClassSpecs::RecordCopy"
|
||||
end
|
||||
|
||||
it "raises TypeError if called on BasicObject" do
|
||||
-> { BasicObject.dup }.should raise_error(TypeError, "can't copy the root class")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module DataSpecs
|
||||
ruby_version_is "3.2" do
|
||||
guard -> { ruby_version_is "3.2" and Data.respond_to?(:define) } do
|
||||
Measure = Data.define(:amount, :unit)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,3 +13,11 @@ describe "Dir.exist?" do
|
|||
|
||||
it_behaves_like :dir_exist, :exist?
|
||||
end
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Dir.exists?" do
|
||||
it "has been removed" do
|
||||
Dir.should_not.respond_to?(:exists?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ describe :dir_chroot_as_root, shared: true do
|
|||
before :all do
|
||||
DirSpecs.create_mock_dirs
|
||||
|
||||
@real_root = "../" * (File.dirname(__FILE__).count('/') - 1)
|
||||
@real_root = "../" * (__dir__.count('/') - 1)
|
||||
@ref_dir = File.join("/", File.basename(Dir["/*"].first))
|
||||
end
|
||||
|
||||
|
@ -18,7 +18,7 @@ describe :dir_chroot_as_root, shared: true do
|
|||
compilations_ci = ENV["GITHUB_WORKFLOW"] == "Compilations"
|
||||
|
||||
it "can be used to change the process' root directory" do
|
||||
-> { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error
|
||||
-> { Dir.send(@method, __dir__) }.should_not raise_error
|
||||
File.should.exist?("/#{File.basename(__FILE__)}")
|
||||
end unless compilations_ci
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe :dir_exist, shared: true do
|
||||
it "returns true if the given directory exists" do
|
||||
Dir.send(@method, File.dirname(__FILE__)).should be_true
|
||||
Dir.send(@method, __dir__).should be_true
|
||||
end
|
||||
|
||||
it "returns true for '.'" do
|
||||
|
@ -20,7 +20,7 @@ describe :dir_exist, shared: true do
|
|||
end
|
||||
|
||||
it "understands relative paths" do
|
||||
Dir.send(@method, File.dirname(__FILE__) + '/../').should be_true
|
||||
Dir.send(@method, __dir__ + '/../').should be_true
|
||||
end
|
||||
|
||||
it "returns false if the given directory doesn't exist" do
|
||||
|
@ -28,7 +28,7 @@ describe :dir_exist, shared: true do
|
|||
end
|
||||
|
||||
it "doesn't require the name to have a trailing slash" do
|
||||
dir = File.dirname(__FILE__)
|
||||
dir = __dir__
|
||||
dir.sub!(/\/$/,'')
|
||||
Dir.send(@method, dir).should be_true
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ describe :dir_exist, shared: true do
|
|||
|
||||
it "calls #to_path on non String arguments" do
|
||||
p = mock('path')
|
||||
p.should_receive(:to_path).and_return(File.dirname(__FILE__))
|
||||
p.should_receive(:to_path).and_return(__dir__)
|
||||
Dir.send(@method, p)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,10 +22,10 @@ describe "Enumerator::Chain#initialize" do
|
|||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
it "raises a FrozenError" do
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize)
|
||||
}.should raise_error(RuntimeError)
|
||||
}.should raise_error(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,41 +10,41 @@ describe "Enumerator#each" do
|
|||
|
||||
@enum_with_arguments = object_each_with_arguments.to_enum(:each_with_arguments, :arg0, :arg1, :arg2)
|
||||
|
||||
@enum_with_yielder = Enumerator.new {|y| y.yield :ok}
|
||||
@enum_with_yielder = Enumerator.new { |y| y.yield :ok }
|
||||
end
|
||||
|
||||
it "yields each element of self to the given block" do
|
||||
acc = []
|
||||
[1,2,3].to_enum.each {|e| acc << e }
|
||||
acc.should == [1,2,3]
|
||||
[1, 2, 3].to_enum.each { |e| acc << e }
|
||||
acc.should == [1, 2, 3]
|
||||
end
|
||||
|
||||
it "calls #each on the object given in the constructor by default" do
|
||||
each = mock('each')
|
||||
each.should_receive(:each)
|
||||
each.to_enum.each {|e| e }
|
||||
each.to_enum.each { |e| e }
|
||||
end
|
||||
|
||||
it "calls #each on the underlying object until it's exhausted" do
|
||||
each = mock('each')
|
||||
each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
|
||||
acc = []
|
||||
each.to_enum.each {|e| acc << e }
|
||||
acc.should == [1,2,3]
|
||||
each.to_enum.each { |e| acc << e }
|
||||
acc.should == [1, 2, 3]
|
||||
end
|
||||
|
||||
it "calls the method given in the constructor instead of #each" do
|
||||
each = mock('peach')
|
||||
each.should_receive(:peach)
|
||||
each.to_enum(:peach).each {|e| e }
|
||||
each.to_enum(:peach).each { |e| e }
|
||||
end
|
||||
|
||||
it "calls the method given in the constructor until it's exhausted" do
|
||||
each = mock('peach')
|
||||
each.should_receive(:peach).and_yield(1).and_yield(2).and_yield(3)
|
||||
acc = []
|
||||
each.to_enum(:peach).each {|e| acc << e }
|
||||
acc.should == [1,2,3]
|
||||
each.to_enum(:peach).each { |e| acc << e }
|
||||
acc.should == [1, 2, 3]
|
||||
end
|
||||
|
||||
it "raises a NoMethodError if the object doesn't respond to #each" do
|
||||
|
|
|
@ -17,10 +17,10 @@ describe "Enumerator::Generator#initialize" do
|
|||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
it "raises a FrozenError" do
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize) {}
|
||||
}.should raise_error(RuntimeError)
|
||||
}.should raise_error(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,10 +48,10 @@ describe "Enumerator#initialize" do
|
|||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
it "raises a FrozenError" do
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize) {}
|
||||
}.should raise_error(RuntimeError)
|
||||
}.should raise_error(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,8 +56,8 @@ describe "Enumerator::Lazy#initialize" do
|
|||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
-> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError)
|
||||
it "raises a FrozenError" do
|
||||
-> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../../enumerable/shared/enumeratorized'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#each" do
|
||||
it_behaves_like :enumeratorized_with_origin_size, :each, Enumerator::Product.new([1, 2], [:a, :b])
|
||||
|
||||
it "yields each element of Cartesian product of enumerators" do
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
acc = []
|
||||
enum.each { |e| acc << e }
|
||||
acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "calls #each_entry method on enumerators" do
|
||||
object1 = Object.new
|
||||
def object1.each_entry
|
||||
yield 1
|
||||
yield 2
|
||||
end
|
||||
|
||||
object2 = Object.new
|
||||
def object2.each_entry
|
||||
yield :a
|
||||
yield :b
|
||||
end
|
||||
|
||||
enum = Enumerator::Product.new(object1, object2)
|
||||
acc = []
|
||||
enum.each { |e| acc << e }
|
||||
acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "raises a NoMethodError if the object doesn't respond to #each_entry" do
|
||||
-> {
|
||||
Enumerator::Product.new(Object.new).each {}
|
||||
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
|
||||
end
|
||||
|
||||
it "returns enumerator if not given a block" do
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
enum.each.should.kind_of?(Enumerator)
|
||||
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "returns self if given a block" do
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
enum.each {}.should.equal?(enum)
|
||||
end
|
||||
|
||||
it "doesn't accept arguments" do
|
||||
Enumerator::Product.instance_method(:each).arity.should == 0
|
||||
end
|
||||
|
||||
it "yields each element to a block that takes multiple arguments" do
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
|
||||
acc = []
|
||||
enum.each { |x, y| acc << x }
|
||||
acc.should == [1, 1, 2, 2]
|
||||
|
||||
acc = []
|
||||
enum.each { |x, y| acc << y }
|
||||
acc.should == [:a, :b, :a, :b]
|
||||
|
||||
acc = []
|
||||
enum.each { |x, y, z| acc << z }
|
||||
acc.should == [nil, nil, nil, nil]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,54 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#initialize_copy" do
|
||||
it "replaces content of the receiver with content of the other object" do
|
||||
enum = Enumerator::Product.new([true, false])
|
||||
enum2 = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
|
||||
enum.send(:initialize_copy, enum2)
|
||||
enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
enum = Enumerator::Product.new([true, false])
|
||||
enum2 = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
|
||||
enum.send(:initialize_copy, enum2).should.equal?(enum)
|
||||
end
|
||||
|
||||
it "is a private method" do
|
||||
Enumerator::Product.should have_private_instance_method(:initialize_copy, false)
|
||||
end
|
||||
|
||||
it "does nothing if the argument is the same as the receiver" do
|
||||
enum = Enumerator::Product.new(1..2)
|
||||
enum.send(:initialize_copy, enum).should.equal?(enum)
|
||||
|
||||
enum.freeze
|
||||
enum.send(:initialize_copy, enum).should.equal?(enum)
|
||||
end
|
||||
|
||||
it "raises FrozenError if the receiver is frozen" do
|
||||
enum = Enumerator::Product.new(1..2)
|
||||
enum2 = Enumerator::Product.new(3..4)
|
||||
|
||||
-> { enum.freeze.send(:initialize_copy, enum2) }.should raise_error(FrozenError)
|
||||
end
|
||||
|
||||
it "raises TypeError if the objects are of different class" do
|
||||
enum = Enumerator::Product.new(1..2)
|
||||
enum2 = Class.new(Enumerator::Product).new(3..4)
|
||||
|
||||
-> { enum.send(:initialize_copy, enum2) }.should raise_error(TypeError, 'initialize_copy should take same class object')
|
||||
-> { enum2.send(:initialize_copy, enum) }.should raise_error(TypeError, 'initialize_copy should take same class object')
|
||||
end
|
||||
|
||||
it "raises ArgumentError if the argument is not initialized yet" do
|
||||
enum = Enumerator::Product.new(1..2)
|
||||
enum2 = Enumerator::Product.allocate
|
||||
|
||||
-> { enum.send(:initialize_copy, enum2) }.should raise_error(ArgumentError, 'uninitialized product')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#initialize" do
|
||||
before :each do
|
||||
@uninitialized = Enumerator::Product.allocate
|
||||
end
|
||||
|
||||
it "is a private method" do
|
||||
Enumerator::Product.should have_private_instance_method(:initialize, false)
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@uninitialized.send(:initialize).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
it "accepts many arguments" do
|
||||
@uninitialized.send(:initialize, 0..1, 2..3, 4..5).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
it "accepts arguments that are not Enumerable nor responding to :each_entry" do
|
||||
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a FrozenError" do
|
||||
-> {
|
||||
@uninitialized.freeze.send(:initialize, 0..1)
|
||||
}.should raise_error(FrozenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#inspect" do
|
||||
it "returns a String including enumerators" do
|
||||
enum = Enumerator::Product.new([1, 2], [:a, :b])
|
||||
enum.inspect.should == "#<Enumerator::Product: [[1, 2], [:a, :b]]>"
|
||||
end
|
||||
|
||||
it "represents a recursive element with '[...]'" do
|
||||
enum = [1, 2]
|
||||
enum_recursive = Enumerator::Product.new(enum)
|
||||
|
||||
enum << enum_recursive
|
||||
enum_recursive.inspect.should == "#<Enumerator::Product: [[1, 2, #<Enumerator::Product: ...>]]>"
|
||||
end
|
||||
|
||||
it "returns a not initialized representation if #initialized is not called yet" do
|
||||
Enumerator::Product.allocate.inspect.should == "#<Enumerator::Product: uninitialized>"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#rewind" do
|
||||
before :each do
|
||||
@enum = Enumerator::Product.new([1, 2].each.to_enum, [:a, :b].each.to_enum)
|
||||
end
|
||||
|
||||
it "resets the enumerator to its initial state" do
|
||||
@enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
@enum.rewind
|
||||
@enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@enum.rewind.should.equal? @enum
|
||||
end
|
||||
|
||||
it "has no effect on a new enumerator" do
|
||||
@enum.rewind
|
||||
@enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "has no effect if called multiple, consecutive times" do
|
||||
@enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
@enum.rewind
|
||||
@enum.rewind
|
||||
@enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
|
||||
end
|
||||
|
||||
it "calls the enclosed object's rewind method if one exists" do
|
||||
obj = mock('rewinder')
|
||||
enum = Enumerator::Product.new(obj.to_enum)
|
||||
|
||||
obj.should_receive(:rewind)
|
||||
enum.rewind
|
||||
end
|
||||
|
||||
it "does nothing if the object doesn't have a #rewind method" do
|
||||
obj = mock('rewinder')
|
||||
enum = Enumerator::Product.new(obj.to_enum)
|
||||
|
||||
enum.rewind.should == enum
|
||||
end
|
||||
|
||||
it "calls a rewind method on each enumerable in direct order" do
|
||||
ScratchPad.record []
|
||||
|
||||
object1 = Object.new
|
||||
def object1.rewind; ScratchPad << :object1; end
|
||||
|
||||
object2 = Object.new
|
||||
def object2.rewind; ScratchPad << :object2; end
|
||||
|
||||
object3 = Object.new
|
||||
def object3.rewind; ScratchPad << :object3; end
|
||||
|
||||
enum = Enumerator::Product.new(object1, object2, object3)
|
||||
enum.rewind
|
||||
|
||||
ScratchPad.recorded.should == [:object1, :object2, :object3]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Enumerator::Product#size" do
|
||||
it "returns the total size of the enumerator product calculated by multiplying the sizes of enumerables in the product" do
|
||||
product = Enumerator::Product.new(1..2, 1..3, 1..4)
|
||||
product.size.should == 24 # 2 * 3 * 4
|
||||
end
|
||||
|
||||
it "returns nil if any enumerable reports its size as nil" do
|
||||
enum = Object.new
|
||||
def enum.size; nil; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == nil
|
||||
end
|
||||
|
||||
it "returns Float::INFINITY if any enumerable reports its size as Float::INFINITY" do
|
||||
enum = Object.new
|
||||
def enum.size; Float::INFINITY; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == Float::INFINITY
|
||||
end
|
||||
|
||||
it "returns -Float::INFINITY if any enumerable reports its size as -Float::INFINITY" do
|
||||
enum = Object.new
|
||||
def enum.size; -Float::INFINITY; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == -Float::INFINITY
|
||||
end
|
||||
|
||||
it "returns nil if any enumerable reports its size as Float::NAN" do
|
||||
enum = Object.new
|
||||
def enum.size; Float::NAN; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == nil
|
||||
end
|
||||
|
||||
it "returns nil if any enumerable doesn't respond to #size" do
|
||||
enum = Object.new
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == nil
|
||||
end
|
||||
|
||||
it "returns nil if any enumerable reports a not-convertible to Integer" do
|
||||
enum = Object.new
|
||||
def enum.size; :symbol; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == nil
|
||||
end
|
||||
|
||||
it "returns nil if any enumerable reports a non-Integer but convertible to Integer size" do
|
||||
enum = Object.new
|
||||
def enum.size; 1.0; end
|
||||
|
||||
product = Enumerator::Product.new(1..2, enum)
|
||||
product.size.should == nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -44,6 +44,11 @@ ruby_version_is "3.2" do
|
|||
elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
|
||||
end
|
||||
|
||||
it "returns nil when a block passed" do
|
||||
Enumerator.product(1..2) {}.should == nil
|
||||
end
|
||||
|
||||
# https://bugs.ruby-lang.org/issues/19829
|
||||
it "reject keyword arguments" do
|
||||
-> {
|
||||
Enumerator.product(1..3, foo: 1, bar: 2)
|
||||
|
|
|
@ -14,7 +14,7 @@ describe "Enumerator#rewind" do
|
|||
end
|
||||
|
||||
it "returns self" do
|
||||
@enum.rewind.should == @enum
|
||||
@enum.rewind.should.equal? @enum
|
||||
end
|
||||
|
||||
it "has no effect on a new enumerator" do
|
||||
|
@ -49,7 +49,7 @@ describe "Enumerator#rewind" do
|
|||
obj = mock('rewinder')
|
||||
enum = obj.to_enum
|
||||
obj.should_receive(:each).at_most(1)
|
||||
-> { enum.rewind.should == enum }.should_not raise_error
|
||||
enum.rewind.should == enum
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -41,6 +41,14 @@ describe "ENV.delete" do
|
|||
ENV["foo"].should == nil
|
||||
end
|
||||
|
||||
it "removes the variable coerced with #to_str" do
|
||||
ENV["foo"] = "bar"
|
||||
k = mock('key')
|
||||
k.should_receive(:to_str).and_return("foo")
|
||||
ENV.delete(k)
|
||||
ENV["foo"].should == nil
|
||||
end
|
||||
|
||||
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
||||
-> { ENV.delete(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
|
||||
end
|
||||
|
|
|
@ -1,11 +1,39 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/include'
|
||||
require_relative 'shared/key'
|
||||
|
||||
describe "ENV.key?" do
|
||||
it_behaves_like :env_include, :key?
|
||||
end
|
||||
|
||||
describe "ENV.key" do
|
||||
it_behaves_like :env_key, :key
|
||||
before :each do
|
||||
@saved_foo = ENV["foo"]
|
||||
end
|
||||
|
||||
after :each do
|
||||
ENV["foo"] = @saved_foo
|
||||
end
|
||||
|
||||
it "returns the index associated with the passed value" do
|
||||
ENV["foo"] = "bar"
|
||||
ENV.key("bar").should == "foo"
|
||||
end
|
||||
|
||||
it "returns nil if the passed value is not found" do
|
||||
ENV.delete("foo")
|
||||
ENV.key("foo").should be_nil
|
||||
end
|
||||
|
||||
it "coerces the key element with #to_str" do
|
||||
ENV["foo"] = "bar"
|
||||
k = mock('key')
|
||||
k.should_receive(:to_str).and_return("bar")
|
||||
ENV.key(k).should == "foo"
|
||||
end
|
||||
|
||||
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
||||
-> {
|
||||
ENV.key(Object.new)
|
||||
}.should raise_error(TypeError, "no implicit conversion of Object into String")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,13 @@ describe :env_include, shared: true do
|
|||
ENV.send(@method, "foo").should == false
|
||||
end
|
||||
|
||||
it "coerces the key with #to_str" do
|
||||
ENV["foo"] = "bar"
|
||||
k = mock('key')
|
||||
k.should_receive(:to_str).and_return("foo")
|
||||
ENV.send(@method, k).should == true
|
||||
end
|
||||
|
||||
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
||||
-> { ENV.send(@method, Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
|
||||
end
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
describe :env_key, shared: true do
|
||||
before :each do
|
||||
@saved_foo = ENV["foo"]
|
||||
end
|
||||
|
||||
after :each do
|
||||
ENV["foo"] = @saved_foo
|
||||
end
|
||||
|
||||
it "returns the index associated with the passed value" do
|
||||
ENV["foo"] = "bar"
|
||||
suppress_warning {
|
||||
ENV.send(@method, "bar").should == "foo"
|
||||
}
|
||||
end
|
||||
|
||||
it "returns nil if the passed value is not found" do
|
||||
ENV.delete("foo")
|
||||
suppress_warning {
|
||||
ENV.send(@method, "foo").should be_nil
|
||||
}
|
||||
end
|
||||
|
||||
it "raises TypeError if the argument is not a String and does not respond to #to_str" do
|
||||
-> {
|
||||
suppress_warning {
|
||||
ENV.send(@method, Object.new)
|
||||
}
|
||||
}.should raise_error(TypeError, "no implicit conversion of Object into String")
|
||||
end
|
||||
end
|
|
@ -16,6 +16,13 @@ describe :env_value, shared: true do
|
|||
ENV.send(@method, "foo").should == false
|
||||
end
|
||||
|
||||
it "coerces the value element with #to_str" do
|
||||
ENV["foo"] = "bar"
|
||||
v = mock('value')
|
||||
v.should_receive(:to_str).and_return("bar")
|
||||
ENV.send(@method, v).should == true
|
||||
end
|
||||
|
||||
it "returns nil if the argument is not a String and does not respond to #to_str" do
|
||||
ENV.send(@method, Object.new).should == nil
|
||||
end
|
||||
|
|
|
@ -21,6 +21,16 @@ describe "ENV.slice" do
|
|||
ENV.slice("foo", "boo", "bar").should == {"foo" => "0", "bar" => "1"}
|
||||
end
|
||||
|
||||
it "returns the values for the keys coerced with #to_str, but keeps the original objects as result keys" do
|
||||
foo = mock('key 1')
|
||||
foo.should_receive(:to_str).and_return("foo")
|
||||
boo = mock('key 2')
|
||||
boo.should_receive(:to_str).and_return("boo")
|
||||
bar = mock('key 3')
|
||||
bar.should_receive(:to_str).and_return("bar")
|
||||
ENV.slice(foo, boo, bar).should == {foo => "0", bar => "1"}
|
||||
end
|
||||
|
||||
it "raises TypeError if any argument is not a String and does not respond to #to_str" do
|
||||
-> { ENV.slice(Object.new) }.should raise_error(TypeError, "no implicit conversion of Object into String")
|
||||
end
|
||||
|
|
|
@ -22,18 +22,18 @@ describe "Exception#==" do
|
|||
|
||||
it "returns true if both exceptions have the same class, the same message, and the same backtrace" do
|
||||
one = TypeError.new("message")
|
||||
one.set_backtrace [File.dirname(__FILE__)]
|
||||
one.set_backtrace [__dir__]
|
||||
two = TypeError.new("message")
|
||||
two.set_backtrace [File.dirname(__FILE__)]
|
||||
two.set_backtrace [__dir__]
|
||||
one.should == two
|
||||
end
|
||||
|
||||
it "returns false if the two exceptions inherit from Exception but have different classes" do
|
||||
one = RuntimeError.new("message")
|
||||
one.set_backtrace [File.dirname(__FILE__)]
|
||||
one.set_backtrace [__dir__]
|
||||
one.should be_kind_of(Exception)
|
||||
two = TypeError.new("message")
|
||||
two.set_backtrace [File.dirname(__FILE__)]
|
||||
two.set_backtrace [__dir__]
|
||||
two.should be_kind_of(Exception)
|
||||
one.should_not == two
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ describe "Exception#==" do
|
|||
|
||||
it "returns false if the two exceptions differ only in their backtrace" do
|
||||
one = RuntimeError.new("message")
|
||||
one.set_backtrace [File.dirname(__FILE__)]
|
||||
one.set_backtrace [__dir__]
|
||||
two = RuntimeError.new("message")
|
||||
two.set_backtrace nil
|
||||
one.should_not == two
|
||||
|
@ -60,9 +60,9 @@ describe "Exception#==" do
|
|||
|
||||
it "returns false if the two exceptions differ only in their message" do
|
||||
one = RuntimeError.new("message")
|
||||
one.set_backtrace [File.dirname(__FILE__)]
|
||||
one.set_backtrace [__dir__]
|
||||
two = RuntimeError.new("message2")
|
||||
two.set_backtrace [File.dirname(__FILE__)]
|
||||
two.set_backtrace [__dir__]
|
||||
one.should_not == two
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,10 @@ require_relative '../../spec_helper'
|
|||
describe "FalseClass#singleton_method" do
|
||||
ruby_version_is '3.3' do
|
||||
it "raises regardless of whether FalseClass defines the method" do
|
||||
proc{false.singleton_method(:foo)}.should raise_error(NameError)
|
||||
-> { false.singleton_method(:foo) }.should raise_error(NameError)
|
||||
begin
|
||||
def false.foo; end
|
||||
proc{false.singleton_method(:foo)}.should raise_error(NameError)
|
||||
def (false).foo; end
|
||||
-> { false.singleton_method(:foo) }.should raise_error(NameError)
|
||||
ensure
|
||||
FalseClass.send(:remove_method, :foo)
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
require 'fiber'
|
||||
|
||||
describe "Fiber.new(storage:)" do
|
||||
ruby_version_is "3.2" do
|
||||
ruby_version_is "3.2" do
|
||||
describe "Fiber.new(storage:)" do
|
||||
it "creates a Fiber with the given storage" do
|
||||
storage = {life: 42}
|
||||
fiber = Fiber.new(storage: storage) { Fiber.current.storage }
|
||||
|
@ -24,11 +22,26 @@ describe "Fiber.new(storage:)" do
|
|||
it "cannot create a fiber with non-hash storage" do
|
||||
-> { Fiber.new(storage: 42) {} }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber#storage=" do
|
||||
ruby_version_is "3.2" do
|
||||
it "cannot create a fiber with a frozen hash as storage" do
|
||||
-> { Fiber.new(storage: {life: 43}.freeze) {} }.should raise_error(FrozenError)
|
||||
end
|
||||
|
||||
it "cannot create a fiber with a storage hash with non-symbol keys" do
|
||||
-> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber#storage" do
|
||||
it "cannot be accessed from a different fiber" do
|
||||
f = Fiber.new(storage: {life: 42}) { nil }
|
||||
-> {
|
||||
f.storage
|
||||
}.should raise_error(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber#storage=" do
|
||||
it "can clear the storage of the fiber" do
|
||||
fiber = Fiber.new(storage: {life: 42}) do
|
||||
Fiber.current.storage = nil
|
||||
|
@ -58,10 +71,8 @@ describe "Fiber#storage=" do
|
|||
-> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber.[]" do
|
||||
ruby_version_is "3.2" do
|
||||
describe "Fiber.[]" do
|
||||
it "returns the value of the given key in the storage of the current fiber" do
|
||||
Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42
|
||||
end
|
||||
|
@ -73,25 +84,34 @@ describe "Fiber.[]" do
|
|||
it "returns nil if the current fiber has no storage" do
|
||||
Fiber.new { Fiber[:life] }.resume.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.2.3" do
|
||||
it "can use dynamically defined keys" do
|
||||
key = :"#{self.class.name}#.#{self.object_id}"
|
||||
Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
|
||||
end
|
||||
ruby_version_is "3.2.3" do
|
||||
it "can use dynamically defined keys" do
|
||||
key = :"#{self.class.name}#.#{self.object_id}"
|
||||
Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
|
||||
end
|
||||
|
||||
it "can't use invalid keys" do
|
||||
invalid_keys = [Object.new, "Foo", 12]
|
||||
invalid_keys.each do |key|
|
||||
-> { Fiber[key] }.should raise_error(TypeError)
|
||||
it "can't use invalid keys" do
|
||||
invalid_keys = [Object.new, "Foo", 12]
|
||||
invalid_keys.each do |key|
|
||||
-> { Fiber[key] }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber.[]=" do
|
||||
ruby_version_is "3.2" do
|
||||
it "can access the storage of the parent fiber" do
|
||||
f = Fiber.new(storage: {life: 42}) do
|
||||
Fiber.new { Fiber[:life] }.resume
|
||||
end
|
||||
f.resume.should == 42
|
||||
end
|
||||
|
||||
it "can't access the storage of the fiber with non-symbol keys" do
|
||||
-> { Fiber[Object.new] }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Fiber.[]=" do
|
||||
it "sets the value of the given key in the storage of the current fiber" do
|
||||
Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
|
||||
end
|
||||
|
@ -103,17 +123,31 @@ describe "Fiber.[]=" do
|
|||
it "sets the value of the given key in the storage of the current fiber" do
|
||||
Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.3" do
|
||||
it "deletes the fiber storage key when assigning nil" do
|
||||
Fiber.new(storage: {life: 42}) { Fiber[:life] = nil; Fiber.current.storage }.resume.should == {}
|
||||
it "does not overwrite the storage of the parent fiber" do
|
||||
f = Fiber.new(storage: {life: 42}) do
|
||||
Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume
|
||||
Fiber[:life]
|
||||
end
|
||||
f.resume.should == 43 # Value of the inner fiber
|
||||
f.resume.should == 42 # Value of the outer fiber
|
||||
end
|
||||
|
||||
it "can't access the storage of the fiber with non-symbol keys" do
|
||||
-> { Fiber[Object.new] = 44 }.should raise_error(TypeError)
|
||||
end
|
||||
|
||||
ruby_version_is "3.3" do
|
||||
it "deletes the fiber storage key when assigning nil" do
|
||||
Fiber.new(storage: {life: 42}) {
|
||||
Fiber[:life] = nil
|
||||
Fiber.current.storage
|
||||
}.resume.should == {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Thread.new" do
|
||||
ruby_version_is "3.2" do
|
||||
describe "Thread.new" do
|
||||
it "creates a thread with the storage of the current fiber" do
|
||||
fiber = Fiber.new(storage: {life: 42}) do
|
||||
Thread.new { Fiber.current.storage }.value
|
||||
|
|
|
@ -85,7 +85,7 @@ describe "File.absolute_path" do
|
|||
end
|
||||
|
||||
it "accepts a second argument of a directory from which to resolve the path" do
|
||||
File.absolute_path(__FILE__, File.dirname(__FILE__)).should == @abs
|
||||
File.absolute_path(__FILE__, __dir__).should == @abs
|
||||
end
|
||||
|
||||
it "calls #to_path on its argument" do
|
||||
|
|
|
@ -4,3 +4,11 @@ require_relative '../../shared/file/exist'
|
|||
describe "File.exist?" do
|
||||
it_behaves_like :file_exist, :exist?, File
|
||||
end
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "File.exists?" do
|
||||
it "has been removed" do
|
||||
File.should_not.respond_to?(:exists?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -314,7 +314,7 @@ describe "File.open" do
|
|||
end
|
||||
end
|
||||
|
||||
it "raises an IOError when read in a block opened with File::RDONLY|File::APPEND mode" do
|
||||
it "raises an IOError when write in a block opened with File::RDONLY|File::APPEND mode" do
|
||||
-> {
|
||||
File.open(@file, File::RDONLY|File::APPEND ) do |f|
|
||||
f.puts("writing")
|
||||
|
|
|
@ -54,6 +54,10 @@ platform_is_not :windows do
|
|||
File.realpath(@relative_symlink).should == @file
|
||||
end
|
||||
|
||||
it "removes the file element when going one level up" do
|
||||
File.realpath('../', @file).should == @real_dir
|
||||
end
|
||||
|
||||
it "raises an Errno::ELOOP if the symlink points to itself" do
|
||||
File.unlink @link
|
||||
File.symlink(@link, @link)
|
||||
|
|
|
@ -76,7 +76,7 @@ describe "IO#eof?" do
|
|||
end
|
||||
|
||||
it "returns true on one-byte stream after single-byte read" do
|
||||
File.open(File.dirname(__FILE__) + '/fixtures/one_byte.txt') { |one_byte|
|
||||
File.open(__dir__ + '/fixtures/one_byte.txt') { |one_byte|
|
||||
one_byte.read(1)
|
||||
one_byte.should.eof?
|
||||
}
|
||||
|
|
|
@ -40,3 +40,19 @@ describe "IO#getbyte" do
|
|||
@io.getbyte.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "IO#getbyte" do
|
||||
before :each do
|
||||
@name = tmp("io_getbyte.txt")
|
||||
@io = new_io(@name, 'w')
|
||||
end
|
||||
|
||||
after :each do
|
||||
@io.close if @io
|
||||
rm_r @name if @name
|
||||
end
|
||||
|
||||
it "raises an IOError if the stream is not readable" do
|
||||
-> { @io.getbyte }.should raise_error(IOError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'shared/new'
|
||||
|
||||
# NOTE: should be syncronized with library/stringio/initialize_spec.rb
|
||||
# NOTE: should be synchronized with library/stringio/initialize_spec.rb
|
||||
|
||||
describe "IO.new" do
|
||||
it_behaves_like :io_new, :new
|
||||
|
|
|
@ -55,8 +55,8 @@ describe "IO.select" do
|
|||
end
|
||||
end
|
||||
|
||||
it "returns supplied objects correctly even when monitoring the same object in different arrays" do
|
||||
filename = tmp("IO_select_pipe_file") + $$.to_s
|
||||
it "returns supplied objects correctly when monitoring the same object in different arrays" do
|
||||
filename = tmp("IO_select_pipe_file")
|
||||
io = File.open(filename, 'w+')
|
||||
result = IO.select [io], [io], nil, 0
|
||||
result.should == [[io], [io], []]
|
||||
|
@ -64,6 +64,17 @@ describe "IO.select" do
|
|||
rm_r filename
|
||||
end
|
||||
|
||||
it "returns the pipe read end in read set if the pipe write end is closed concurrently" do
|
||||
main = Thread.current
|
||||
t = Thread.new {
|
||||
Thread.pass until main.stop?
|
||||
@wr.close
|
||||
}
|
||||
IO.select([@rd]).should == [[@rd], [], []]
|
||||
ensure
|
||||
t.join
|
||||
end
|
||||
|
||||
it "invokes to_io on supplied objects that are not IO and returns the supplied objects" do
|
||||
# make some data available
|
||||
@wr.write("foobar")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require_relative '../fixtures/classes'
|
||||
|
||||
# NOTE: should be syncronized with library/stringio/initialize_spec.rb
|
||||
# NOTE: should be synchronized with library/stringio/initialize_spec.rb
|
||||
|
||||
# This group of specs may ONLY contain specs that do successfully create
|
||||
# an IO instance from the file descriptor returned by #new_fd helper.
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "Kernel#initialize_copy" do
|
||||
it "returns self" do
|
||||
obj = Object.new
|
||||
obj.send(:initialize_copy, obj).should.equal?(obj)
|
||||
end
|
||||
|
||||
it "does nothing if the argument is the same as the receiver" do
|
||||
obj = Object.new
|
||||
obj.send(:initialize_copy, obj).should.equal?(obj)
|
||||
obj.freeze
|
||||
|
||||
obj = Object.new.freeze
|
||||
obj.send(:initialize_copy, obj).should.equal?(obj)
|
||||
|
||||
1.send(:initialize_copy, 1).should.equal?(1)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ describe "Kernel#require_relative with a relative path" do
|
|||
before :each do
|
||||
CodeLoadingSpecs.spec_setup
|
||||
@dir = "../../fixtures/code"
|
||||
@abs_dir = File.realpath(@dir, File.dirname(__FILE__))
|
||||
@abs_dir = File.realpath(@dir, __dir__)
|
||||
@path = "#{@dir}/load_fixture.rb"
|
||||
@abs_path = File.realpath(@path, File.dirname(__FILE__))
|
||||
@abs_path = File.realpath(@path, __dir__)
|
||||
end
|
||||
|
||||
after :each do
|
||||
|
@ -92,7 +92,7 @@ describe "Kernel#require_relative with a relative path" do
|
|||
|
||||
it "raises a LoadError that includes the missing path" do
|
||||
missing_path = "#{@dir}/nonexistent.rb"
|
||||
expanded_missing_path = File.expand_path(missing_path, File.dirname(__FILE__))
|
||||
expanded_missing_path = File.expand_path(missing_path, __dir__)
|
||||
-> { require_relative(missing_path) }.should raise_error(LoadError) { |e|
|
||||
e.message.should include(expanded_missing_path)
|
||||
e.path.should == expanded_missing_path
|
||||
|
@ -277,7 +277,7 @@ end
|
|||
describe "Kernel#require_relative with an absolute path" do
|
||||
before :each do
|
||||
CodeLoadingSpecs.spec_setup
|
||||
@dir = File.expand_path "../../fixtures/code", File.dirname(__FILE__)
|
||||
@dir = File.expand_path "../../fixtures/code", __dir__
|
||||
@abs_dir = @dir
|
||||
@path = File.join @dir, "load_fixture.rb"
|
||||
@abs_path = @path
|
||||
|
|
|
@ -356,13 +356,13 @@ describe :kernel_sprintf, shared: true do
|
|||
|
||||
it "raises TypeError if converting to Integer with to_int returns non-Integer" do
|
||||
obj = BasicObject.new
|
||||
def obj.to_str
|
||||
def obj.to_int
|
||||
:foo
|
||||
end
|
||||
|
||||
-> {
|
||||
@method.call("%c", obj)
|
||||
}.should raise_error(TypeError, /can't convert BasicObject to String/)
|
||||
}.should raise_error(TypeError, /can't convert BasicObject to Integer/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ require_relative 'fixtures/classes'
|
|||
|
||||
describe "Kernel#test" do
|
||||
before :all do
|
||||
@file = File.dirname(__FILE__) + '/fixtures/classes.rb'
|
||||
@dir = File.dirname(__FILE__) + '/fixtures'
|
||||
@file = __dir__ + '/fixtures/classes.rb'
|
||||
@dir = __dir__ + '/fixtures'
|
||||
end
|
||||
|
||||
it "is a private method" do
|
||||
|
|
|
@ -271,6 +271,18 @@ describe "Marshal.dump" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "with a Rational" do
|
||||
it "dumps a Rational" do
|
||||
Marshal.dump(Rational(2, 3)).should == "\x04\bU:\rRational[\ai\ai\b"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a Complex" do
|
||||
it "dumps a Complex" do
|
||||
Marshal.dump(Complex(2, 3)).should == "\x04\bU:\fComplex[\ai\ai\b"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a String" do
|
||||
it "dumps a blank String" do
|
||||
Marshal.dump("".force_encoding("binary")).should == "\004\b\"\000"
|
||||
|
@ -769,7 +781,6 @@ describe "Marshal.dump" do
|
|||
end
|
||||
|
||||
describe "when passed an IO" do
|
||||
|
||||
it "writes the serialized data to the IO-Object" do
|
||||
(obj = mock('test')).should_receive(:write).at_least(1)
|
||||
Marshal.dump("test", obj)
|
||||
|
@ -792,8 +803,6 @@ describe "Marshal.dump" do
|
|||
obj.should_receive(:binmode).at_least(1)
|
||||
Marshal.dump("test", obj)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "when passed a StringIO" do
|
||||
|
|
|
@ -1034,13 +1034,17 @@ describe :marshal_load, shared: true do
|
|||
|
||||
describe "for a Rational" do
|
||||
it "loads" do
|
||||
Marshal.send(@method, Marshal.dump(Rational(1, 3))).should == Rational(1, 3)
|
||||
r = Marshal.send(@method, Marshal.dump(Rational(1, 3)))
|
||||
r.should == Rational(1, 3)
|
||||
r.should.frozen?
|
||||
end
|
||||
end
|
||||
|
||||
describe "for a Complex" do
|
||||
it "loads" do
|
||||
Marshal.send(@method, Marshal.dump(Complex(4, 3))).should == Complex(4, 3)
|
||||
c = Marshal.send(@method, Marshal.dump(Complex(4, 3)))
|
||||
c.should == Complex(4, 3)
|
||||
c.should.frozen?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe "Method#source_location" do
|
|||
it "sets the first value to the path of the file in which the method was defined" do
|
||||
file = @method.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/classes.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/classes.rb', __dir__)
|
||||
end
|
||||
|
||||
it "sets the last value to an Integer representing the line on which the method was defined" do
|
||||
|
|
|
@ -121,5 +121,40 @@ describe "Module#const_added" do
|
|||
|
||||
ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11]
|
||||
end
|
||||
|
||||
it "is called when the constant is already assigned a value" do
|
||||
ScratchPad.record []
|
||||
|
||||
mod = Module.new do
|
||||
def self.const_added(name)
|
||||
ScratchPad.record const_get(name)
|
||||
end
|
||||
end
|
||||
|
||||
mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
||||
TEST = 123
|
||||
RUBY
|
||||
|
||||
ScratchPad.recorded.should == 123
|
||||
end
|
||||
|
||||
it "records re-definition of existing constants" do
|
||||
ScratchPad.record []
|
||||
|
||||
mod = Module.new do
|
||||
def self.const_added(name)
|
||||
ScratchPad << const_get(name)
|
||||
end
|
||||
end
|
||||
|
||||
-> {
|
||||
mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
||||
TEST = 123
|
||||
TEST = 456
|
||||
RUBY
|
||||
}.should complain(/warning: already initialized constant .+::TEST/)
|
||||
|
||||
ScratchPad.recorded.should == [123, 456]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -499,6 +499,33 @@ describe "Module#define_method" do
|
|||
Class.new { define_method :bar, m }
|
||||
}.should raise_error(TypeError, /can't bind singleton method to a different class/)
|
||||
end
|
||||
|
||||
it "defines a new method with public visibility when a Method passed and the class/module of the context isn't equal to the receiver of #define_method" do
|
||||
c = Class.new do
|
||||
private def foo
|
||||
"public"
|
||||
end
|
||||
end
|
||||
|
||||
object = c.new
|
||||
object.singleton_class.define_method(:bar, object.method(:foo))
|
||||
|
||||
object.bar.should == "public"
|
||||
end
|
||||
|
||||
it "defines the new method according to the scope visibility when a Method passed and the class/module of the context is equal to the receiver of #define_method" do
|
||||
c = Class.new do
|
||||
def foo; end
|
||||
end
|
||||
|
||||
object = c.new
|
||||
object.singleton_class.class_eval do
|
||||
private
|
||||
define_method(:bar, c.new.method(:foo))
|
||||
end
|
||||
|
||||
-> { object.bar }.should raise_error(NoMethodError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Module#define_method" do
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
describe "Mutex#lock" do
|
||||
before :each do
|
||||
ScratchPad.clear
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
m = Mutex.new
|
||||
m.lock.should == m
|
||||
|
|
|
@ -3,10 +3,10 @@ require_relative '../../spec_helper'
|
|||
describe "NilClass#singleton_method" do
|
||||
ruby_version_is '3.3' do
|
||||
it "raises regardless of whether NilClass defines the method" do
|
||||
proc{nil.singleton_method(:foo)}.should raise_error(NameError)
|
||||
-> { nil.singleton_method(:foo) }.should raise_error(NameError)
|
||||
begin
|
||||
def nil.foo; end
|
||||
proc{nil.singleton_method(:foo)}.should raise_error(NameError)
|
||||
def (nil).foo; end
|
||||
-> { nil.singleton_method(:foo) }.should raise_error(NameError)
|
||||
ensure
|
||||
NilClass.send(:remove_method, :foo)
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe "Numeric#clone" do
|
|||
1.clone.frozen?.should == true
|
||||
end
|
||||
|
||||
it "accepts optonal keyword argument :freeze" do
|
||||
it "accepts optional keyword argument :freeze" do
|
||||
value = 1
|
||||
value.clone(freeze: true).should equal(value)
|
||||
end
|
||||
|
|
|
@ -19,19 +19,19 @@ describe "Proc#source_location" do
|
|||
it "sets the first value to the path of the file in which the proc was defined" do
|
||||
file = @proc.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/source_location.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/source_location.rb', __dir__)
|
||||
|
||||
file = @proc_new.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/source_location.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/source_location.rb', __dir__)
|
||||
|
||||
file = @lambda.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/source_location.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/source_location.rb', __dir__)
|
||||
|
||||
file = @method.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/source_location.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/source_location.rb', __dir__)
|
||||
end
|
||||
|
||||
it "sets the last value to an Integer representing the line on which the proc was defined" do
|
||||
|
|
|
@ -8,7 +8,7 @@ describe "Process.argv0" do
|
|||
it "is the path given as the main script and the same as __FILE__" do
|
||||
script = "fixtures/argv0.rb"
|
||||
|
||||
Dir.chdir(File.dirname(__FILE__)) do
|
||||
Dir.chdir(__dir__) do
|
||||
ruby_exe(script).should == "#{script}\n#{script}\nOK"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ describe "Process.exec" do
|
|||
end
|
||||
|
||||
it "raises Errno::EACCES when passed a directory" do
|
||||
-> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES)
|
||||
-> { Process.exec __dir__ }.should raise_error(Errno::EACCES)
|
||||
end
|
||||
|
||||
it "runs the specified command, replacing current process" do
|
||||
|
|
|
@ -714,7 +714,7 @@ describe "Process.spawn" do
|
|||
end
|
||||
|
||||
it "raises an Errno::EACCES or Errno::EISDIR when passed a directory" do
|
||||
-> { Process.spawn File.dirname(__FILE__) }.should raise_error(SystemCallError) { |e|
|
||||
-> { Process.spawn __dir__ }.should raise_error(SystemCallError) { |e|
|
||||
[Errno::EACCES, Errno::EISDIR].should include(e.class)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -9,7 +9,6 @@ describe "Random#bytes" do
|
|||
Random.new(33).bytes(2).should == Random.new(33).bytes(2)
|
||||
end
|
||||
|
||||
# Should double check this is official spec
|
||||
it "returns the same numeric output for a given seed across all implementations and platforms" do
|
||||
rnd = Random.new(33)
|
||||
rnd.bytes(2).should == "\x14\\"
|
||||
|
|
|
@ -7,4 +7,8 @@ describe "Range#cover?" do
|
|||
it_behaves_like :range_cover_and_include, :cover?
|
||||
it_behaves_like :range_cover, :cover?
|
||||
it_behaves_like :range_cover_subrange, :cover?
|
||||
|
||||
it "covers U+9995 in the range U+0999..U+9999" do
|
||||
("\u{999}".."\u{9999}").cover?("\u{9995}").should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,4 +7,8 @@ require_relative 'shared/cover'
|
|||
describe "Range#include?" do
|
||||
it_behaves_like :range_cover_and_include, :include?
|
||||
it_behaves_like :range_include, :include?
|
||||
|
||||
it "does not include U+9995 in the range U+0999..U+9999" do
|
||||
("\u{999}".."\u{9999}").include?("\u{9995}").should be_false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,7 +57,6 @@ describe :range_cover_and_include, shared: true do
|
|||
it "returns true if argument is less than the last value of the range and greater than the first value" do
|
||||
(20..30).send(@method, 28).should be_true
|
||||
('e'..'h').send(@method, 'g').should be_true
|
||||
("\u{999}".."\u{9999}").send @method, "\u{9995}"
|
||||
end
|
||||
|
||||
it "returns true if argument is sole element in the range" do
|
||||
|
|
|
@ -11,8 +11,10 @@ describe "Refinement#extend_object" do
|
|||
Module.new do
|
||||
refine c do
|
||||
called = false
|
||||
define_method(:extend_object){called = true}
|
||||
proc{c.extend(self)}.should raise_error(TypeError)
|
||||
define_method(:extend_object) { called = true }
|
||||
-> {
|
||||
c.extend(self)
|
||||
}.should raise_error(TypeError)
|
||||
called.should == false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
require_relative '../../spec_helper'
|
||||
|
||||
ruby_version_is "3.2" do
|
||||
describe "Struct::Group" do
|
||||
it "is no longer defined" do
|
||||
Struct.should_not.const_defined?(:Group)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Struct::Passwd" do
|
||||
it "is no longer defined" do
|
||||
Struct.should_not.const_defined?(:Passwd)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -41,7 +41,7 @@ describe 'Thread::Backtrace::Location#path' do
|
|||
context 'when using a relative script path' do
|
||||
it 'returns a path relative to the working directory' do
|
||||
path = 'fixtures/main.rb'
|
||||
directory = File.dirname(__FILE__)
|
||||
directory = __dir__
|
||||
Dir.chdir(directory) {
|
||||
ruby_exe(path)
|
||||
}.should == path
|
||||
|
|
|
@ -3,10 +3,10 @@ require_relative '../../spec_helper'
|
|||
describe "TrueClass#singleton_method" do
|
||||
ruby_version_is '3.3' do
|
||||
it "raises regardless of whether TrueClass defines the method" do
|
||||
proc{true.singleton_method(:foo)}.should raise_error(NameError)
|
||||
-> { true.singleton_method(:foo) }.should raise_error(NameError)
|
||||
begin
|
||||
def true.foo; end
|
||||
proc{true.singleton_method(:foo)}.should raise_error(NameError)
|
||||
def (true).foo; end
|
||||
-> { true.singleton_method(:foo) }.should raise_error(NameError)
|
||||
ensure
|
||||
TrueClass.send(:remove_method, :foo)
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe "UnboundMethod#source_location" do
|
|||
it "sets the first value to the path of the file in which the method was defined" do
|
||||
file = @method.source_location.first
|
||||
file.should be_an_instance_of(String)
|
||||
file.should == File.realpath('../fixtures/classes.rb', __FILE__)
|
||||
file.should == File.realpath('fixtures/classes.rb', __dir__)
|
||||
end
|
||||
|
||||
it "sets the last value to an Integer representing the line on which the method was defined" do
|
||||
|
|
|
@ -3,8 +3,8 @@ require_relative '../../spec_helper'
|
|||
describe "Warning.[]" do
|
||||
ruby_version_is '2.7.2' do
|
||||
it "returns default values for categories :deprecated and :experimental" do
|
||||
ruby_exe('p Warning[:deprecated]').chomp.should == "false"
|
||||
ruby_exe('p Warning[:experimental]').chomp.should == "true"
|
||||
ruby_exe('p [Warning[:deprecated], Warning[:experimental]]').chomp.should == "[false, true]"
|
||||
ruby_exe('p [Warning[:deprecated], Warning[:experimental]]', options: "-w").chomp.should == "[true, true]"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,6 +17,18 @@ describe "Warning.[]=" do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is '3.3' do
|
||||
it "enables or disables performance warnings" do
|
||||
original = Warning[:performance]
|
||||
begin
|
||||
Warning[:performance] = !original
|
||||
Warning[:performance].should == !original
|
||||
ensure
|
||||
Warning[:performance] = original
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "raises for unknown category" do
|
||||
-> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/)
|
||||
end
|
||||
|
|
|
@ -1107,9 +1107,9 @@ describe "A method" do
|
|||
m({a: 1}).should == {a: 1}
|
||||
m({"a" => 1}).should == {"a" => 1}
|
||||
|
||||
-> { m(a: 1) }.should raise_error(ArgumentError)
|
||||
-> { m(**{a: 1}) }.should raise_error(ArgumentError)
|
||||
-> { m("a" => 1) }.should raise_error(ArgumentError)
|
||||
-> { m(a: 1) }.should raise_error(ArgumentError, 'no keywords accepted')
|
||||
-> { m(**{a: 1}) }.should raise_error(ArgumentError, 'no keywords accepted')
|
||||
-> { m("a" => 1) }.should raise_error(ArgumentError, 'no keywords accepted')
|
||||
end
|
||||
|
||||
evaluate <<-ruby do
|
||||
|
@ -1193,14 +1193,42 @@ describe "A method call with a space between method name and parentheses" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when a single argument provided" do
|
||||
it "assigns it" do
|
||||
context "when a single argument is provided" do
|
||||
it "assigns a simple expression" do
|
||||
args = m (1)
|
||||
args.should == [1]
|
||||
end
|
||||
|
||||
it "assigns an expression consisting of multiple statements" do
|
||||
args = m ((0; 1))
|
||||
args.should == [1]
|
||||
end
|
||||
|
||||
it "assigns one single statement, without the need of parentheses" do
|
||||
args = m (1 == 1 ? true : false)
|
||||
args.should == [true]
|
||||
end
|
||||
|
||||
ruby_version_is "3.3" do
|
||||
it "supports multiple statements" do
|
||||
eval("m (1; 2)").should == [2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when 2+ arguments provided" do
|
||||
context "when multiple arguments are provided" do
|
||||
it "assigns simple expressions" do
|
||||
args = m (1), (2)
|
||||
args.should == [1, 2]
|
||||
end
|
||||
|
||||
it "assigns expressions consisting of multiple statements" do
|
||||
args = m ((0; 1)), ((2; 3))
|
||||
args.should == [1, 3]
|
||||
end
|
||||
end
|
||||
|
||||
context "when the argument looks like an argument list" do
|
||||
it "raises a syntax error" do
|
||||
-> {
|
||||
eval("m (1, 2)")
|
||||
|
|
|
@ -1037,7 +1037,7 @@ describe "Global variable $0" do
|
|||
|
||||
it "is the path given as the main script and the same as __FILE__" do
|
||||
script = "fixtures/dollar_zero.rb"
|
||||
Dir.chdir(File.dirname(__FILE__)) do
|
||||
Dir.chdir(__dir__) do
|
||||
ruby_exe(script).should == "#{script}\n#{script}\nOK"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ describe "BigDecimal#add" do
|
|||
end
|
||||
|
||||
it "returns a + b with given precision" do
|
||||
# documentation states, that precision ist optional, but it ain't,
|
||||
# documentation states that precision is optional, but it ain't,
|
||||
@two.add(@one, 1).should == @three
|
||||
@one .add(@two, 1).should == @three
|
||||
@one.add(@one_minus, 1).should == @zero
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'date'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do
|
||||
version_is date_version, "3.3" do #ruby_version_is "3.2" do
|
||||
describe "Date#deconstruct_keys" do
|
||||
it "returns whole hash for nil as an argument" do
|
||||
d = Date.new(2022, 10, 5)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative "../../spec_helper"
|
||||
require 'date'
|
||||
require_relative '../../shared/time/strftime_for_date'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
describe "Date#strftime" do
|
||||
before :all do
|
||||
|
@ -23,14 +24,14 @@ describe "Date#strftime" do
|
|||
end
|
||||
|
||||
# %v is %e-%b-%Y for Date/DateTime
|
||||
version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@date.strftime("%v").should == " 9-Apr-2000"
|
||||
@date.strftime("%v").should == @date.strftime('%e-%b-%Y')
|
||||
end
|
||||
end
|
||||
|
||||
version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do
|
||||
version_is date_version, "3.2" do #ruby_version_is "3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@date.strftime("%v").should == " 9-APR-2000"
|
||||
@date.strftime("%v").should != @date.strftime('%e-%b-%Y')
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'date'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do
|
||||
version_is date_version, "3.3" do #ruby_version_is "3.2" do
|
||||
describe "DateTime#deconstruct_keys" do
|
||||
it "returns whole hash for nil as an argument" do
|
||||
d = DateTime.new(2022, 10, 5, 13, 30)
|
||||
|
|
|
@ -2,6 +2,7 @@ require_relative '../../spec_helper'
|
|||
require 'date'
|
||||
require_relative '../../shared/time/strftime_for_date'
|
||||
require_relative '../../shared/time/strftime_for_time'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
describe "DateTime#strftime" do
|
||||
before :all do
|
||||
|
@ -33,14 +34,14 @@ describe "DateTime#strftime" do
|
|||
end
|
||||
|
||||
# %v is %e-%b-%Y for Date/DateTime
|
||||
version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
version_is date_version, ""..."3.2" do #ruby_version_is ""..."3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@time.strftime("%v").should == " 3-Feb-2001"
|
||||
@time.strftime("%v").should == @time.strftime('%e-%b-%Y')
|
||||
end
|
||||
end
|
||||
|
||||
version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do
|
||||
version_is date_version, "3.2" do #ruby_version_is "3.1" do
|
||||
it "should be able to show the commercial week" do
|
||||
@time.strftime("%v").should == " 3-FEB-2001"
|
||||
@time.strftime("%v").should != @time.strftime('%e-%b-%Y')
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'date'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
describe "DateTime#to_time" do
|
||||
it "yields a new Time object" do
|
||||
|
@ -18,7 +19,7 @@ describe "DateTime#to_time" do
|
|||
time.sec.should == 59
|
||||
end
|
||||
|
||||
version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do
|
||||
version_is date_version, '3.2.3' do #ruby_version_is "3.2" do
|
||||
it "returns a Time representing the same instant before Gregorian" do
|
||||
datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
|
||||
time = datetime.to_time.utc
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe :net_ftp_getbinaryfile, shared: true do
|
||||
before :each do
|
||||
@fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile"
|
||||
@fixture_file = __dir__ + "/../fixtures/getbinaryfile"
|
||||
@tmp_file = tmp("getbinaryfile")
|
||||
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
|
|
|
@ -3,7 +3,7 @@ describe :net_ftp_putbinaryfile, shared: true do
|
|||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile"
|
||||
@local_fixture_file = __dir__ + "/../fixtures/putbinaryfile"
|
||||
@remote_tmp_file = tmp("binaryfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
|
|
|
@ -3,7 +3,7 @@ describe :net_ftp_puttextfile, shared: true do
|
|||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile"
|
||||
@local_fixture_file = __dir__ + "/../fixtures/puttextfile"
|
||||
@remote_tmp_file = tmp("textfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
|
|
|
@ -9,7 +9,7 @@ ruby_version_is ""..."3.1" do
|
|||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/fixtures/putbinaryfile"
|
||||
@local_fixture_file = __dir__ + "/fixtures/putbinaryfile"
|
||||
@tmp_file = tmp("binaryfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
|
|
|
@ -9,7 +9,7 @@ ruby_version_is ""..."3.1" do
|
|||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/fixtures/puttextfile"
|
||||
@local_fixture_file = __dir__ + "/fixtures/puttextfile"
|
||||
@tmp_file = tmp("textfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
|
|
|
@ -13,11 +13,11 @@ describe "Set#divide" do
|
|||
ret.sort.should == ["five", "four", "one", "three", "two"]
|
||||
end
|
||||
|
||||
# BUG: Does not raise a LocalJumpError, but a NoMethodError
|
||||
#
|
||||
# it "raises a LocalJumpError when not passed a block" do
|
||||
# lambda { Set[1].divide }.should raise_error(LocalJumpError)
|
||||
# end
|
||||
it "returns an enumerator when not passed a block" do
|
||||
ret = Set[1, 2, 3, 4].divide
|
||||
ret.should be_kind_of(Enumerator)
|
||||
ret.each(&:even?).should == Set[Set[1, 3], Set[2, 4]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "Set#divide when passed a block with an arity of 2" do
|
||||
|
@ -31,4 +31,29 @@ describe "Set#divide when passed a block with an arity of 2" do
|
|||
Set[1, 2].divide { |x, y| ret << [x, y] }
|
||||
ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]]
|
||||
end
|
||||
|
||||
it "returns an enumerator when not passed a block" do
|
||||
ret = Set[1, 2, 3, 4].divide
|
||||
ret.should be_kind_of(Enumerator)
|
||||
ret.each { |a, b| (a + b).even? }.should == Set[Set[1, 3], Set[2, 4]]
|
||||
end
|
||||
end
|
||||
|
||||
describe "Set#divide when passed a block with an arity of > 2" do
|
||||
it "only uses the first element if the arity > 2" do
|
||||
set = Set["one", "two", "three", "four", "five"].divide do |x, y, z|
|
||||
y.should be_nil
|
||||
z.should be_nil
|
||||
x.length
|
||||
end
|
||||
set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]]
|
||||
end
|
||||
|
||||
it "only uses the first element if the arity = -1" do
|
||||
set = Set["one", "two", "three", "four", "five"].divide do |*xs|
|
||||
xs.size.should == 1
|
||||
xs.first.length
|
||||
end
|
||||
set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,11 @@ describe :set_inspect, shared: true do
|
|||
Set["1", "2"].send(@method).should include('", "')
|
||||
end
|
||||
|
||||
it "correctly handles self-references" do
|
||||
(set = Set[]) << set
|
||||
set.send(@method).should be_kind_of(String)
|
||||
set.send(@method).should include("#<Set: {...}>")
|
||||
it "correctly handles cyclic-references" do
|
||||
set1 = Set[]
|
||||
set2 = Set[set1]
|
||||
set1 << set2
|
||||
set1.send(@method).should be_kind_of(String)
|
||||
set1.send(@method).should include("#<Set: {...}>")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require_relative '../../spec_helper'
|
||||
require 'time'
|
||||
require 'date'
|
||||
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
|
||||
|
||||
describe "Time#to_datetime" do
|
||||
it "returns a DateTime representing the same instant" do
|
||||
|
@ -13,7 +15,7 @@ describe "Time#to_datetime" do
|
|||
datetime.sec.should == 59
|
||||
end
|
||||
|
||||
version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do
|
||||
version_is date_version, '3.2.3' do #ruby_version_is '3.2' do
|
||||
it "returns a DateTime representing the same instant before Gregorian" do
|
||||
time = Time.utc(1582, 10, 14, 23, 58, 59)
|
||||
datetime = time.to_datetime
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'yaml'
|
||||
|
||||
$test_file = tmp("yaml_test_file")
|
||||
$test_parse_file = File.dirname(__FILE__) + "/test_yaml.yml"
|
||||
$test_parse_file = __dir__ + "/test_yaml.yml"
|
||||
|
|
|
@ -503,6 +503,11 @@ describe "C-API Kernel function" do
|
|||
it "evaluates a string of ruby code" do
|
||||
@s.rb_eval_string("1+1").should == 2
|
||||
end
|
||||
|
||||
it "captures local variables when called within a method" do
|
||||
a = 2
|
||||
@s.rb_eval_string("a+1").should == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "rb_eval_cmd_kw" do
|
||||
|
|
|
@ -219,7 +219,7 @@ describe "CApiObject" do
|
|||
end
|
||||
|
||||
it "requires a ruby file" do
|
||||
$:.unshift File.dirname(__FILE__)
|
||||
$:.unshift __dir__
|
||||
@o.rb_require()
|
||||
$foo.should == 7
|
||||
end
|
||||
|
|
|
@ -4,11 +4,6 @@ describe :file_exist, shared: true do
|
|||
@object.send(@method, 'a_fake_file').should == false
|
||||
end
|
||||
|
||||
it "returns true if the file exist using the alias exists?" do
|
||||
@object.send(@method, __FILE__).should == true
|
||||
@object.send(@method, 'a_fake_file').should == false
|
||||
end
|
||||
|
||||
it "raises an ArgumentError if not passed one argument" do
|
||||
-> { @object.send(@method) }.should raise_error(ArgumentError)
|
||||
-> { @object.send(@method, __FILE__, __FILE__) }.should raise_error(ArgumentError)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use_realpath = File.respond_to?(:realpath)
|
||||
root = File.dirname(__FILE__)
|
||||
root = __dir__
|
||||
dir = "fixtures/code"
|
||||
CODE_LOADING_DIR = use_realpath ? File.realpath(dir, root) : File.expand_path(dir, root)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче