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@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-06-29 14:35:37 +00:00
parent 6a4aa4838c
commit 5b593e3889
79 changed files with 1555 additions and 304 deletions

View file

@ -0,0 +1,40 @@
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.4
DisplayCopNames: true
Exclude:
- command_line/fixtures/bad_syntax.rb
DisabledByDefault: true
Lint:
Enabled: true
Lint/AssignmentInCondition:
Enabled: false
Lint/LiteralInCondition:
Enabled: false
Lint/UnifiedInteger:
Enabled: false
Lint/UnusedBlockArgument:
Enabled: false
Lint/UnusedMethodArgument:
Enabled: false
Lint/UselessAssignment:
Enabled: false
Lint/UselessComparison:
Enabled: false
# The cop registers too many false positives to `.should == something`
Lint/Void:
Enabled: false
Lint/EmptyExpression:
Exclude:
- 'language/**/*.rb'

View file

@ -0,0 +1,211 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-06-18 19:12:38 +0200 using RuboCop version 0.49.1.
# 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
# versions of RuboCop, may require this file to be generated again.
# Offense count: 6
Lint/AmbiguousBlockAssociation:
Exclude:
- 'core/kernel/trace_var_spec.rb'
- 'language/fixtures/argv_encoding.rb'
- 'language/fixtures/break.rb'
- 'shared/process/abort.rb'
# Offense count: 3
Lint/CircularArgumentReference:
Exclude:
- 'language/block_spec.rb'
- 'language/def_spec.rb'
- 'language/lambda_spec.rb'
# Offense count: 2
Lint/DuplicateCaseCondition:
Exclude:
- 'language/case_spec.rb'
# Offense count: 6
Lint/DuplicateMethods:
Exclude:
- 'core/array/fixtures/encoded_strings.rb'
- 'core/method/fixtures/classes.rb'
- 'core/module/fixtures/classes.rb'
- 'core/unboundmethod/fixtures/classes.rb'
- 'fixtures/class.rb'
# Offense count: 4
Lint/EmptyWhen:
Exclude:
- 'language/case_spec.rb'
# Offense count: 5
Lint/EnsureReturn:
Exclude:
- 'language/fixtures/ensure.rb'
- 'language/fixtures/return.rb'
- 'language/return_spec.rb'
# Offense count: 10
Lint/FloatOutOfRange:
Exclude:
- 'core/string/modulo_spec.rb'
# Offense count: 46
Lint/FormatParameterMismatch:
Exclude:
- 'core/kernel/sprintf_spec.rb'
- 'core/string/modulo_spec.rb'
# Offense count: 25
Lint/HandleExceptions:
Enabled: false
# Offense count: 2
Lint/ImplicitStringConcatenation:
Exclude:
- 'language/string_spec.rb'
# Offense count: 4
Lint/IneffectiveAccessModifier:
Exclude:
- 'core/kernel/fixtures/classes.rb'
- 'core/module/fixtures/classes.rb'
- 'language/fixtures/private.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: runtime_error, standard_error
Lint/InheritException:
Exclude:
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/exception/fixtures/common.rb'
- 'core/module/fixtures/autoload_ex1.rb'
# Offense count: 3
# Cop supports --auto-correct.
Lint/LiteralInInterpolation:
Exclude:
- 'language/defined_spec.rb'
- 'language/fixtures/squiggly_heredoc.rb'
# Offense count: 16
Lint/Loop:
Exclude:
- 'language/until_spec.rb'
- 'language/while_spec.rb'
# Offense count: 8
# Cop supports --auto-correct.
Lint/MultipleCompare:
Exclude:
- 'language/precedence_spec.rb'
# Offense count: 8
Lint/NestedMethodDefinition:
Exclude:
- 'language/def_spec.rb'
# Offense count: 12
Lint/ParenthesesAsGroupedExpression:
Exclude:
- 'command_line/rubyopt_spec.rb'
- 'core/string/fixtures/freeze_magic_comment.rb'
- 'language/block_spec.rb'
- 'language/fixtures/send.rb'
- 'language/method_spec.rb'
- 'library/socket/socket/getaddrinfo_spec.rb'
# Offense count: 22
Lint/RescueException:
Exclude:
- 'command_line/fixtures/debug_info.rb'
- 'core/dir/fileno_spec.rb'
- 'core/exception/cause_spec.rb'
- 'core/exception/no_method_error_spec.rb'
- 'core/kernel/fixtures/autoload_frozen.rb'
- 'core/module/autoload_spec.rb'
- 'core/mutex/sleep_spec.rb'
- 'core/process/euid_spec.rb'
- 'core/process/setsid_spec.rb'
- 'core/process/uid_spec.rb'
- 'core/thread/abort_on_exception_spec.rb'
- 'core/thread/shared/exit.rb'
- 'language/rescue_spec.rb'
- 'library/erb/filename_spec.rb'
# Offense count: 1
Lint/ScriptPermission:
Exclude:
- 'command_line/fixtures/bin/launcher.rb'
# Offense count: 10
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'core/binding/local_variables_spec.rb'
- 'language/block_spec.rb'
- 'language/proc_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
Lint/StringConversionInInterpolation:
Exclude:
- 'core/io/print_spec.rb'
# Offense count: 9
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'core/io/pipe_spec.rb'
- 'core/io/popen_spec.rb'
- 'language/block_spec.rb'
# Offense count: 91
# Cop supports --auto-correct.
Lint/UnneededSplatExpansion:
Exclude:
- 'core/array/element_reference_spec.rb'
- 'core/array/unshift_spec.rb'
- 'core/enumerable/fixtures/classes.rb'
- 'core/enumerable/max_by_spec.rb'
- 'core/enumerable/min_by_spec.rb'
- 'core/enumerable/minmax_by_spec.rb'
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/file/basename_spec.rb'
- 'core/kernel/p_spec.rb'
- 'language/array_spec.rb'
- 'language/break_spec.rb'
- 'language/case_spec.rb'
- 'language/next_spec.rb'
- 'language/send_spec.rb'
- 'language/variables_spec.rb'
# Offense count: 53
Lint/UnreachableCode:
Exclude:
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/kernel/catch_spec.rb'
- 'core/kernel/throw_spec.rb'
- 'language/break_spec.rb'
- 'language/fixtures/break.rb'
- 'language/fixtures/break_lambda_toplevel.rb'
- 'language/fixtures/break_lambda_toplevel_block.rb'
- 'language/fixtures/break_lambda_toplevel_method.rb'
- 'language/fixtures/return.rb'
- 'language/next_spec.rb'
- 'language/return_spec.rb'
- 'optional/capi/kernel_spec.rb'
- 'shared/kernel/raise.rb'
# Offense count: 9
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Exclude:
- 'core/module/define_method_spec.rb'
- 'core/module/fixtures/classes.rb'
- 'core/module/module_function_spec.rb'
- 'core/module/private_class_method_spec.rb'
- 'core/module/private_spec.rb'
- 'core/module/protected_spec.rb'
- 'core/module/public_spec.rb'

View file

@ -3,6 +3,7 @@ language: ruby
install:
- git clone https://github.com/ruby/mspec.git ../mspec
script:
- if [ -n "$RUBOCOP" ]; then gem install rubocop -v 0.49.1 && rubocop; fi
- ../mspec/bin/mspec $MSPEC_OPTS
matrix:
include:
@ -17,7 +18,7 @@ matrix:
rvm: 2.3.4
- os: linux
rvm: 2.4.1
env: CHECK_LEAKS=true
env: CHECK_LEAKS=true RUBOCOP=true
- os: linux
rvm: ruby-head
allow_failures:

View file

@ -19,5 +19,11 @@ describe 'The -S command line option' do
result = ruby_exe(nil, options: '-S launcher.rb', env: { 'PATH' => @path }, args: '2>&1')
result.should =~ /success$/
end
it "runs launcher found in PATH and sets the exit status to 1 if it fails" do
result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1')
result.should =~ /\bdie\b/
$?.exitstatus.should == 1
end
end
end

View file

@ -0,0 +1 @@
raise 'die'

View file

