aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-29 14:35:37 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-29 14:35:37 +0000
commit021bec087823b11e60a669ed0390096d978b893e (patch)
tree70d928d35c01b51bb9a6cdc44af4bd7cc05a669b
parenta6c9453d869479e23ce0c0349795ea5853ac1898 (diff)
downloadruby-021bec087823b11e60a669ed0390096d978b893e.tar.gz
Update to ruby/spec@abf1700
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--spec/rubyspec/.rubocop.yml40
-rw-r--r--spec/rubyspec/.rubocop_todo.yml211
-rw-r--r--spec/rubyspec/.travis.yml3
-rw-r--r--spec/rubyspec/command_line/dash_upper_s_spec.rb6
-rw-r--r--spec/rubyspec/command_line/fixtures/bin/dash_s_fail1
-rw-r--r--spec/rubyspec/core/argf/binmode_spec.rb23
-rw-r--r--spec/rubyspec/core/argf/fixtures/encoding.rb5
-rw-r--r--spec/rubyspec/core/argf/set_encoding_spec.rb31
-rw-r--r--spec/rubyspec/core/array/element_set_spec.rb23
-rw-r--r--spec/rubyspec/core/array/shared/inspect.rb40
-rw-r--r--spec/rubyspec/core/basicobject/equal_spec.rb4
-rw-r--r--spec/rubyspec/core/bignum/bignum_spec.rb12
-rw-r--r--spec/rubyspec/core/enumerable/sum_spec.rb30
-rw-r--r--spec/rubyspec/core/enumerable/uniq_spec.rb29
-rw-r--r--spec/rubyspec/core/enumerator/inspect_spec.rb14
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb2
-rw-r--r--spec/rubyspec/core/enumerator/lazy/uniq_spec.rb39
-rw-r--r--spec/rubyspec/core/false/falseclass_spec.rb15
-rw-r--r--spec/rubyspec/core/fixnum/bit_and_spec.rb6
-rw-r--r--spec/rubyspec/core/fixnum/fixnum_spec.rb12
-rw-r--r--spec/rubyspec/core/float/float_spec.rb12
-rw-r--r--spec/rubyspec/core/float/shared/modulo.rb6
-rw-r--r--spec/rubyspec/core/hash/shared/to_s.rb42
-rw-r--r--spec/rubyspec/core/io/output_spec.rb6
-rw-r--r--spec/rubyspec/core/io/popen_spec.rb29
-rw-r--r--spec/rubyspec/core/kernel/autoload_spec.rb3
-rw-r--r--spec/rubyspec/core/kernel/caller_spec.rb6
-rw-r--r--spec/rubyspec/core/kernel/chomp_spec.rb2
-rw-r--r--spec/rubyspec/core/kernel/chop_spec.rb2
-rw-r--r--spec/rubyspec/core/kernel/clone_spec.rb10
-rw-r--r--spec/rubyspec/core/kernel/fixtures/classes.rb34
-rw-r--r--spec/rubyspec/core/kernel/public_method_spec.rb4
-rw-r--r--spec/rubyspec/core/kernel/singleton_method_spec.rb41
-rw-r--r--spec/rubyspec/core/marshal/dump_spec.rb9
-rw-r--r--spec/rubyspec/core/matchdata/named_captures_spec.rb13
-rw-r--r--spec/rubyspec/core/matchdata/values_at_spec.rb10
-rw-r--r--spec/rubyspec/core/module/autoload_spec.rb2
-rw-r--r--spec/rubyspec/core/module/module_function_spec.rb88
-rw-r--r--spec/rubyspec/core/module/shared/set_visibility.rb86
-rw-r--r--spec/rubyspec/core/nil/nilclass_spec.rb15
-rw-r--r--spec/rubyspec/core/numeric/shared/step.rb12
-rw-r--r--spec/rubyspec/core/process/fixtures/common.rb20
-rw-r--r--spec/rubyspec/core/process/fixtures/env.rb1
-rw-r--r--spec/rubyspec/core/process/fixtures/print.rb1
-rw-r--r--spec/rubyspec/core/process/kill_spec.rb48
-rw-r--r--spec/rubyspec/core/process/spawn_spec.rb84
-rw-r--r--spec/rubyspec/core/process/wait_spec.rb3
-rw-r--r--spec/rubyspec/core/regexp/encoding_spec.rb2
-rw-r--r--spec/rubyspec/core/string/encoding_spec.rb2
-rw-r--r--spec/rubyspec/core/symbol/symbol_spec.rb12
-rw-r--r--spec/rubyspec/core/time/dup_spec.rb7
-rw-r--r--spec/rubyspec/core/time/localtime_spec.rb14
-rw-r--r--spec/rubyspec/core/time/shared/gmtime.rb25
-rw-r--r--spec/rubyspec/core/true/trueclass_spec.rb15
-rw-r--r--spec/rubyspec/language/predefined_spec.rb6
-rw-r--r--spec/rubyspec/library/bigdecimal/gt_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/gte_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/lt_spec.rb15
-rw-r--r--spec/rubyspec/library/bigdecimal/lte_spec.rb15
-rw-r--r--spec/rubyspec/library/date/shared/jd.rb2
-rw-r--r--spec/rubyspec/library/matrix/regular_spec.rb14
-rw-r--r--spec/rubyspec/library/matrix/singular_spec.rb14
-rw-r--r--spec/rubyspec/library/net/ftp/fixtures/server.rb5
-rw-r--r--spec/rubyspec/library/rexml/element/add_attribute_spec.rb2
-rw-r--r--spec/rubyspec/library/rexml/text/wrap_spec.rb2
-rw-r--r--spec/rubyspec/library/securerandom/random_number_spec.rb48
-rw-r--r--spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb2
-rw-r--r--spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb1
-rw-r--r--spec/rubyspec/library/stringio/printf_spec.rb2
-rw-r--r--spec/rubyspec/library/stringscanner/shared/matched_size.rb2
-rw-r--r--spec/rubyspec/library/zlib/deflate/params_spec.rb17
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/gets_spec.rb21
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb17
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb122
-rw-r--r--spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb291
-rw-r--r--spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb13
-rw-r--r--spec/rubyspec/optional/capi/bignum_spec.rb2
-rw-r--r--spec/rubyspec/optional/capi/kernel_spec.rb2
79 files changed, 1555 insertions, 304 deletions
diff --git a/spec/rubyspec/.rubocop.yml b/spec/rubyspec/.rubocop.yml
new file mode 100644
index 0000000000..a776517b73
--- /dev/null
+++ b/spec/rubyspec/.rubocop.yml
@@ -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'
diff --git a/spec/rubyspec/.rubocop_todo.yml b/spec/rubyspec/.rubocop_todo.yml
new file mode 100644
index 0000000000..cb91f43ead
--- /dev/null
+++ b/spec/rubyspec/.rubocop_todo.yml
@@ -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'
diff --git a/spec/rubyspec/.travis.yml b/spec/rubyspec/.travis.yml
index dd72c877f3..1a2e64ff84 100644
--- a/spec/rubyspec/.travis.yml
+++ b/spec/rubyspec/.travis.yml
@@ -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:
diff --git a/spec/rubyspec/command_line/dash_upper_s_spec.rb b/spec/rubyspec/command_line/dash_upper_s_spec.rb
index ce945895e4..2e293e9a62 100644
--- a/spec/rubyspec/command_line/dash_upper_s_spec.rb
+++ b/spec/rubyspec/command_line/dash_upper_s_spec.rb
@@ -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
diff --git a/spec/rubyspec/command_line/fixtures/bin/dash_s_fail b/spec/rubyspec/command_line/fixtures/bin/dash_s_fail
new file mode 100644
index 0000000000..70c1b8759c
--- /dev/null
+++ b/spec/rubyspec/command_line/fixtures/bin/dash_s_fail
@@ -0,0 +1 @@
+raise 'die'
diff --git a/spec/rubyspec/core/argf/binmode_spec.rb b/spec/rubyspec/core/argf/binmode_spec.rb
index 3daf4f4345..62202360e3 100644
--- a/spec/rubyspec/core/argf/binmode_spec.rb
+++ b/spec/rubyspec/core/argf/binmode_spec.rb
@@ -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
- 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
+ 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
end
diff --git a/spec/rubyspec/core/argf/fixtures/encoding.rb b/spec/rubyspec/core/argf/fixtures/encoding.rb
deleted file mode 100644
index 6e87e64346..0000000000
--- a/spec/rubyspec/core/argf/fixtures/encoding.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-ARGF.binmode
-puts ARGF.binmode?
-puts ARGF.gets.encoding
-ARGF.skip
-puts ARGF.read.encoding
diff --git a/spec/rubyspec/core/argf/set_encoding_spec.rb b/spec/rubyspec/core/argf/set_encoding_spec.rb
index 16d49a8c44..f6ec74ded1 100644
--- a/spec/rubyspec/core/argf/set_encoding_spec.rb
+++ b/spec/rubyspec/core/argf/set_encoding_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/array/element_set_spec.rb b/spec/rubyspec/core/array/element_set_spec.rb
index 280b507fc4..6544ad9b6f 100644
--- a/spec/rubyspec/core/array/element_set_spec.rb
+++ b/spec/rubyspec/core/array/element_set_spec.rb
@@ -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
-
diff --git a/spec/rubyspec/core/array/shared/inspect.rb b/spec/rubyspec/core/array/shared/inspect.rb
index 823dd40e7e..6a60781b45 100644
--- a/spec/rubyspec/core/array/shared/inspect.rb
+++ b/spec/rubyspec/core/array/shared/inspect.rb
@@ -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]"
diff --git a/spec/rubyspec/core/basicobject/equal_spec.rb b/spec/rubyspec/core/basicobject/equal_spec.rb
index 8142efa6bd..8120df836f 100644
--- a/spec/rubyspec/core/basicobject/equal_spec.rb
+++ b/spec/rubyspec/core/basicobject/equal_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/bignum/bignum_spec.rb b/spec/rubyspec/core/bignum/bignum_spec.rb
index b723718f69..cf99bb4937 100644
--- a/spec/rubyspec/core/bignum/bignum_spec.rb
+++ b/spec/rubyspec/core/bignum/bignum_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/enumerable/sum_spec.rb b/spec/rubyspec/core/enumerable/sum_spec.rb
new file mode 100644
index 0000000000..4881039a8d
--- /dev/null
+++ b/spec/rubyspec/core/enumerable/sum_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/enumerable/uniq_spec.rb b/spec/rubyspec/core/enumerable/uniq_spec.rb
new file mode 100644
index 0000000000..0ede0170ce
--- /dev/null
+++ b/spec/rubyspec/core/enumerable/uniq_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/enumerator/inspect_spec.rb b/spec/rubyspec/core/enumerator/inspect_spec.rb
index e89d3b7f3a..b708256247 100644
--- a/spec/rubyspec/core/enumerator/inspect_spec.rb
+++ b/spec/rubyspec/core/enumerator/inspect_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
index c5fbfcf1dd..372be80d61 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_spec.rb
@@ -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)
diff --git a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
index 06dd42213c..123cbae58c 100644
--- a/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
+++ b/spec/rubyspec/core/enumerator/lazy/grep_v_spec.rb
@@ -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)
diff --git a/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
new file mode 100644
index 0000000000..6220c7ba34
--- /dev/null
+++ b/spec/rubyspec/core/enumerator/lazy/uniq_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/false/falseclass_spec.rb b/spec/rubyspec/core/false/falseclass_spec.rb
new file mode 100644
index 0000000000..e91682c94c
--- /dev/null
+++ b/spec/rubyspec/core/false/falseclass_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/fixnum/bit_and_spec.rb b/spec/rubyspec/core/fixnum/bit_and_spec.rb
index ff0e597a52..9586075039 100644
--- a/spec/rubyspec/core/fixnum/bit_and_spec.rb
+++ b/spec/rubyspec/core/fixnum/bit_and_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/fixnum/fixnum_spec.rb b/spec/rubyspec/core/fixnum/fixnum_spec.rb
index d0af975c59..8a050fd25e 100644
--- a/spec/rubyspec/core/fixnum/fixnum_spec.rb
+++ b/spec/rubyspec/core/fixnum/fixnum_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/float/float_spec.rb b/spec/rubyspec/core/float/float_spec.rb
index e26e082a55..f2931d184c 100644
--- a/spec/rubyspec/core/float/float_spec.rb
+++ b/spec/rubyspec/core/float/float_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/float/shared/modulo.rb b/spec/rubyspec/core/float/shared/modulo.rb
index 9ac967389c..6c423a3a28 100644
--- a/spec/rubyspec/core/float/shared/modulo.rb
+++ b/spec/rubyspec/core/float/shared/modulo.rb
@@ -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)
diff --git a/spec/rubyspec/core/hash/shared/to_s.rb b/spec/rubyspec/core/hash/shared/to_s.rb
index 7ef2c207d4..0afe605826 100644
--- a/spec/rubyspec/core/hash/shared/to_s.rb
+++ b/spec/rubyspec/core/hash/shared/to_s.rb
@@ -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
diff --git a/spec/rubyspec/core/io/output_spec.rb b/spec/rubyspec/core/io/output_spec.rb
index ac3e781cee..2d52315430 100644
--- a/spec/rubyspec/core/io/output_spec.rb
+++ b/spec/rubyspec/core/io/output_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/io/popen_spec.rb b/spec/rubyspec/core/io/popen_spec.rb
index f24e61032f..45bb0e2cab 100644
--- a/spec/rubyspec/core/io/popen_spec.rb
+++ b/spec/rubyspec/core/io/popen_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/autoload_spec.rb b/spec/rubyspec/core/kernel/autoload_spec.rb
index 082903e92d..e2741de74c 100644
--- a/spec/rubyspec/core/kernel/autoload_spec.rb
+++ b/spec/rubyspec/core/kernel/autoload_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/caller_spec.rb b/spec/rubyspec/core/kernel/caller_spec.rb
index 94fbe3ab7e..d9be29a8db 100644
--- a/spec/rubyspec/core/kernel/caller_spec.rb
+++ b/spec/rubyspec/core/kernel/caller_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/chomp_spec.rb b/spec/rubyspec/core/kernel/chomp_spec.rb
index 4b34784169..524a4c8b1d 100644
--- a/spec/rubyspec/core/kernel/chomp_spec.rb
+++ b/spec/rubyspec/core/kernel/chomp_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/chop_spec.rb b/spec/rubyspec/core/kernel/chop_spec.rb
index 53b6e47cd1..5106fefee8 100644
--- a/spec/rubyspec/core/kernel/chop_spec.rb
+++ b/spec/rubyspec/core/kernel/chop_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/clone_spec.rb b/spec/rubyspec/core/kernel/clone_spec.rb
index 0e8216d434..48b3c24c7f 100644
--- a/spec/rubyspec/core/kernel/clone_spec.rb
+++ b/spec/rubyspec/core/kernel/clone_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/fixtures/classes.rb b/spec/rubyspec/core/kernel/fixtures/classes.rb
index c4a4d00485..afa2bec12f 100644
--- a/spec/rubyspec/core/kernel/fixtures/classes.rb
+++ b/spec/rubyspec/core/kernel/fixtures/classes.rb
@@ -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?
diff --git a/spec/rubyspec/core/kernel/public_method_spec.rb b/spec/rubyspec/core/kernel/public_method_spec.rb
index c4a29d9192..f1cc168420 100644
--- a/spec/rubyspec/core/kernel/public_method_spec.rb
+++ b/spec/rubyspec/core/kernel/public_method_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/kernel/singleton_method_spec.rb b/spec/rubyspec/core/kernel/singleton_method_spec.rb
new file mode 100644
index 0000000000..77022b40c2
--- /dev/null
+++ b/spec/rubyspec/core/kernel/singleton_method_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/marshal/dump_spec.rb b/spec/rubyspec/core/marshal/dump_spec.rb
index 6b369f9bb0..393b8a93f4 100644
--- a/spec/rubyspec/core/marshal/dump_spec.rb
+++ b/spec/rubyspec/core/marshal/dump_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/matchdata/named_captures_spec.rb b/spec/rubyspec/core/matchdata/named_captures_spec.rb
new file mode 100644
index 0000000000..1ab3152262
--- /dev/null
+++ b/spec/rubyspec/core/matchdata/named_captures_spec.rb
@@ -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 \ No newline at end of file
diff --git a/spec/rubyspec/core/matchdata/values_at_spec.rb b/spec/rubyspec/core/matchdata/values_at_spec.rb
index 8d786246f9..0b2727e001 100644
--- a/spec/rubyspec/core/matchdata/values_at_spec.rb
+++ b/spec/rubyspec/core/matchdata/values_at_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/module/autoload_spec.rb b/spec/rubyspec/core/module/autoload_spec.rb
index b479d049bb..9116ddf0a9 100644
--- a/spec/rubyspec/core/module/autoload_spec.rb
+++ b/spec/rubyspec/core/module/autoload_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/module/module_function_spec.rb b/spec/rubyspec/core/module/module_function_spec.rb
index 8ced48c505..61509c8d03 100644
--- a/spec/rubyspec/core/module/module_function_spec.rb
+++ b/spec/rubyspec/core/module/module_function_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/module/shared/set_visibility.rb b/spec/rubyspec/core/module/shared/set_visibility.rb
index 45eedc13fa..c39d59e05d 100644
--- a/spec/rubyspec/core/module/shared/set_visibility.rb
+++ b/spec/rubyspec/core/module/shared/set_visibility.rb
@@ -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
diff --git a/spec/rubyspec/core/nil/nilclass_spec.rb b/spec/rubyspec/core/nil/nilclass_spec.rb
new file mode 100644
index 0000000000..3f28cde0bd
--- /dev/null
+++ b/spec/rubyspec/core/nil/nilclass_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/numeric/shared/step.rb b/spec/rubyspec/core/numeric/shared/step.rb
index 6898a9ff3c..3072830534 100644
--- a/spec/rubyspec/core/numeric/shared/step.rb
+++ b/spec/rubyspec/core/numeric/shared/step.rb
@@ -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
diff --git a/spec/rubyspec/core/process/fixtures/common.rb b/spec/rubyspec/core/process/fixtures/common.rb
index 046efa5396..bdbf1e654b 100644
--- a/spec/rubyspec/core/process/fixtures/common.rb
+++ b/spec/rubyspec/core/process/fixtures/common.rb
@@ -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
diff --git a/spec/rubyspec/core/process/fixtures/env.rb b/spec/rubyspec/core/process/fixtures/env.rb
deleted file mode 100644
index 2d626caf26..0000000000
--- a/spec/rubyspec/core/process/fixtures/env.rb
+++ /dev/null
@@ -1 +0,0 @@
-File.write ARGV[0], ENV["FOO"]
diff --git a/spec/rubyspec/core/process/fixtures/print.rb b/spec/rubyspec/core/process/fixtures/print.rb
deleted file mode 100644
index 3697f7dc93..0000000000
--- a/spec/rubyspec/core/process/fixtures/print.rb
+++ /dev/null
@@ -1 +0,0 @@
-print :glark
diff --git a/spec/rubyspec/core/process/kill_spec.rb b/spec/rubyspec/core/process/kill_spec.rb
index c7b0e2a129..4316daf374 100644
--- a/spec/rubyspec/core/process/kill_spec.rb
+++ b/spec/rubyspec/core/process/kill_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/process/spawn_spec.rb b/spec/rubyspec/core/process/spawn_spec.rb
index 66b5c5e402..330ec8fcd8 100644
--- a/spec/rubyspec/core/process/spawn_spec.rb
+++ b/spec/rubyspec/core/process/spawn_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/process/wait_spec.rb b/spec/rubyspec/core/process/wait_spec.rb
index dca43140fd..8111621695 100644
--- a/spec/rubyspec/core/process/wait_spec.rb
+++ b/spec/rubyspec/core/process/wait_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/regexp/encoding_spec.rb b/spec/rubyspec/core/regexp/encoding_spec.rb
index 6ce1ada337..c30519c9d7 100644
--- a/spec/rubyspec/core/regexp/encoding_spec.rb
+++ b/spec/rubyspec/core/regexp/encoding_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/string/encoding_spec.rb b/spec/rubyspec/core/string/encoding_spec.rb
index a07032b041..9c655757a8 100644
--- a/spec/rubyspec/core/string/encoding_spec.rb
+++ b/spec/rubyspec/core/string/encoding_spec.rb
@@ -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?
diff --git a/spec/rubyspec/core/symbol/symbol_spec.rb b/spec/rubyspec/core/symbol/symbol_spec.rb
index bb95211ba0..af6b46fed3 100644
--- a/spec/rubyspec/core/symbol/symbol_spec.rb
+++ b/spec/rubyspec/core/symbol/symbol_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/time/dup_spec.rb b/spec/rubyspec/core/time/dup_spec.rb
index 16aab04200..b32ce96d44 100644
--- a/spec/rubyspec/core/time/dup_spec.rb
+++ b/spec/rubyspec/core/time/dup_spec.rb
@@ -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
diff --git a/spec/rubyspec/core/time/localtime_spec.rb b/spec/rubyspec/core/time/localtime_spec.rb
index 8144fd67e6..6f682b0b34 100644
--- a/spec/rubyspec/core/time/localtime_spec.rb
+++ b/spec/rubyspec/core/time/localtime_spec.rb
@@ -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')
diff --git a/spec/rubyspec/core/time/shared/gmtime.rb b/spec/rubyspec/core/time/shared/gmtime.rb
index a1b4b88418..e684a1fd95 100644
--- a/spec/rubyspec/core/time/shared/gmtime.rb
+++ b/spec/rubyspec/core/time/shared/gmtime.rb
@@ -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
diff --git a/spec/rubyspec/core/true/trueclass_spec.rb b/spec/rubyspec/core/true/trueclass_spec.rb
new file mode 100644
index 0000000000..8837117d71
--- /dev/null
+++ b/spec/rubyspec/core/true/trueclass_spec.rb
@@ -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
diff --git a/spec/rubyspec/language/predefined_spec.rb b/spec/rubyspec/language/predefined_spec.rb
index 6bbd2e216f..a0930eb214 100644
--- a/spec/rubyspec/language/predefined_spec.rb
+++ b/spec/rubyspec/language/predefined_spec.rb
@@ -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"]}
diff --git a/spec/rubyspec/library/bigdecimal/gt_spec.rb b/spec/rubyspec/library/bigdecimal/gt_spec.rb
index effd3ea35f..2f9ea4fd68 100644
--- a/spec/rubyspec/library/bigdecimal/gt_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/gt_spec.rb
@@ -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|
diff --git a/spec/rubyspec/library/bigdecimal/gte_spec.rb b/spec/rubyspec/library/bigdecimal/gte_spec.rb
index 28e84690ad..aab5338ad6 100644
--- a/spec/rubyspec/library/bigdecimal/gte_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/gte_spec.rb
@@ -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|
diff --git a/spec/rubyspec/library/bigdecimal/lt_spec.rb b/spec/rubyspec/library/bigdecimal/lt_spec.rb
index 67811c5db4..089e7aef73 100644
--- a/spec/rubyspec/library/bigdecimal/lt_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/lt_spec.rb
@@ -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|
diff --git a/spec/rubyspec/library/bigdecimal/lte_spec.rb b/spec/rubyspec/library/bigdecimal/lte_spec.rb
index 61fb676245..5cda9842bd 100644
--- a/spec/rubyspec/library/bigdecimal/lte_spec.rb
+++ b/spec/rubyspec/library/bigdecimal/lte_spec.rb
@@ -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|
diff --git a/spec/rubyspec/library/date/shared/jd.rb b/spec/rubyspec/library/date/shared/jd.rb
index e47dbae1b8..511557b4f7 100644
--- a/spec/rubyspec/library/date/shared/jd.rb
+++ b/spec/rubyspec/library/date/shared/jd.rb
@@ -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
diff --git a/spec/rubyspec/library/matrix/regular_spec.rb b/spec/rubyspec/library/matrix/regular_spec.rb
index a62a200d6d..2f0af99c1e 100644
--- a/spec/rubyspec/library/matrix/regular_spec.rb
+++ b/spec/rubyspec/library/matrix/regular_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/matrix/singular_spec.rb b/spec/rubyspec/library/matrix/singular_spec.rb
index 480621998f..83914befbe 100644
--- a/spec/rubyspec/library/matrix/singular_spec.rb
+++ b/spec/rubyspec/library/matrix/singular_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/net/ftp/fixtures/server.rb b/spec/rubyspec/library/net/ftp/fixtures/server.rb
index 2129835883..a6741820ff 100644
--- a/spec/rubyspec/library/net/ftp/fixtures/server.rb
+++ b/spec/rubyspec/library/net/ftp/fixtures/server.rb
@@ -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"
diff --git a/spec/rubyspec/library/rexml/element/add_attribute_spec.rb b/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
index 74eceee99b..998f5d6251 100644
--- a/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
+++ b/spec/rubyspec/library/rexml/element/add_attribute_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/rexml/text/wrap_spec.rb b/spec/rubyspec/library/rexml/text/wrap_spec.rb
index 9491e47fc8..a56759b0f4 100644
--- a/spec/rubyspec/library/rexml/text/wrap_spec.rb
+++ b/spec/rubyspec/library/rexml/text/wrap_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/securerandom/random_number_spec.rb b/spec/rubyspec/library/securerandom/random_number_spec.rb
index 296da51be2..a23a457df2 100644
--- a/spec/rubyspec/library/securerandom/random_number_spec.rb
+++ b/spec/rubyspec/library/securerandom/random_number_spec.rb
@@ -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 = []
diff --git a/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb b/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
index 8f8616bd2b..cb3a45eb5f 100644
--- a/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
+++ b/spec/rubyspec/library/socket/basicsocket/getsockname_spec.rb
@@ -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)
diff --git a/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb b/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
index fd92c0740c..26bceabb51 100644
--- a/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
+++ b/spec/rubyspec/library/socket/socket/connect_nonblock_spec.rb
@@ -14,6 +14,7 @@ describe "Socket#connect_nonblock" do
after :each do
@socket.close
+ @server.close
@thread.join if @thread
end
diff --git a/spec/rubyspec/library/stringio/printf_spec.rb b/spec/rubyspec/library/stringio/printf_spec.rb
index 0309480a9a..5f811547bc 100644
--- a/spec/rubyspec/library/stringio/printf_spec.rb
+++ b/spec/rubyspec/library/stringio/printf_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/stringscanner/shared/matched_size.rb b/spec/rubyspec/library/stringscanner/shared/matched_size.rb
index 0d783dc92b..92174733f7 100644
--- a/spec/rubyspec/library/stringscanner/shared/matched_size.rb
+++ b/spec/rubyspec/library/stringscanner/shared/matched_size.rb
@@ -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
diff --git a/spec/rubyspec/library/zlib/deflate/params_spec.rb b/spec/rubyspec/library/zlib/deflate/params_spec.rb
index bb2fd3ee7c..59b1353c07 100644
--- a/spec/rubyspec/library/zlib/deflate/params_spec.rb
+++ b/spec/rubyspec/library/zlib/deflate/params_spec.rb
@@ -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
-
diff --git a/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb b/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
index 6a4c1dadb4..d49adc2850 100644
--- a/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipreader/gets_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb b/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb
new file mode 100644
index 0000000000..2cdef54fd1
--- /dev/null
+++ b/spec/rubyspec/library/zlib/gzipreader/readpartial_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb
new file mode 100644
index 0000000000..16f1c12272
--- /dev/null
+++ b/spec/rubyspec/library/zlib/gzipreader/ungetbyte_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb b/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
index 6a4c1dadb4..2d218e8d19 100644
--- a/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipreader/ungetc_spec.rb
@@ -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
diff --git a/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb b/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
index f73d6e3226..af7a4ac735 100644
--- a/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
+++ b/spec/rubyspec/library/zlib/gzipwriter/mtime_spec.rb
@@ -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
-
diff --git a/spec/rubyspec/optional/capi/bignum_spec.rb b/spec/rubyspec/optional/capi/bignum_spec.rb
index 59d867cc46..a5d5995dc0 100644
--- a/spec/rubyspec/optional/capi/bignum_spec.rb
+++ b/spec/rubyspec/optional/capi/bignum_spec.rb
@@ -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
diff --git a/spec/rubyspec/optional/capi/kernel_spec.rb b/spec/rubyspec/optional/capi/kernel_spec.rb
index ccb125be0d..47f368b517 100644
--- a/spec/rubyspec/optional/capi/kernel_spec.rb
+++ b/spec/rubyspec/optional/capi/kernel_spec.rb
@@ -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