@ -8,7 +8,9 @@ describe "ARGF.binmode" do
end
it "returns self" do
ruby_exe("puts(ARGF.binmode == ARGF)", args: @bin_file).chomp.should == 'true'
argf [@bin_file] do
@argf.binmode.should equal @argf
end
end
platform_is :windows do
@ -29,18 +31,13 @@ describe "ARGF.binmode" do
end
end
platform_is_not :windows do
# This does nothing on Unix but it should not raise any errors.
it "does not raise an error" do
ruby_exe("ARGF.binmode", args: @bin_file)
$?.should be_kind_of(Process::Status)
$?.to_i.should == 0
it "sets the file's encoding to ASCII-8BIT" do
argf [@bin_file, @file1] do
@argf.binmode
@argf.binmode?.should == true
@argf.gets.encoding.should == Encoding::ASCII_8BIT
@argf.skip
@argf.read.encoding.should == Encoding::ASCII_8BIT
end
end
it "sets the file's encoding to ASCII-8BIT" do
script = fixture __FILE__, "encoding.rb"
output = "true\n#{Encoding::ASCII_8BIT}\n#{Encoding::ASCII_8BIT}\n"
ruby_exe(script, args: [@bin_file, @file1]).should == output
end
end

View file

@ -1,5 +0,0 @@
ARGF.binmode
puts ARGF.binmode?
puts ARGF.gets.encoding
ARGF.skip
puts ARGF.read.encoding

View file

@ -1,28 +1,41 @@
require File.expand_path('../../../spec_helper', __FILE__)
# These specs need to be run to a separate process as there is no way to reset ARGF encoding
describe "ARGF.set_encoding" do
before :each do
@file = fixture __FILE__, "file1.txt"
end
it "sets the external encoding when passed an encoding instance" do
enc = ruby_exe('ARGF.set_encoding(Encoding::UTF_8); print ARGF.gets.encoding', args: [@file])
enc.should == "UTF-8"
argf [@file] do
@argf.set_encoding(Encoding::US_ASCII)
@argf.external_encoding.should == Encoding::US_ASCII
@argf.gets.encoding.should == Encoding::US_ASCII
end
end
it "sets the external encoding when passed an encoding name" do
enc = ruby_exe('ARGF.set_encoding("utf-8"); print ARGF.gets.encoding', args: [@file])
enc.should == "UTF-8"
argf [@file] do
@argf.set_encoding("us-ascii")
@argf.external_encoding.should == Encoding::US_ASCII
@argf.gets.encoding.should == Encoding::US_ASCII
end
end
it "sets the external, internal encoding when passed two encoding instances" do
enc = ruby_exe('ARGF.set_encoding(Encoding::UTF_8, Encoding::EUC_JP); print ARGF.gets.encoding', args: [@file])
enc.should == "EUC-JP"
argf [@file] do
@argf.set_encoding(Encoding::US_ASCII, Encoding::EUC_JP)
@argf.external_encoding.should == Encoding::US_ASCII
@argf.internal_encoding.should == Encoding::EUC_JP
@argf.gets.encoding.should == Encoding::EUC_JP
end
end
it "sets the external, internal encoding when passed 'ext:int' String" do
enc = ruby_exe('ARGF.set_encoding("utf-8:euc-jp"); print ARGF.gets.encoding', args: [@file])
enc.should == "EUC-JP"
argf [@file] do
@argf.set_encoding("us-ascii:euc-jp")
@argf.external_encoding.should == Encoding::US_ASCII
@argf.internal_encoding.should == Encoding::EUC_JP
@argf.gets.encoding.should == Encoding::EUC_JP
end
end
end

View file

@ -258,12 +258,12 @@ describe "Array#[]= with [index]" do
end
it "sets the value of the element at index" do
a = [1, 2, 3, 4]
a[2] = 5
a[-1] = 6
a[5] = 3
a.should == [1, 2, 5, 6, nil, 3]
end
a = [1, 2, 3, 4]
a[2] = 5
a[-1] = 6
a[5] = 3
a.should == [1, 2, 5, 6, nil, 3]
end
it "sets the value of the element if it is right beyond the array boundary" do
a = [1, 2, 3, 4]
@ -370,11 +370,11 @@ describe "Array#[]= with [m..n]" do
end
it "replaces the section defined by range" do
a = [6, 5, 4, 3, 2, 1]
a[1...2] = 9
a[3..6] = [6, 6, 6]
a.should == [6, 9, 4, 6, 6, 6]
end
a = [6, 5, 4, 3, 2, 1]
a[1...2] = 9
a[3..6] = [6, 6, 6]
a.should == [6, 9, 4, 6, 6, 6]
end
it "replaces the section if m and n < 0" do
a = [1, 2, 3, 4, 5]
@ -415,4 +415,3 @@ describe "Array#[] after a shift" do
a.should == [3,4]
end
end

View file

@ -18,6 +18,46 @@ describe :array_inspect, shared: true do
items.send(@method).should == "[0, 1, 2]"
end
it "does not call #to_s on a String returned from #inspect" do
str = "abc"
str.should_not_receive(:to_s)
[str].send(@method).should == '["abc"]'
end
it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
obj = mock("Array#inspect/to_s calls #to_s")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return("abc")
[obj].send(@method).should == "[abc]"
end
it "does not call #to_str on the object returned from #inspect when it is not a String" do
obj = mock("Array#inspect/to_s does not call #to_str")
obj.should_receive(:inspect).and_return(obj)
obj.should_not_receive(:to_str)
[obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
end
it "does not call #to_str on the object returned from #to_s when it is not a String" do
obj = mock("Array#inspect/to_s does not call #to_str on #to_s result")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return(obj)
obj.should_not_receive(:to_str)
[obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
end
it "does not swallow exceptions raised by #to_s" do
obj = mock("Array#inspect/to_s does not swallow #to_s exceptions")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_raise(Exception)
lambda { [obj].send(@method) }.should raise_error(Exception)
end
it "represents a recursive element with '[...]'" do
ArraySpecs.recursive_array.send(@method).should == "[1, \"two\", 3.0, [...], [...], [...], [...], [...]]"
ArraySpecs.head_recursive_array.send(@method).should == "[[...], [...], [...], [...], [...], 1, \"two\", 3.0]"

View file

@ -10,9 +10,9 @@ describe "BasicObject#equal?" do
it "is unaffected by overriding __id__" do
o1 = mock("object")
o1.stub!(:__id__).and_return(10)
o2 = mock("object")
o2.stub!(:__id__).and_return(10)
def o1.__id__; 10; end
def o2.__id__; 10; end
o1.equal?(o2).should be_false
end

View file

@ -4,4 +4,16 @@ describe "Bignum" do
it "includes Comparable" do
Bignum.include?(Comparable).should == true
end
it ".allocate raises a TypeError" do
lambda do
Bignum.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
Bignum.new
end.should raise_error(NoMethodError)
end
end

View file

@ -0,0 +1,30 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '2.4' do
describe 'Enumerable#sum' do
before :each do
@enum = Object.new.to_enum
class << @enum
def each
yield 0
yield(-1)
yield 2
yield 2/3r
end
end
end
it 'returns amount of the elements with taking an argument as the initial value' do
@enum.sum(10).should == 35/3r
end
it 'gives 0 as a default argument' do
@enum.sum.should == 5/3r
end
it 'takes a block to transform the elements' do
@enum.sum { |element| element * 2 }.should == 10/3r
end
end
end

View file

@ -0,0 +1,29 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '2.4' do
describe 'Enumerable#uniq' do
it 'returns an array that contains only unique elements' do
[0, 1, 2, 3].to_enum.uniq { |n| n.even? }.should == [0, 1]
end
context 'when yielded with multiple arguments' do
before :each do
@enum = Object.new.to_enum
class << @enum
def each
yield 0, 'foo'
yield 1, 'FOO'
yield 2, 'bar'
end
end
end
ruby_bug '#13669', ''...'2.5' do
it 'returns all yield arguments as an array' do
@enum.uniq { |_, label| label.downcase }.should == [[0, 'foo'], [2, 'bar']]
end
end
end
end
end

View file

@ -1,5 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Enumerator#inspect" do
it "needs to be reviewed for spec completeness"
describe "shows a representation of the Enumerator" do
it "including receiver and method" do
(1..3).each.inspect.should == "#<Enumerator: 1..3:each>"
end
it "including receiver and method and arguments" do
(1..3).each_slice(2).inspect.should == "#<Enumerator: 1..3:each_slice(2)>"
end
it "including the nested Enumerator" do
(1..3).each.each_slice(2).inspect.should == "#<Enumerator: #<Enumerator: 1..3:each>:each_slice(2)>"
end
end
end

View file

@ -64,7 +64,7 @@ describe "Enumerator::Lazy#grep" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep(Integer).grep(Object).first(3).should == [0, 1, 2]
@eventsmixed.grep(BasicObject).grep(Object).first(1)

View file

@ -63,7 +63,7 @@ ruby_version_is "2.3" do
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
@eventsmixed.grep_v(Symbol).grep_v(String).first(1)

View file

@ -0,0 +1,39 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '2.4' do
describe 'Enumerator::Lazy#uniq' do
context 'when yielded with an argument' do
before :each do
@lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
end
it 'returns a lazy enumerator' do
@lazy.should be_an_instance_of(Enumerator::Lazy)
@lazy.force.should == [0, 1]
end
it 'sets the size to nil' do
@lazy.size.should == nil
end
end
context 'when yielded with multiple arguments' do
before :each do
enum = Object.new.to_enum
class << enum
def each
yield 0, 'foo'
yield 1, 'FOO'
yield 2, 'bar'
end
end
@lazy = enum.lazy
end
it 'returns all yield arguments as an array' do
@lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end
end
end
end

View file

@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "FalseClass" do
it ".allocate raises a TypeError" do
lambda do
FalseClass.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
FalseClass.new
end.should raise_error(NoMethodError)
end
end

View file

@ -27,6 +27,12 @@ describe "Fixnum#&" do
(-1 & 2**64).should == 18446744073709551616
end
it "coerces the rhs and calls #coerce" do
obj = mock("fixnum bit and")
obj.should_receive(:coerce).with(6).and_return([3, 6])
(6 & obj).should == 2
end
it "raises a TypeError when passed a Float" do
lambda { (3 & 3.4) }.should raise_error(TypeError)
end

View file

@ -4,4 +4,16 @@ describe "Fixnum" do
it "includes Comparable" do
Fixnum.include?(Comparable).should == true
end
it ".allocate raises a TypeError" do
lambda do
Fixnum.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
Fixnum.new
end.should raise_error(NoMethodError)
end
end

View file

@ -4,4 +4,16 @@ describe "Float" do
it "includes Comparable" do
Float.include?(Comparable).should == true
end
it ".allocate raises a TypeError" do
lambda do
Float.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
Float.new
end.should raise_error(NoMethodError)
end
end

View file

@ -35,6 +35,12 @@ describe :float_modulo, shared: true do
(1/r).should < 0
end
it "tries to coerce the modulus" do
obj = mock("modulus")
obj.should_receive(:coerce).with(1.25).and_return([1.25, 0.5])
(1.25 % obj).should == 0.25
end
it "raises a ZeroDivisionError if other is zero" do
lambda { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError)
lambda { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)

View file

@ -15,7 +15,7 @@ describe :hash_to_s, shared: true do
h.send(@method).should == str
end
it "calls inspect on keys and values" do
it "calls #inspect on keys and values" do
key = mock('key')
val = mock('val')
key.should_receive(:inspect).and_return('key')
@ -24,6 +24,46 @@ describe :hash_to_s, shared: true do
{ key => val }.send(@method).should == '{key=>val}'
end
it "does not call #to_s on a String returned from #inspect" do
str = "abc"
str.should_not_receive(:to_s)
{ a: str }.send(@method).should == '{:a=>"abc"}'
end
it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
obj = mock("Hash#inspect/to_s calls #to_s")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return("abc")
{ a: obj }.send(@method).should == "{:a=>abc}"
end
it "does not call #to_str on the object returned from #inspect when it is not a String" do
obj = mock("Hash#inspect/to_s does not call #to_str")
obj.should_receive(:inspect).and_return(obj)
obj.should_not_receive(:to_str)
{ a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
end
it "does not call #to_str on the object returned from #to_s when it is not a String" do
obj = mock("Hash#inspect/to_s does not call #to_str on #to_s result")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_return(obj)
obj.should_not_receive(:to_str)
{ a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
end
it "does not swallow exceptions raised by #to_s" do
obj = mock("Hash#inspect/to_s does not swallow #to_s exceptions")
obj.should_receive(:inspect).and_return(obj)
obj.should_receive(:to_s).and_raise(Exception)
lambda { { a: obj }.send(@method) }.should raise_error(Exception)
end
it "handles hashes with recursive values" do
x = {}
x[0] = x

View file

@ -9,10 +9,10 @@ describe "IO#<<" do
end
it "calls #to_s on the object to print it" do
lambda {
$stderr << 1337
lambda {
$stderr << 1337
}.should output_to_fd("1337", $stderr)
end
end
it "raises an error if the stream is closed" do
io = IOSpecs.closed_io

View file

@ -74,10 +74,7 @@ describe "IO.popen" do
end
it "does not throw an exception if child exited and has been waited for" do
# Avoid the /bin/sh subshell using :options and :args to sleep.
# We don't want to kill only the subshell and leave "ruby -e sleep"
# running indefinitely
@io = IO.popen(ruby_cmd(nil, :options => '-e', :args => 'sleep'))
@io = IO.popen([*ruby_exe, '-e', 'sleep'])
pid = @io.pid
Process.kill "KILL", pid
@io.close
@ -201,28 +198,28 @@ describe "IO.popen" do
end
it "accepts an Array of command and arguments" do
exe, *args = ruby_cmd(nil).split
exe, *args = ruby_exe
IO.popen({"FOO" => "bar"}, [[exe, "specfu"], *args, "-e", "puts ENV['FOO']"]) do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array of command and arguments, and an IO mode" do
exe, *args = ruby_cmd(nil).split
exe, *args = ruby_exe
IO.popen({"FOO" => "bar"}, [[exe, "specfu"], *args, "-e", "puts ENV['FOO']"], "r") do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array command with a separate trailing Hash of Process.exec options" do
IO.popen({"FOO" => "bar"}, [*ruby_cmd(nil).split, "-e", "STDERR.puts ENV['FOO']"],
IO.popen({"FOO" => "bar"}, [*ruby_exe, "-e", "STDERR.puts ENV['FOO']"],
err: [:child, :out]) do |io|
io.read.should == "bar\n"
end
end
it "accepts an Array command with a separate trailing Hash of Process.exec options, and an IO mode" do
IO.popen({"FOO" => "bar"}, [*ruby_cmd(nil).split, "-e", "STDERR.puts ENV['FOO']"],
IO.popen({"FOO" => "bar"}, [*ruby_exe, "-e", "STDERR.puts ENV['FOO']"],
"r", err: [:child, :out]) do |io|
io.read.should == "bar\n"
end
@ -231,45 +228,45 @@ describe "IO.popen" do
context "with a leading Array argument" do
it "uses the Array as command plus args for the child process" do
IO.popen([*ruby_cmd(nil).split, "-e", "puts 'hello'"]) do |io|
IO.popen([*ruby_exe, "-e", "puts 'hello'"]) do |io|
io.read.should == "hello\n"
end
end
it "accepts a leading ENV Hash" do
IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "puts ENV['FOO']"]) do |io|
IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "puts ENV['FOO']"]) do |io|
io.read.should == "bar\n"
end
end
it "accepts a trailing Hash of Process.exec options" do
IO.popen([*ruby_cmd(nil).split, "does_not_exist", {err: [:child, :out]}]) do |io|
IO.popen([*ruby_exe, "does_not_exist", {err: [:child, :out]}]) do |io|
io.read.should =~ /LoadError/
end
end
it "accepts an IO mode argument following the Array" do
IO.popen([*ruby_cmd(nil).split, "does_not_exist", {err: [:child, :out]}], "r") do |io|
IO.popen([*ruby_exe, "does_not_exist", {err: [:child, :out]}], "r") do |io|
io.read.should =~ /LoadError/
end
end
it "accepts [env, command, arg1, arg2, ..., exec options]" do
IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]]) do |io|
io.read.should == "bar\n"
end
end
it "accepts '[env, command, arg1, arg2, ..., exec options], mode'" do
IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]], "r") do |io|
io.read.should == "bar\n"
end
end
it "accepts '[env, command, arg1, arg2, ..., exec options], mode, IO options'" do
IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]",
IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]",
err: [:child, :out]], "r",
internal_encoding: Encoding::EUC_JP) do |io|
io.read.should == "bar\n"
@ -278,7 +275,7 @@ describe "IO.popen" do
end
it "accepts '[env, command, arg1, arg2, ...], mode, IO + exec options'" do
IO.popen([{"FOO" => "bar"}, *ruby_cmd(nil).split, "-e", "STDERR.puts ENV[:FOO.to_s]"], "r",
IO.popen([{"FOO" => "bar"}, *ruby_exe, "-e", "STDERR.puts ENV[:FOO.to_s]"], "r",
err: [:child, :out], internal_encoding: Encoding::EUC_JP) do |io|
io.read.should == "bar\n"
io.internal_encoding.should == Encoding::EUC_JP

View file

@ -49,8 +49,7 @@ describe "Kernel#autoload" do
end
it "can autoload in instance_eval" do
instance_eval do
# this instance_eval is not needed because specs are run in instance_eval
Object.new.instance_eval do
autoload :KSAutoloadD, fixture(__FILE__, "autoload_d.rb")
KSAutoloadD.loaded.should == :ksautoload_d
end

View file

@ -22,6 +22,12 @@ describe 'Kernel#caller' do
locations.length.should == 1
end
it 'returns an Array of caller locations using a range' do
locations = KernelSpecs::CallerTest.locations(1..1)
locations.length.should == 1
end
it 'returns the locations as String instances' do
locations = KernelSpecs::CallerTest.locations
line = __LINE__ - 1

View file

@ -53,7 +53,7 @@ with_feature :encoding do
it "removes the final carriage return, newline from a multi-byte $_" do
script = fixture __FILE__, "#{@method}.rb"
KernelSpecs.encoded_chomp(script).should == "あれ"
KernelSpecs.run_with_dash_n(script).should == "あれ"
end
end

View file

@ -41,7 +41,7 @@ with_feature :encoding do
it "removes the final multi-byte character from $_" do
script = fixture __FILE__, "#{@method}.rb"
KernelSpecs.encoded_chop(script).should == ""
KernelSpecs.run_with_dash_n(script).should == ""
end
end

View file

@ -37,6 +37,16 @@ describe "Kernel#clone" do
o3.frozen?.should == true
end
ruby_version_is '2.4' do
it 'takes an option to copy freeze state or not' do
@obj.clone(freeze: true).frozen?.should == false
@obj.clone(freeze: false).frozen?.should == false
@obj.freeze
@obj.clone(freeze: true).frozen?.should == true
@obj.clone(freeze: false).frozen?.should == false
end
end
it "copies instance variables" do
clone = @obj.clone
clone.one.should == 1

View file

@ -32,26 +32,36 @@ module KernelSpecs
end
def self.has_private_method(name)
cmd = %[| #{ruby_cmd(nil)} -n -e "print Kernel.private_method_defined?('#{name}')"]
ruby_exe("puts", args: cmd) == "true"
IO.popen([*ruby_exe, "-n", "-e", "print Kernel.private_method_defined?(#{name.inspect})"], "r+") do |io|
io.puts
io.close_write
io.read
end == "true"
end
def self.chop(str, method)
cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; #{method}; print $_'"
ruby_exe "puts", args: cmd
end
def self.encoded_chop(file)
ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
IO.popen([*ruby_exe, "-n", "-e", "$_ = #{str.inspect}; #{method}; print $_"], "r+") do |io|
io.puts
io.close_write
io.read
end
end
def self.chomp(str, method, sep="\n")
cmd = "| #{ruby_cmd(nil)} -n -e '$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_'"
ruby_exe "puts", args: cmd
code = "$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_"
IO.popen([*ruby_exe, "-n", "-e", code], "r+") do |io|
io.puts
io.close_write
io.read
end
end
def self.encoded_chomp(file)
ruby_exe "puts", args: "| #{ruby_cmd(nil)} -n #{file}"
def self.run_with_dash_n(file)
IO.popen([*ruby_exe, "-n", file], "r+") do |io|
io.puts
io.close_write
io.read
end
end
# kind_of?, is_a?, instance_of?

View file

@ -18,9 +18,9 @@ describe "Kernel#public_method" do
it "raises a NameError when called on a protected method" do
@obj.send(:protected_method).should == :protected_method
lambda do
lambda {
@obj.public_method(:protected_method)
end.should raise_error(NameError)
}.should raise_error(NameError)
end
it "raises a NameError if we only repond_to_missing? method, true" do

View file

@ -0,0 +1,41 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Kernel#singleton_method" do
it "find a method defined on the singleton class" do
obj = Object.new
def obj.foo; end
obj.singleton_method(:foo).should be_an_instance_of(Method)
end
it "returns a Method which can be called" do
obj = Object.new
def obj.foo; 42; end
obj.singleton_method(:foo).call.should == 42
end
it "only looks at singleton methods and not at methods in the class" do
klass = Class.new do
def foo
42
end
end
obj = klass.new
obj.foo.should == 42
-> {
obj.singleton_method(:foo)
}.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
it "raises a NameError if there is no such method" do
obj = Object.new
-> {
obj.singleton_method(:not_existing)
}.should raise_error(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
end

View file

@ -415,6 +415,15 @@ describe "Marshal.dump" do
load = Marshal.load(dump)
load.should == (1...2)
end
it "dumps a Range with extra instance variables" do
range = (1...3)
range.instance_variable_set :@foo, 42
dump = Marshal.dump(range)
load = Marshal.load(dump)
load.should == range
load.instance_variable_get(:@foo).should == 42
end
end
describe "with a Time" do

View file

@ -0,0 +1,13 @@
require File.expand_path('../../../spec_helper', __FILE__)
ruby_version_is '2.4' do
describe 'MatchData#named_captures' do
it 'returns a Hash that has captured name and the matched string pairs' do
/(?<a>.)(?<b>.)?/.match('0').named_captures.should == { 'a' => '0', 'b' => nil }
end
it 'prefers later captures' do
/\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
end
end
end

View file

@ -10,4 +10,14 @@ describe "MatchData#values_at" do
/(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(2..4, 0..1).should == ["X", "113", "8", "HX1138", "H"]
end
end
ruby_version_is '2.4' do
it 'slices captures with the given names' do
/(?<a>.)(?<b>.)(?<c>.)/.match('012').values_at(:c, :a).should == ['2', '0']
end
it 'takes names and indices' do
/\A(?<a>.)(?<b>.)\z/.match('01').values_at(0, 1, 2, :a, :b).should == ['01', '0', '1', '0', '1']
end
end
end

View file

@ -414,7 +414,7 @@ describe "Module#autoload" do
mod_names = []
mod_count.times do |i|
mod_name = :"Mod#{i}"
autoload mod_name, autoload_path
Object.autoload mod_name, autoload_path
mod_names << mod_name
end

View file

@ -151,10 +151,10 @@ end
describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "makes any subsequently defined methods module functions with the normal semantics" do
m = Module.new {
module_function
def test1() end
def test2() end
}
module_function
def test1() end
def test2() end
}
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@ -172,12 +172,12 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "stops creating module functions if the body encounters another toggle " \
"like public/protected/private without arguments" do
m = Module.new {
module_function
def test1() end
def test2() end
public
def test3() end
}
module_function
def test1() end
def test2() end
public
def test3() end
}
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@ -187,16 +187,13 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "does not stop creating module functions if the body encounters " \
"public/protected/private WITH arguments" do
m = Module.new {
def foo() end
module_function
def test1() end
def test2() end
public :foo
def test3() end
}
def foo() end
module_function
def test1() end
def test2() end
public :foo
def test3() end
}
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@ -205,11 +202,10 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "does not affect module_evaled method definitions also if outside the eval itself" do
m = Module.new {
module_function
module_eval { def test1() end }
module_eval " def test2() end "
}
module_function
module_eval { def test1() end }
module_eval " def test2() end "
}
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
@ -217,11 +213,10 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "has no effect if inside a module_eval if the definitions are outside of it" do
m = Module.new {
module_eval { module_function }
def test1() end
def test2() end
}
module_eval { module_function }
def test1() end
def test2() end
}
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
@ -229,13 +224,12 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "functions normally if both toggle and definitions inside a module_eval" do
m = Module.new {
module_eval {
module_function
def test1() end
def test2() end
}
}
module_eval {
module_function
def test1() end
def test2() end
}
}
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@ -243,10 +237,9 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "affects evaled method definitions also even when outside the eval itself" do
m = Module.new {
module_function
eval "def test1() end"
}
module_function
eval "def test1() end"
}
m.respond_to?(:test1).should == true
end
@ -254,7 +247,6 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do
m = Module.new {
eval "module_function"
def test1() end
}
@ -263,13 +255,13 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "functions normally if both toggle and definitions inside a eval" do
m = Module.new {
eval <<-CODE
module_function
eval <<-CODE
module_function
def test1() end
def test2() end
CODE
}
def test1() end
def test2() end
CODE
}
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true

View file

@ -9,11 +9,11 @@ describe :set_visibility, shared: true do
it "sets visibility to following method definitions" do
visibility = @method
mod = Module.new {
send visibility
send visibility
def test1() end
def test2() end
}
def test1() end
def test2() end
}
mod.should send(:"have_#{@method}_instance_method", :test1, false)
mod.should send(:"have_#{@method}_instance_method", :test2, false)
@ -23,11 +23,11 @@ describe :set_visibility, shared: true do
visibility = @method
new_visibility = nil
mod = Module.new {
send visibility
new_visibility = [:protected, :private].find {|vis| vis != visibility }
send new_visibility
def test1() end
}
send visibility
new_visibility = [:protected, :private].find {|vis| vis != visibility }
send new_visibility
def test1() end
}
mod.should send(:"have_#{new_visibility}_instance_method", :test1, false)
end
@ -35,11 +35,11 @@ describe :set_visibility, shared: true do
it "continues setting visibility if the body encounters other visibility setters with arguments" do
visibility = @method
mod = Module.new {
send visibility
def test1() end
send([:protected, :private].find {|vis| vis != visibility }, :test1)
def test2() end
}
send visibility
def test1() end
send([:protected, :private].find {|vis| vis != visibility }, :test1)
def test2() end
}
mod.should send(:"have_#{@method}_instance_method", :test2, false)
end
@ -47,11 +47,11 @@ describe :set_visibility, shared: true do
it "does not affect module_evaled method definitions when itself is outside the eval" do
visibility = @method
mod = Module.new {
send visibility
send visibility
module_eval { def test1() end }
module_eval " def test2() end "
}
module_eval { def test1() end }
module_eval " def test2() end "
}
mod.should have_public_instance_method(:test1, false)
mod.should have_public_instance_method(:test2, false)
@ -60,10 +60,10 @@ describe :set_visibility, shared: true do
it "does not affect outside method definitions when itself is inside a module_eval" do
visibility = @method
mod = Module.new {
module_eval { send visibility }
module_eval { send visibility }
def test1() end
}
def test1() end
}
mod.should have_public_instance_method(:test1, false)
end
@ -71,12 +71,12 @@ describe :set_visibility, shared: true do
it "affects normally if itself and method definitions are inside a module_eval" do
visibility = @method
mod = Module.new {
module_eval {
send visibility
module_eval {
send visibility
def test1() end
}
}
def test1() end
}
}
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@ -85,11 +85,11 @@ describe :set_visibility, shared: true do
visibility = @method
initialized_visibility = [:public, :protected, :private].find {|sym| sym != visibility }
mod = Module.new {
send initialized_visibility
eval visibility.to_s
send initialized_visibility
eval visibility.to_s
def test1() end
}
def test1() end
}
mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false)
end
@ -97,10 +97,10 @@ describe :set_visibility, shared: true do
it "affects evaled method definitions when itself is outside the eval" do
visibility = @method
mod = Module.new {
send visibility
send visibility
eval "def test1() end"
}
eval "def test1() end"
}
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@ -108,12 +108,12 @@ describe :set_visibility, shared: true do
it "affects normally if itself and following method definitions are inside a eval" do
visibility = @method
mod = Module.new {
eval <<-CODE
#{visibility}
eval <<-CODE
#{visibility}
def test1() end
CODE
}
def test1() end
CODE
}
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end
@ -122,11 +122,11 @@ describe :set_visibility, shared: true do
it "sets the visibility outside the closure" do
visibility = @method
mod = Module.new {
1.times {
send visibility
}
def test1() end
}
1.times {
send visibility
}
def test1() end
}
mod.should send(:"have_#{@method}_instance_method", :test1, false)
end

View file

@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "NilClass" do
it ".allocate raises a TypeError" do
lambda do
NilClass.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
NilClass.new
end.should raise_error(NoMethodError)
end
end

View file

@ -407,6 +407,18 @@ describe :numeric_step, :shared => true do
end
end
end
describe "when stop is not passed" do
it "returns infinity_value" do
1.send(@method, *@step_args.call()).size.should == infinity_value
end
end
describe "when stop is nil" do
it "returns infinity_value" do
1.send(@method, *@step_args.call(nil, 5)).size.should == infinity_value
end
end
end
end
end

View file

@ -1,4 +1,17 @@
module ProcessSpecs
def self.use_system_ruby(context)
if defined?(MSpecScript::SYSTEM_RUBY)
context.send(:before, :all) do
@ruby = ::RUBY_EXE
Object.const_set(:RUBY_EXE, MSpecScript::SYSTEM_RUBY)
end
context.send(:after, :all) do
Object.const_set(:RUBY_EXE, @ruby)
end
end
end
class Daemonizer
attr_reader :input, :data
@ -55,13 +68,6 @@ module ProcessSpecs
end
def wait_on_result
# Ensure the process exits
begin
Process.kill :TERM, pid if pid
rescue Errno::ESRCH
# Ignore the process not existing
end
@thread.join
end

View file

@ -1 +0,0 @@
File.write ARGV[0], ENV["FOO"]

View file

@ -1 +0,0 @@
print :glark

View file

@ -2,6 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Process.kill" do
ProcessSpecs.use_system_ruby(self)
before :each do
@pid = Process.pid
end
@ -22,7 +24,7 @@ describe "Process.kill" do
end
it "raises Errno::ESRCH if the process does not exist" do
pid = Process.spawn(ruby_cmd("sleep 10"))
pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
Process.kill("SIGKILL", pid)
Process.wait(pid)
lambda {
@ -33,6 +35,8 @@ end
platform_is_not :windows do
describe "Process.kill" do
ProcessSpecs.use_system_ruby(self)
before :each do
@sp = ProcessSpecs::Signalizer.new
end
@ -73,6 +77,8 @@ platform_is_not :windows do
end
describe "Process.kill" do
ProcessSpecs.use_system_ruby(self)
before :each do
@sp1 = ProcessSpecs::Signalizer.new
@sp2 = ProcessSpecs::Signalizer.new
@ -95,57 +101,27 @@ platform_is_not :windows do
end
describe "Process.kill" do
before :each do
@sp = ProcessSpecs::Signalizer.new "self"
end
after :each do
@sp.cleanup
@sp.cleanup if @sp
end
it "signals the process group if the PID is zero" do
@sp = ProcessSpecs::Signalizer.new "self"
@sp.result.should == "signaled"
end
end
describe "Process.kill" do
before :each do
@sp = ProcessSpecs::Signalizer.new "group_numeric"
end
after :each do
@sp.cleanup
end
it "signals the process group if the signal number is negative" do
@sp = ProcessSpecs::Signalizer.new "group_numeric"
@sp.result.should == "signaled"
end
end
describe "Process.kill" do
before :each do
@sp = ProcessSpecs::Signalizer.new "group_short_string"
end
after :each do
@sp.cleanup
end
it "signals the process group if the short signal name starts with a minus sign" do
@sp = ProcessSpecs::Signalizer.new "group_short_string"
@sp.result.should == "signaled"
end
end
describe "Process.kill" do
before :each do
@sp = ProcessSpecs::Signalizer.new "group_full_string"
end
after :each do
@sp.cleanup
end
it "signals the process group if the full signal name starts with a minus sign" do
@sp = ProcessSpecs::Signalizer.new "group_full_string"
@sp.result.should == "signaled"
end
end

View file

@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
newline = "\n"
platform_is :windows do
@ -31,8 +32,14 @@ describe :process_spawn_does_not_close_std_streams, shared: true do
end
describe "Process.spawn" do
ProcessSpecs.use_system_ruby(self)
before :each do
@name = tmp("process_spawn.txt")
@var = "$FOO"
platform_is :windows do
@var = "%FOO%"
end
end
after :each do
@ -44,14 +51,14 @@ describe "Process.spawn" do
end
it "returns the process ID of the new process as a Fixnum" do
pid = Process.spawn(ruby_cmd("exit"))
pid = Process.spawn(*ruby_exe, "-e", "exit")
Process.wait pid
pid.should be_an_instance_of(Fixnum)
end
it "returns immediately" do
start = Time.now
pid = Process.spawn(ruby_cmd("sleep 10"))
pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
(Time.now - start).should < 5
Process.kill :KILL, pid
Process.wait pid
@ -196,52 +203,57 @@ describe "Process.spawn" do
end
it "sets environment variables in the child environment" do
Process.wait Process.spawn({"FOO" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
File.read(@name).should == "BAR"
Process.wait Process.spawn({"FOO" => "BAR"}, "echo #{@var}>#{@name}")
File.read(@name).should == "BAR\n"
end
it "unsets environment variables whose value is nil" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn({"FOO" => nil}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
File.read(@name).should == ""
Process.wait Process.spawn({"FOO" => nil}, "echo #{@var}>#{@name}")
expected = "\n"
platform_is :windows do
# Windows does not expand the variable if it is unset
expected = "#{@var}\n"
end
File.read(@name).should == expected
end
it "calls #to_hash to convert the environment" do
o = mock("to_hash")
o.should_receive(:to_hash).and_return({"FOO" => "BAR"})
Process.wait Process.spawn(o, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
File.read(@name).should == "BAR"
Process.wait Process.spawn(o, "echo #{@var}>#{@name}")
File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment keys" do
o = mock("to_str")
o.should_receive(:to_str).and_return("FOO")
Process.wait Process.spawn({o => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
File.read(@name).should == "BAR"
Process.wait Process.spawn({o => "BAR"}, "echo #{@var}>#{@name}")
File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment values" do
o = mock("to_str")
o.should_receive(:to_str).and_return("BAR")
Process.wait Process.spawn({"FOO" => o}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
File.read(@name).should == "BAR"
Process.wait Process.spawn({"FOO" => o}, "echo #{@var}>#{@name}")
File.read(@name).should == "BAR\n"
end
it "raises an ArgumentError if an environment key includes an equals sign" do
lambda do
Process.spawn({"FOO=" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
Process.spawn({"FOO=" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment key includes a null byte" do
lambda do
Process.spawn({"\000" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
Process.spawn({"\000" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment value includes a null byte" do
lambda do
Process.spawn({"FOO" => "\000"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
Process.spawn({"FOO" => "\000"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
@ -252,7 +264,7 @@ describe "Process.spawn" do
"PATH" => ENV["PATH"],
"HOME" => ENV["HOME"]
}
@common_env_spawn_args = [@minimal_env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name)]
@common_env_spawn_args = [@minimal_env, "echo #{@var}>#{@name}"]
end
platform_is_not :windows do
@ -260,7 +272,7 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: true)
$?.success?.should be_true
File.read(@name).should == ""
File.read(@name).should == "\n"
end
end
@ -268,15 +280,15 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: false)
$?.success?.should be_true
File.read(@name).should == "BAR"
File.read(@name).should == "BAR\n"
end
platform_is_not :windows do
it "does not unset environment variables included in the environment hash" do
env = @minimal_env.merge({"FOO" => "BAR"})
Process.wait Process.spawn(env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name), unsetenv_others: true)
Process.wait Process.spawn(env, "echo #{@var}>#{@name}", unsetenv_others: true)
$?.success?.should be_true
File.read(@name).should == "BAR"
File.read(@name).should == "BAR\n"
end
end
@ -400,55 +412,55 @@ describe "Process.spawn" do
it "redirects STDOUT to the given file descriptior if out: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file.fileno)
end.should output_to_fd("glark", file)
Process.wait Process.spawn("echo glark", out: file.fileno)
end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: IO" do
File.open(@name, 'w') do |file|
lambda do
Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file)
end.should output_to_fd("glark", file)
Process.wait Process.spawn("echo glark", out: file)
end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: String" do
Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: @name)
File.read(@name).should == "glark"
Process.wait Process.spawn("echo glark", out: @name)
File.read(@name).should == "glark\n"
end
it "redirects STDOUT to the given file if out: [String name, String mode]" do
Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: [@name, 'w'])
File.read(@name).should == "glark"
Process.wait Process.spawn("echo glark", out: [@name, 'w'])
File.read(@name).should == "glark\n"
end
it "redirects STDERR to the given file descriptior if err: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file.fileno)
end.should output_to_fd("glark", file)
Process.wait Process.spawn("echo glark>&2", err: file.fileno)
end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file descriptor if err: IO" do
File.open(@name, 'w') do |file|
lambda do
Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file)
end.should output_to_fd("glark", file)
Process.wait Process.spawn("echo glark>&2", err: file)
end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file if err: String" do
Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: @name)
File.read(@name).should == "glark"
Process.wait Process.spawn("echo glark>&2", err: @name)
File.read(@name).should == "glark\n"
end
it "redirects STDERR to child STDOUT if :err => [:child, :out]" do
File.open(@name, 'w') do |file|
lambda do
Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), :out => file, :err => [:child, :out])
end.should output_to_fd("glark", file)
Process.wait Process.spawn("echo glark>&2", :out => file, :err => [:child, :out])
end.should output_to_fd("glark\n", file)
end
end

View file

@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Process.wait" do
ProcessSpecs.use_system_ruby(self)
before :all do
begin
leaked = Process.waitall

View file

@ -15,7 +15,7 @@ describe "Regexp#encoding" do
end
it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do
/#{}\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
/\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
end
it "defaults to UTF-8 if \\u escapes appear" do

View file

@ -133,7 +133,7 @@ with_feature :encoding do
str += [0xDF].pack('C')
str.ascii_only?.should be_false
str.encoding.should == Encoding::ASCII_8BIT
end
end
# TODO: Deal with case when the byte in question isn't valid in the source
# encoding?

View file

@ -4,4 +4,16 @@ describe "Symbol" do
it "includes Comparable" do
Symbol.include?(Comparable).should == true
end
it ".allocate raises a TypeError" do
lambda do
Symbol.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
Symbol.new
end.should raise_error(NoMethodError)
end
end

View file

@ -36,4 +36,11 @@ describe "Time#dup" do
t.dup.should be_an_instance_of(c)
t.dup.should_not be_an_instance_of(Time)
end
it "does not copy frozen status from the original" do
t = Time.now
t.freeze
t2 = t.dup
t2.frozen?.should be_false
end
end

View file

@ -22,6 +22,20 @@ describe "Time#localtime" do
t.utc_offset.should == 3630
end
describe "on a frozen time" do
it "does not raise an error if already in the right time zone" do
time = Time.now
time.freeze
time.localtime.should equal(time)
end
it "raises a RuntimeError if the time has a different time zone" do
time = Time.gm(2007, 1, 9, 12, 0, 0)
time.freeze
lambda { time.localtime }.should raise_error(RuntimeError)
end
end
describe "with an argument that responds to #to_int" do
it "coerces using #to_int" do
o = mock('integer')

View file

@ -1,5 +1,5 @@
describe :time_gmtime, shared: true do
it "returns the utc representation of time" do
it "converts self to UTC, modifying the receiver" do
# Testing with America/Regina here because it doesn't have DST.
with_timezone("CST", -6) do
t = Time.local(2007, 1, 9, 6, 0, 0)
@ -7,4 +7,27 @@ describe :time_gmtime, shared: true do
t.should == Time.gm(2007, 1, 9, 12, 0, 0)
end
end
it "returns self" do
with_timezone("CST", -6) do
t = Time.local(2007, 1, 9, 12, 0, 0)
t.send(@method).should equal(t)
end
end
describe "on a frozen time" do
it "does not raise an error if already in UTC" do
time = Time.gm(2007, 1, 9, 12, 0, 0)
time.freeze
time.send(@method).should equal(time)
end
it "raises a RuntimeError if the time is not UTC" do
with_timezone("CST", -6) do
time = Time.now
time.freeze
lambda { time.send(@method) }.should raise_error(RuntimeError)
end
end
end
end

View file

@ -0,0 +1,15 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "TrueClass" do
it ".allocate raises a TypeError" do
lambda do
TrueClass.allocate
end.should raise_error(TypeError)
end
it ".new is undefined" do
lambda do
TrueClass.new
end.should raise_error(NoMethodError)
end
end

View file

@ -1134,7 +1134,7 @@ with_feature :encoding do
STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
end
it "has the encodings set by #set_encoding"do
it "has the encodings set by #set_encoding" do
code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
"p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
@ -1167,7 +1167,7 @@ with_feature :encoding do
STDOUT.external_encoding.should be_nil
end
it "has the encodings set by #set_encoding"do
it "has the encodings set by #set_encoding" do
code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
"p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
@ -1193,7 +1193,7 @@ with_feature :encoding do
STDERR.external_encoding.should be_nil
end
it "has the encodings set by #set_encoding"do
it "has the encodings set by #set_encoding" do
code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
"p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}

View file

@ -28,6 +28,10 @@ describe "BigDecimal#>" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY
@nan = BigDecimal("NaN")
end
@ -64,6 +68,17 @@ describe "BigDecimal#>" do
(@infinity_neg > @infinity).should == false
end
ruby_bug "#13674", ""..."2.4" do
it "properly handles Float infinity values" do
@values.each { |val|
(val > @float_infinity).should == false
(@float_infinity > val).should == true
(val > @float_infinity_neg).should == true
(@float_infinity_neg > val).should == false
}
end
end
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|

View file

@ -28,6 +28,10 @@ describe "BigDecimal#>=" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY
@nan = BigDecimal("NaN")
end
@ -68,6 +72,17 @@ describe "BigDecimal#>=" do
(@infinity_neg >= @infinity).should == false
end
ruby_bug "#13674", ""..."2.4" do
it "properly handles Float infinity values" do
@values.each { |val|
(val >= @float_infinity).should == false
(@float_infinity >= val).should == true
(val >= @float_infinity_neg).should == true
(@float_infinity_neg >= val).should == false
}
end
end
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|

View file

@ -28,6 +28,10 @@ describe "BigDecimal#<" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY
@nan = BigDecimal("NaN")
end
@ -62,6 +66,17 @@ describe "BigDecimal#<" do
(@infinity_neg < @infinity).should == true
end
ruby_bug "#13674", ""..."2.4" do
it "properly handles Float infinity values" do
@values.each { |val|
(val < @float_infinity).should == true
(@float_infinity < val).should == false
(val < @float_infinity_neg).should == false
(@float_infinity_neg < val).should == true
}
end
end
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|

View file

@ -28,6 +28,10 @@ describe "BigDecimal#<=" do
@infinity = BigDecimal("Infinity")
@infinity_neg = BigDecimal("-Infinity")
@float_infinity = Float::INFINITY
@float_infinity_neg = -Float::INFINITY
@nan = BigDecimal("NaN")
end
@ -68,6 +72,17 @@ describe "BigDecimal#<=" do
(@infinity_neg <= @infinity).should == true
end
ruby_bug "#13674", ""..."2.4" do
it "properly handles Float infinity values" do
@values.each { |val|
(val <= @float_infinity).should == true
(@float_infinity <= val).should == false
(val <= @float_infinity_neg).should == false
(@float_infinity_neg <= val).should == true
}
end
end
it "properly handles NaN values" do
@values += [@infinity, @infinity_neg, @nan]
@values.each { |val|

View file

@ -3,7 +3,7 @@ describe :date_jd, shared: true do
Date.send(@method, 2454482).should == Date.civil(2008, 1, 16)
end
it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed"do
it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do
Date.send(@method).should == Date.civil(-4712, 1, 1)
end

View file

@ -20,12 +20,12 @@ describe "Matrix#regular?" do
end
it "raises an error for rectangular matrices" do
lambda {
Matrix[[1], [2], [3]].regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
Matrix[[1], [2], [3]].regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
Matrix.empty(3,0).regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end
lambda {
Matrix.empty(3,0).regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end
end

View file

@ -19,13 +19,13 @@ describe "Matrix#singular?" do
end
it "raises an error for rectangular matrices" do
lambda {
Matrix[[1], [2], [3]].singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
Matrix[[1], [2], [3]].singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
Matrix.empty(3,0).singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end
lambda {
Matrix.empty(3,0).singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end
end

View file

@ -35,10 +35,7 @@ module NetFTPSpecs
response @connect_message || "220 Dummy FTP Server ready!"
begin
loop do
command = @socket.recv(1024)
break if command.nil?
while command = @socket.recv(1024)
command, argument = command.chomp.split(" ", 2)
if command == "QUIT"

View file

@ -34,7 +34,7 @@ describe "REXML::Element#add_attribute" do
@person.attributes["male"].should == "true"
end
it "returns the attribute added" do
it "returns the attribute added" do
attr = REXML::Attribute.new("name", "Tony")
@person.add_attribute(attr).should == attr
end

View file

@ -14,7 +14,7 @@ describe "REXML::Text#wrap" do
@t.wrap("abc def", 10, false).should == "abc def"
end
it "takes a newline at the beginning option as the third parameter"do
it "takes a newline at the beginning option as the third parameter" do
@t.wrap("abc def", 3, true).should == "\nabc\ndef"
end
end

View file

@ -12,6 +12,16 @@ describe "SecureRandom.random_number" do
end
end
it "generates a random (potentially bignum) integer value for bignum argument" do
max = 12345678901234567890
11.times do
num = SecureRandom.random_number max
num.should be_kind_of(Integer)
(0 <= num).should == true
(num < max).should == true
end
end
it "generates a random float number between 0.0 and 1.0 if no argument provided" do
64.times do
num = SecureRandom.random_number
@ -21,6 +31,37 @@ describe "SecureRandom.random_number" do
end
end
ruby_version_is "2.3" do
it "generates a random value in given (integer) range limits" do
64.times do
num = SecureRandom.random_number 11...13
num.should be_kind_of(Integer)
(11 <= num).should == true
(num < 13).should == true
end
end
it "generates a random value in given big (integer) range limits" do
lower = 12345678901234567890
upper = 12345678901234567890 + 5
32.times do
num = SecureRandom.random_number lower..upper
num.should be_kind_of(Integer)
(lower <= num).should == true
(num <= upper).should == true
end
end
it "generates a random value in given (float) range limits" do
64.times do
num = SecureRandom.random_number 0.6..0.9
num.should be_kind_of(Float)
(0.6 <= num).should == true
(num <= 0.9).should == true
end
end
end
it "generates a random float number between 0.0 and 1.0 if argument is negative" do
num = SecureRandom.random_number(-10)
num.should be_kind_of(Float)
@ -28,6 +69,13 @@ describe "SecureRandom.random_number" do
(num < 1.0).should == true
end
it "generates a random float number between 0.0 and 1.0 if argument is negative float" do
num = SecureRandom.random_number(-11.1)
num.should be_kind_of(Float)
(0.0 <= num).should == true
(num < 1.0).should == true
end
it "generates different float numbers with subsequent invocations" do
# quick and dirty check, but good enough
values = []

View file

@ -11,7 +11,7 @@ describe "Socket::BasicSocket#getsockname" do
@socket = TCPServer.new("127.0.0.1", 0)
sockaddr = Socket.unpack_sockaddr_in(@socket.getsockname)
sockaddr.should == [@socket.addr[1], "127.0.0.1"]
end
end
it "works on sockets listening in ipaddr_any" do
@socket = TCPServer.new(0)

View file

@ -14,6 +14,7 @@ describe "Socket#connect_nonblock" do
after :each do
@socket.close
@server.close
@thread.join if @thread
end

View file

@ -27,7 +27,7 @@ describe "StringIO#printf" do
@io.printf("%d %04x", 123, 123)
@io.pos.should eql(16)
end
end
end
describe "StringIO#printf when in append mode" do

View file

@ -3,7 +3,7 @@ describe :strscan_matched_size, shared: true do
@s = StringScanner.new("This is a test")
end
it "returns the size of the most recent match" do
it "returns the size of the most recent match" do
@s.check(/This/)
@s.send(@method).should == 4
@s.send(@method).should == 4

View file

@ -2,17 +2,16 @@ require File.expand_path('../../../../spec_helper', __FILE__)
require 'zlib'
describe "Zlib::Deflate#params" do
it "changes the deflate parameters" do
data = 'abcdefghijklm'
it "changes the deflate parameters" do
data = 'abcdefghijklm'
d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY
d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY
d << data.slice!(0..10)
d.params Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY
d << data
d << data.slice!(0..10)
d.params Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY
d << data
Zlib::Inflate.inflate(d.finish).should == 'abcdefghijklm'
Zlib::Inflate.inflate(d.finish).should == 'abcdefghijklm'
end
end

View file

@ -1 +1,22 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'zlib'
require 'stringio'
describe 'GzipReader#gets' do
describe 'with "" separator' do
it 'reads paragraphs skipping newlines' do
# gz contains "\n\n\n\n\n123\n45\n\n\n\n\nabc\nde\n\n\n\n\n"
gz = Zlib::GzipReader.new(
StringIO.new(
[31, 139, 8, 0, 223, 152, 48, 89, 0, 3, 227, 226, 2, 2, 67, 35,
99, 46, 19, 83, 16, 139, 43, 49, 41, 153, 43, 37, 21, 204, 4, 0,
32, 119, 45, 184, 27, 0, 0, 0].pack('C*')
)
)
gz.gets('').should == "123\n45\n\n"
gz.gets('').should == "abc\nde\n\n"
gz.eof?.should be_true
end
end
end

View file

@ -0,0 +1,17 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'stringio'
require 'zlib'
describe 'GzipReader#readpartial' do
before :each do
@data = '12345abcde'
@zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
@io = StringIO.new(@zip)
end
it 'accepts nil buffer' do
gz = Zlib::GzipReader.new(@io)
gz.readpartial(5, nil).should == '12345'
end
end

View file

@ -0,0 +1,122 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'stringio'
require 'zlib'
describe 'GzipReader#ungetbyte' do
before :each do
@data = '12345abcde'
@zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
@io = StringIO.new @zip
end
describe 'at the start of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io)
end
describe 'with an integer' do
it 'prepends the byte to the stream' do
@gz.ungetbyte 0x21
@gz.read.should == '!12345abcde'
end
ruby_bug "#13616", ""..."2.6" do
it 'decrements pos' do
@gz.ungetbyte 0x21
@gz.pos.should == -1
end
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not prepend anything to the stream' do
@gz.ungetbyte nil
@gz.read.should == '12345abcde'
end
it 'does not decrement pos' do
@gz.ungetbyte nil
@gz.pos.should == 0
end
end
end
end
describe 'in the middle of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io)
@gz.read 5
end
describe 'with an integer' do
it 'inserts the corresponding character into the stream' do
@gz.ungetbyte 0x21
@gz.read.should == '!abcde'
end
it 'decrements pos' do
@gz.ungetbyte 0x21
@gz.pos.should == 4
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not insert anything into the stream' do
@gz.ungetbyte nil
@gz.read.should == 'abcde'
end
it 'does not decrement pos' do
@gz.ungetbyte nil
@gz.pos.should == 5
end
end
end
end
describe 'at the end of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io)
@gz.read
end
describe 'with an integer' do
it 'appends the corresponding character to the stream' do
@gz.ungetbyte 0x21
@gz.read.should == '!'
end
it 'decrements pos' do
@gz.ungetbyte 0x21
@gz.pos.should == 9
end
it 'makes eof? false' do
@gz.ungetbyte 0x21
@gz.eof?.should be_false
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not append anything to the stream' do
@gz.ungetbyte nil
@gz.read.should == ''
end
it 'does not decrement pos' do
@gz.ungetbyte nil
@gz.pos.should == 10
end
it 'does not make eof? false' do
@gz.ungetbyte nil
@gz.eof?.should be_true
end
end
end
end
end

View file

@ -1 +1,292 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'stringio'
require 'zlib'
describe 'GzipReader#ungetc' do
before :each do
@data = '12345abcde'
@zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
@io = StringIO.new @zip
end
describe 'at the start of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
end
describe 'with a single-byte character' do
it 'prepends the character to the stream' do
@gz.ungetc 'x'
@gz.read.should == 'x12345abcde'
end
ruby_bug "#13616", ""..."2.6" do
it 'decrements pos' do
@gz.ungetc 'x'
@gz.pos.should == -1
end
end
end
describe 'with a multi-byte character' do
it 'prepends the character to the stream' do
@gz.ungetc 'ŷ'
@gz.read.should == 'ŷ12345abcde'
end
ruby_bug "#13616", ""..."2.6" do
it 'decrements pos' do
@gz.ungetc 'ŷ'
@gz.pos.should == -2
end
end
end
describe 'with a multi-character string' do
it 'prepends the characters to the stream' do
@gz.ungetc 'xŷž'
@gz.read.should == 'xŷž12345abcde'
end
ruby_bug "#13616", ""..."2.6" do
it 'decrements pos' do
@gz.ungetc 'xŷž'
@gz.pos.should == -5
end
end
end
describe 'with an integer' do
it 'prepends the corresponding character to the stream' do
@gz.ungetc 0x21
@gz.read.should == '!12345abcde'
end
ruby_bug "#13616", ""..."2.6" do
it 'decrements pos' do
@gz.ungetc 0x21
@gz.pos.should == -1
end
end
end
describe 'with an empty string' do
it 'does not prepend anything to the stream' do
@gz.ungetc ''
@gz.read.should == '12345abcde'
end
it 'does not decrement pos' do
@gz.ungetc ''
@gz.pos.should == 0
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not prepend anything to the stream' do
@gz.ungetc nil
@gz.read.should == '12345abcde'
end
it 'does not decrement pos' do
@gz.ungetc nil
@gz.pos.should == 0
end
end
end
end
describe 'in the middle of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
@gz.read 5
end
describe 'with a single-byte character' do
it 'inserts the character into the stream' do
@gz.ungetc 'x'
@gz.read.should == 'xabcde'
end
it 'decrements pos' do
@gz.ungetc 'x'
@gz.pos.should == 4
end
end
describe 'with a multi-byte character' do
it 'inserts the character into the stream' do
@gz.ungetc 'ŷ'
@gz.read.should == 'ŷabcde'
end
it 'decrements pos' do
@gz.ungetc 'ŷ'
@gz.pos.should == 3
end
end
describe 'with a multi-character string' do
it 'inserts the characters into the stream' do
@gz.ungetc 'xŷž'
@gz.read.should == 'xŷžabcde'
end
it 'decrements pos' do
@gz.ungetc 'xŷž'
@gz.pos.should == 0
end
end
describe 'with an integer' do
it 'inserts the corresponding character into the stream' do
@gz.ungetc 0x21
@gz.read.should == '!abcde'
end
it 'decrements pos' do
@gz.ungetc 0x21
@gz.pos.should == 4
end
end
describe 'with an empty string' do
it 'does not insert anything into the stream' do
@gz.ungetc ''
@gz.read.should == 'abcde'
end
it 'does not decrement pos' do
@gz.ungetc ''
@gz.pos.should == 5
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not insert anything into the stream' do
@gz.ungetc nil
@gz.read.should == 'abcde'
end
it 'does not decrement pos' do
@gz.ungetc nil
@gz.pos.should == 5
end
end
end
end
describe 'at the end of the stream' do
before :each do
@gz = Zlib::GzipReader.new(@io, external_encoding: Encoding::UTF_8)
@gz.read
end
describe 'with a single-byte character' do
it 'appends the character to the stream' do
@gz.ungetc 'x'
@gz.read.should == 'x'
end
it 'decrements pos' do
@gz.ungetc 'x'
@gz.pos.should == 9
end
it 'makes eof? false' do
@gz.ungetc 'x'
@gz.eof?.should be_false
end
end
describe 'with a multi-byte character' do
it 'appends the character to the stream' do
@gz.ungetc 'ŷ'
@gz.read.should == 'ŷ'
end
it 'decrements pos' do
@gz.ungetc 'ŷ'
@gz.pos.should == 8
end
it 'makes eof? false' do
@gz.ungetc 'ŷ'
@gz.eof?.should be_false
end
end
describe 'with a multi-character string' do
it 'appends the characters to the stream' do
@gz.ungetc 'xŷž'
@gz.read.should == 'xŷž'
end
it 'decrements pos' do
@gz.ungetc 'xŷž'
@gz.pos.should == 5
end
it 'makes eof? false' do
@gz.ungetc 'xŷž'
@gz.eof?.should be_false
end
end
describe 'with an integer' do
it 'appends the corresponding character to the stream' do
@gz.ungetc 0x21
@gz.read.should == '!'
end
it 'decrements pos' do
@gz.ungetc 0x21
@gz.pos.should == 9
end
it 'makes eof? false' do
@gz.ungetc 0x21
@gz.eof?.should be_false
end
end
describe 'with an empty string' do
it 'does not append anything to the stream' do
@gz.ungetc ''
@gz.read.should == ''
end
it 'does not decrement pos' do
@gz.ungetc ''
@gz.pos.should == 10
end
it 'does not make eof? false' do
@gz.ungetc ''
@gz.eof?.should be_true
end
end
quarantine! do # https://bugs.ruby-lang.org/issues/13675
describe 'with nil' do
it 'does not append anything to the stream' do
@gz.ungetc nil
@gz.read.should == ''
end
it 'does not decrement pos' do
@gz.ungetc nil
@gz.pos.should == 10
end
it 'does not make eof? false' do
@gz.ungetc nil
@gz.eof?.should be_true
end
end
end
end
end

View file

@ -17,14 +17,14 @@ describe "Zlib::GzipWriter#mtime=" do
@io.string[4, 4].should == [1,0,0,0].pack('C*')
end
it "sets mtime using Time" do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.mtime = Time.at 1
it "sets mtime using Time" do
Zlib::GzipWriter.wrap @io do |gzio|
gzio.mtime = Time.at 1
gzio.mtime.should == Time.at(1)
end
gzio.mtime.should == Time.at(1)
end
@io.string[4, 4].should == [1,0,0,0].pack('C*')
@io.string[4, 4].should == [1,0,0,0].pack('C*')
end
it "raises if the header was written" do
@ -36,4 +36,3 @@ it "sets mtime using Time" do
end
end
end

View file

@ -22,7 +22,7 @@ describe "CApiBignumSpecs" do
@min_long = ensure_bignum(-@max_long - 1)
@max_ulong = ensure_bignum(2**(0.size * 8) - 1)
end
end
end
describe "rb_big2long" do
unless full_range_longs

View file

@ -260,7 +260,7 @@ describe "C-API Kernel function" do
end.should raise_error(NameError)
proof[0].should == 23
end
end
end
describe "rb_rescue" do
before :each do