summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:23 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-27 18:53:23 +0200
commita1b4816759418ca8fe510e8739622fc5d77ab0f0 (patch)
tree9d4fb6091d0086817f5bde46bf1150e9130d34fd /spec
parent00c33d9c232ed1a79eda17acd7231ac93caa162b (diff)
Update to ruby/spec@15c9619
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/.travis.yml20
-rw-r--r--spec/ruby/CONTRIBUTING.md14
-rw-r--r--spec/ruby/README.md5
-rw-r--r--spec/ruby/command_line/feature_spec.rb9
-rw-r--r--spec/ruby/core/array/concat_spec.rb34
-rw-r--r--spec/ruby/core/array/max_spec.rb6
-rw-r--r--spec/ruby/core/array/min_spec.rb6
-rw-r--r--spec/ruby/core/array/pack/buffer_spec.rb72
-rw-r--r--spec/ruby/core/array/reject_spec.rb24
-rw-r--r--spec/ruby/core/array/sum_spec.rb78
-rw-r--r--spec/ruby/core/basicobject/basicobject_spec.rb6
-rw-r--r--spec/ruby/core/comparable/clamp_spec.rb88
-rw-r--r--spec/ruby/core/complex/finite_spec.rb50
-rw-r--r--spec/ruby/core/complex/infinite_spec.rb48
-rw-r--r--spec/ruby/core/dir/empty_spec.rb46
-rw-r--r--spec/ruby/core/enumerable/chunk_spec.rb20
-rw-r--r--spec/ruby/core/enumerable/sum_spec.rb38
-rw-r--r--spec/ruby/core/enumerable/uniq_spec.rb134
-rw-r--r--spec/ruby/core/enumerator/lazy/chunk_spec.rb20
-rw-r--r--spec/ruby/core/enumerator/lazy/lazy_spec.rb4
-rw-r--r--spec/ruby/core/enumerator/lazy/select_spec.rb39
-rw-r--r--spec/ruby/core/enumerator/lazy/uniq_spec.rb114
-rw-r--r--spec/ruby/core/env/fetch_spec.rb6
-rw-r--r--spec/ruby/core/false/dup_spec.rb8
-rw-r--r--spec/ruby/core/fiber/resume_spec.rb2
-rw-r--r--spec/ruby/core/file/empty_spec.rb12
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb16
-rw-r--r--spec/ruby/core/file/mtime_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/dev_major_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/dev_minor_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/rdev_major_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/rdev_minor_spec.rb8
-rw-r--r--spec/ruby/core/file/utime_spec.rb24
-rw-r--r--spec/ruby/core/float/ceil_spec.rb14
-rw-r--r--spec/ruby/core/float/dup_spec.rb10
-rw-r--r--spec/ruby/core/float/floor_spec.rb14
-rw-r--r--spec/ruby/core/float/round_spec.rb42
-rw-r--r--spec/ruby/core/float/truncate_spec.rb14
-rw-r--r--spec/ruby/core/hash/compact_spec.rb84
-rw-r--r--spec/ruby/core/hash/compare_by_identity_spec.rb12
-rw-r--r--spec/ruby/core/hash/fetch_spec.rb6
-rw-r--r--spec/ruby/core/hash/merge_spec.rb7
-rw-r--r--spec/ruby/core/hash/shared/each.rb2
-rw-r--r--spec/ruby/core/hash/transform_values_spec.rb146
-rw-r--r--spec/ruby/core/integer/ceil_spec.rb18
-rw-r--r--spec/ruby/core/integer/coerce_spec.rb40
-rw-r--r--spec/ruby/core/integer/digits_spec.rb46
-rw-r--r--spec/ruby/core/integer/dup_spec.rb18
-rw-r--r--spec/ruby/core/integer/floor_spec.rb18
-rw-r--r--spec/ruby/core/integer/integer_spec.rb8
-rw-r--r--spec/ruby/core/integer/pow_spec.rb12
-rw-r--r--spec/ruby/core/integer/round_spec.rb22
-rw-r--r--spec/ruby/core/integer/shared/integer_rounding.rb8
-rw-r--r--spec/ruby/core/integer/truncate_spec.rb18
-rw-r--r--spec/ruby/core/io/gets_spec.rb8
-rw-r--r--spec/ruby/core/io/readline_spec.rb8
-rw-r--r--spec/ruby/core/io/shared/each.rb10
-rw-r--r--spec/ruby/core/io/shared/readlines.rb8
-rw-r--r--spec/ruby/core/kernel/Complex_spec.rb12
-rw-r--r--spec/ruby/core/kernel/Integer_spec.rb16
-rw-r--r--spec/ruby/core/kernel/clone_spec.rb14
-rw-r--r--spec/ruby/core/kernel/shared/dup_clone.rb50
-rw-r--r--spec/ruby/core/kernel/shared/require.rb9
-rw-r--r--spec/ruby/core/kernel/warn_spec.rb14
-rw-r--r--spec/ruby/core/matchdata/named_captures_spec.rb20
-rw-r--r--spec/ruby/core/matchdata/values_at_spec.rb12
-rw-r--r--spec/ruby/core/math/lgamma_spec.rb6
-rw-r--r--spec/ruby/core/method/parameters_spec.rb18
-rw-r--r--spec/ruby/core/module/include_spec.rb24
-rw-r--r--spec/ruby/core/module/prepend_spec.rb24
-rw-r--r--spec/ruby/core/module/private_spec.rb56
-rw-r--r--spec/ruby/core/module/refine_spec.rb144
-rw-r--r--spec/ruby/core/nil/dup_spec.rb8
-rw-r--r--spec/ruby/core/numeric/finite_spec.rb10
-rw-r--r--spec/ruby/core/numeric/infinite_spec.rb10
-rw-r--r--spec/ruby/core/numeric/shared/step.rb6
-rw-r--r--spec/ruby/core/objectspace/each_object_spec.rb1
-rw-r--r--spec/ruby/core/proc/element_reference_spec.rb14
-rw-r--r--spec/ruby/core/process/clock_getres_spec.rb55
-rw-r--r--spec/ruby/core/process/clock_gettime_spec.rb22
-rw-r--r--spec/ruby/core/process/fixtures/clocks.rb24
-rw-r--r--spec/ruby/core/process/wait2_spec.rb6
-rw-r--r--spec/ruby/core/process/wait_spec.rb6
-rw-r--r--spec/ruby/core/rational/round_spec.rb1
-rw-r--r--spec/ruby/core/regexp/match_spec.rb40
-rw-r--r--spec/ruby/core/string/capitalize_spec.rb212
-rw-r--r--spec/ruby/core/string/casecmp_spec.rb126
-rw-r--r--spec/ruby/core/string/concat_spec.rb30
-rw-r--r--spec/ruby/core/string/downcase_spec.rb214
-rw-r--r--spec/ruby/core/string/dump_spec.rb105
-rw-r--r--spec/ruby/core/string/lines_spec.rb10
-rw-r--r--spec/ruby/core/string/match_spec.rb34
-rw-r--r--spec/ruby/core/string/new_spec.rb8
-rw-r--r--spec/ruby/core/string/prepend_spec.rb30
-rw-r--r--spec/ruby/core/string/shared/each_line.rb48
-rw-r--r--spec/ruby/core/string/split_spec.rb60
-rw-r--r--spec/ruby/core/string/swapcase_spec.rb196
-rw-r--r--spec/ruby/core/string/to_f_spec.rb1
-rw-r--r--spec/ruby/core/string/unpack1_spec.rb14
-rw-r--r--spec/ruby/core/string/upcase_spec.rb200
-rw-r--r--spec/ruby/core/symbol/capitalize_spec.rb21
-rw-r--r--spec/ruby/core/symbol/casecmp_spec.rb136
-rw-r--r--spec/ruby/core/symbol/downcase_spec.rb14
-rw-r--r--spec/ruby/core/symbol/dup_spec.rb8
-rw-r--r--spec/ruby/core/symbol/match_spec.rb64
-rw-r--r--spec/ruby/core/symbol/swapcase_spec.rb18
-rw-r--r--spec/ruby/core/symbol/upcase_spec.rb14
-rw-r--r--spec/ruby/core/thread/report_on_exception_spec.rb182
-rw-r--r--spec/ruby/core/time/shared/now.rb15
-rw-r--r--spec/ruby/core/tracepoint/callee_id_spec.rb22
-rw-r--r--spec/ruby/core/tracepoint/disable_spec.rb20
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb56
-rw-r--r--spec/ruby/core/tracepoint/instruction_sequence_spec.rb25
-rw-r--r--spec/ruby/core/tracepoint/new_spec.rb2
-rw-r--r--spec/ruby/core/true/dup_spec.rb8
-rw-r--r--spec/ruby/core/warning/warn_spec.rb84
-rw-r--r--spec/ruby/default.mspec12
-rw-r--r--spec/ruby/language/block_spec.rb24
-rw-r--r--spec/ruby/language/constants_spec.rb4
-rw-r--r--spec/ruby/language/defined_spec.rb6
-rw-r--r--spec/ruby/language/fixtures/block.rb4
-rw-r--r--spec/ruby/language/fixtures/yield.rb4
-rw-r--r--spec/ruby/language/if_spec.rb28
-rw-r--r--spec/ruby/language/lambda_spec.rb17
-rw-r--r--spec/ruby/language/predefined_spec.rb47
-rw-r--r--spec/ruby/language/regexp/character_classes_spec.rb30
-rw-r--r--spec/ruby/language/regexp/modifiers_spec.rb8
-rw-r--r--spec/ruby/language/regexp/repetition_spec.rb17
-rw-r--r--spec/ruby/language/regexp_spec.rb30
-rw-r--r--spec/ruby/language/rescue_spec.rb20
-rw-r--r--spec/ruby/language/return_spec.rb2
-rw-r--r--spec/ruby/language/yield_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb15
-rw-r--r--spec/ruby/library/bigdecimal/gt_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/gte_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/inspect_spec.rb34
-rw-r--r--spec/ruby/library/bigdecimal/lt_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/lte_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/round_spec.rb242
-rw-r--r--spec/ruby/library/bigdecimal/to_s_spec.rb12
-rw-r--r--spec/ruby/library/cgi/cookie/parse_spec.rb25
-rw-r--r--spec/ruby/library/conditionvariable/wait_spec.rb9
-rw-r--r--spec/ruby/library/coverage/fixtures/spec_helper.rb11
-rw-r--r--spec/ruby/library/coverage/peek_result_spec.rb1
-rw-r--r--spec/ruby/library/coverage/result_spec.rb15
-rw-r--r--spec/ruby/library/csv/liberal_parsing_spec.rb26
-rw-r--r--spec/ruby/library/csv/parse_spec.rb10
-rw-r--r--spec/ruby/library/csv/readlines_spec.rb12
-rw-r--r--spec/ruby/library/datetime/now_spec.rb4
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb24
-rw-r--r--spec/ruby/library/ipaddr/operator_spec.rb8
-rw-r--r--spec/ruby/library/logger/logger/new_spec.rb78
-rw-r--r--spec/ruby/library/net/ftp/initialize_spec.rb424
-rw-r--r--spec/ruby/library/net/ftp/status_spec.rb6
-rw-r--r--spec/ruby/library/net/http/http/post_spec.rb56
-rw-r--r--spec/ruby/library/optionparser/order_spec.rb36
-rw-r--r--spec/ruby/library/optionparser/parse_spec.rb36
-rw-r--r--spec/ruby/library/pathname/empty_spec.rb46
-rw-r--r--spec/ruby/library/rbconfig/rbconfig_spec.rb10
-rw-r--r--spec/ruby/library/rexml/element/element_reference_spec.rb14
-rw-r--r--spec/ruby/library/set/compare_by_identity_spec.rb268
-rw-r--r--spec/ruby/library/shellwords/shellwords_spec.rb8
-rw-r--r--spec/ruby/library/socket/fixtures/classes.rb8
-rw-r--r--spec/ruby/library/stringio/each_line_spec.rb6
-rw-r--r--spec/ruby/library/stringio/each_spec.rb6
-rw-r--r--spec/ruby/library/stringio/gets_spec.rb10
-rw-r--r--spec/ruby/library/stringio/lines_spec.rb6
-rw-r--r--spec/ruby/library/stringio/readline_spec.rb10
-rw-r--r--spec/ruby/library/stringio/readlines_spec.rb10
-rw-r--r--spec/ruby/library/stringscanner/scan_spec.rb16
-rw-r--r--spec/ruby/library/time/to_time_spec.rb18
-rw-r--r--spec/ruby/library/timeout/timeout_spec.rb15
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb8
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetc_spec.rb32
-rw-r--r--spec/ruby/optional/capi/class_spec.rb10
-rw-r--r--spec/ruby/optional/capi/constants_spec.rb12
-rw-r--r--spec/ruby/optional/capi/data_spec.rb4
-rw-r--r--spec/ruby/optional/capi/ext/io_spec.c11
-rw-r--r--spec/ruby/optional/capi/ext/kernel_spec.c1
-rw-r--r--spec/ruby/optional/capi/ext/object_spec.c12
-rw-r--r--spec/ruby/optional/capi/ext/string_spec.c5
-rw-r--r--spec/ruby/optional/capi/io_spec.rb20
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb9
-rw-r--r--spec/ruby/optional/capi/object_spec.rb23
-rw-r--r--spec/ruby/optional/capi/string_spec.rb25
-rw-r--r--spec/ruby/optional/capi/struct_spec.rb8
-rw-r--r--spec/ruby/optional/capi/thread_spec.rb2
-rw-r--r--spec/ruby/optional/capi/time_spec.rb2
-rw-r--r--spec/ruby/optional/capi/util_spec.rb5
-rw-r--r--spec/ruby/security/cve_2011_4815_spec.rb4
-rw-r--r--spec/ruby/security/cve_2018_8780_spec.rb10
-rw-r--r--spec/ruby/shared/rational/Rational.rb10
-rw-r--r--spec/ruby/shared/rational/round.rb49
193 files changed, 2969 insertions, 3330 deletions
diff --git a/spec/ruby/.travis.yml b/spec/ruby/.travis.yml
index 11bd7a55fd..467a5e9f68 100644
--- a/spec/ruby/.travis.yml
+++ b/spec/ruby/.travis.yml
@@ -3,20 +3,18 @@ language: ruby
install:
- git clone https://github.com/ruby/mspec.git ../mspec
script:
- - ../mspec/bin/mspec $MSPEC_OPTS
+ - CHECK_LEAKS=true ../mspec/bin/mspec
matrix:
include:
+ - name: Running each spec twice
+ rvm: 2.5.5
+ script:
+ - CHECK_LEAKS=true ../mspec/bin/mspec -R2 -ff
+ - rvm: 2.4.6
- rvm: 2.5.5
- env: MSPEC_OPTS="-R2 -ff"
- - rvm: 2.3.8
- - rvm: 2.4.5
- env: CHECK_LEAKS=true
- - rvm: 2.5.5
- env: CHECK_LEAKS=true
- - rvm: 2.6.2
- env: CHECK_LEAKS=true
- - env: RUBOCOP=true
- rvm: 2.4.5
+ - rvm: 2.6.3
+ - name: RuboCop Lint Checks
+ rvm: 2.4.6
script:
- gem install rubocop:0.61.0
- rubocop
diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md
index 7c9363da37..dd33f7bf4f 100644
--- a/spec/ruby/CONTRIBUTING.md
+++ b/spec/ruby/CONTRIBUTING.md
@@ -144,11 +144,11 @@ end
# Combining guards
-guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
- # Windows and RUBY_VERSION < 2.3
+guard -> { platform_is :windows and ruby_version_is ""..."2.5" } do
+ # Windows and RUBY_VERSION < 2.5
end
-guard_not -> { platform_is :windows and ruby_version_is ""..."2.3" } do
+guard_not -> { platform_is :windows and ruby_version_is ""..."2.5" } do
# The opposite
end
@@ -170,20 +170,20 @@ If an implementation does not support some feature, simply tag the related specs
### Shared Specs
-Often throughout Ruby, identical functionality is used by different methods and modules. In order
+Often throughout Ruby, identical functionality is used by different methods and modules. In order
to avoid duplication of specs, we have shared specs that are re-used in other specs. The use is a
bit tricky however, so let's go over it.
Commonly, if a shared spec is only reused within its own module, the shared spec will live within a
-shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
+shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
only used by `Hash` specs, and so it lives inside `core/hash/shared/`.
When a shared spec is used across multiple modules or classes, it lives within the `shared/` directory.
-An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
+An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
`core/filetest/socket_spec.rb`, and `core/file/state/socket_spec.rb` and so it lives in the root `shared/`.
Defining a shared spec involves adding a `shared: true` option to the top-level `describe` block. This
-will signal not to run the specs directly by the runner. Shared specs have access to two instance
+will signal not to run the specs directly by the runner. Shared specs have access to two instance
variables from the implementor spec: `@method` and `@object`, which the implementor spec will pass in.
Here's an example of a snippet of a shared spec and two specs which integrates it:
diff --git a/spec/ruby/README.md b/spec/ruby/README.md
index 7cb9adaeda..980eaf034f 100644
--- a/spec/ruby/README.md
+++ b/spec/ruby/README.md
@@ -28,8 +28,8 @@ ruby/spec is known to be tested in these implementations for every commit:
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)
-ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
-More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.3.x, 2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
+ruby/spec describes the behavior of Ruby 2.4 and more recent Ruby versions.
+More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
@@ -49,6 +49,7 @@ For older specs try these commits:
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed)
* Ruby 2.2.10 - [Suite](https://github.com/ruby/spec/commit/cbaa0e412270c944df0c2532fc500c920dba0e92) using [MSpec](https://github.com/ruby/mspec/commit/d84d7668449e96856c5f6bac8cb1526b6d357ce3)
+* Ruby 2.3.8 - [Suite](https://github.com/ruby/spec/commit/dc733114d8ae66a3368ba3a98422c50147a76ba5) using [MSpec](https://github.com/ruby/mspec/commit/4599bc195fb109f2a482a01c32a7d659518369ea)
### Running the specs
diff --git a/spec/ruby/command_line/feature_spec.rb b/spec/ruby/command_line/feature_spec.rb
index 2025768b41..02571ee8c6 100644
--- a/spec/ruby/command_line/feature_spec.rb
+++ b/spec/ruby/command_line/feature_spec.rb
@@ -37,15 +37,6 @@ describe "The --enable and --disable flags" do
ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false"
end
- ruby_version_is "2.6" do
- it "can be used with jit" do
- ruby_exe("p :OK", options: "--enable=jit 2>&1").chomp.should == ":OK"
- ruby_exe("p :OK", options: "--disable=jit 2>&1").chomp.should == ":OK"
- ruby_exe("p :OK", options: "--enable-jit 2>&1").chomp.should == ":OK"
- ruby_exe("p :OK", options: "--disable-jit 2>&1").chomp.should == ":OK"
- end
- end
-
it "can be used with all" do
e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
env = {'RUBYOPT' => '-w'}
diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb
index 985c5d884a..91adb8b745 100644
--- a/spec/ruby/core/array/concat_spec.rb
+++ b/spec/ruby/core/array/concat_spec.rb
@@ -110,23 +110,21 @@ describe "Array#concat" do
ary.concat([5, 6]).should == [4, 5, 6]
end
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- ary = [1, 2]
- ary.concat [3, 4]
- ary.should == [1, 2, 3, 4]
- end
-
- it "concatenates the initial value when given arguments contain 2 self" do
- ary = [1, 2]
- ary.concat ary, ary
- ary.should == [1, 2, 1, 2, 1, 2]
- end
-
- it "returns self when given no arguments" do
- ary = [1, 2]
- ary.concat.should equal(ary)
- ary.should == [1, 2]
- end
+ it "takes multiple arguments" do
+ ary = [1, 2]
+ ary.concat [3, 4]
+ ary.should == [1, 2, 3, 4]
+ end
+
+ it "concatenates the initial value when given arguments contain 2 self" do
+ ary = [1, 2]
+ ary.concat ary, ary
+ ary.should == [1, 2, 1, 2, 1, 2]
+ end
+
+ it "returns self when given no arguments" do
+ ary = [1, 2]
+ ary.concat.should equal(ary)
+ ary.should == [1, 2]
end
end
diff --git a/spec/ruby/core/array/max_spec.rb b/spec/ruby/core/array/max_spec.rb
index 5d0423d1e4..329b691883 100644
--- a/spec/ruby/core/array/max_spec.rb
+++ b/spec/ruby/core/array/max_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
describe "Array#max" do
- ruby_version_is "2.4" do
- it "is defined on Array" do
- [1].method(:max).owner.should equal Array
- end
+ it "is defined on Array" do
+ [1].method(:max).owner.should equal Array
end
it "returns nil with no values" do
diff --git a/spec/ruby/core/array/min_spec.rb b/spec/ruby/core/array/min_spec.rb
index 903fa69bb8..22a179d808 100644
--- a/spec/ruby/core/array/min_spec.rb
+++ b/spec/ruby/core/array/min_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
describe "Array#min" do
- ruby_version_is "2.4" do
- it "is defined on Array" do
- [1].method(:max).owner.should equal Array
- end
+ it "is defined on Array" do
+ [1].method(:max).owner.should equal Array
end
it "returns nil with no values" do
diff --git a/spec/ruby/core/array/pack/buffer_spec.rb b/spec/ruby/core/array/pack/buffer_spec.rb
index f2dc3e1930..28b317eacb 100644
--- a/spec/ruby/core/array/pack/buffer_spec.rb
+++ b/spec/ruby/core/array/pack/buffer_spec.rb
@@ -2,51 +2,49 @@
require_relative '../../../spec_helper'
-ruby_version_is '2.4' do
- describe "Array#pack with :buffer option" do
- it "returns specified buffer" do
- n = [ 65, 66, 67 ]
- buffer = " "*3
- result = n.pack("ccc", buffer: buffer) #=> "ABC"
- result.should equal(buffer)
- end
+describe "Array#pack with :buffer option" do
+ it "returns specified buffer" do
+ n = [ 65, 66, 67 ]
+ buffer = " "*3
+ result = n.pack("ccc", buffer: buffer) #=> "ABC"
+ result.should equal(buffer)
+ end
- it "adds result at the end of buffer content" do
- n = [ 65, 66, 67 ] # result without buffer is "ABC"
+ it "adds result at the end of buffer content" do
+ n = [ 65, 66, 67 ] # result without buffer is "ABC"
- buffer = ""
- n.pack("ccc", buffer: buffer).should == "ABC"
+ buffer = ""
+ n.pack("ccc", buffer: buffer).should == "ABC"
- buffer = "123"
- n.pack("ccc", buffer: buffer).should == "123ABC"
+ buffer = "123"
+ n.pack("ccc", buffer: buffer).should == "123ABC"
+
+ buffer = "12345"
+ n.pack("ccc", buffer: buffer).should == "12345ABC"
+ end
- buffer = "12345"
- n.pack("ccc", buffer: buffer).should == "12345ABC"
+ it "raises TypeError exception if buffer is not String" do
+ lambda { [65].pack("ccc", buffer: []) }.should raise_error(
+ TypeError, "buffer must be String, not Array")
+ end
+
+ context "offset (@) is specified" do
+ it 'keeps buffer content if it is longer than offset' do
+ n = [ 65, 66, 67 ]
+ buffer = "123456"
+ n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
- it "raises TypeError exception if buffer is not String" do
- lambda { [65].pack("ccc", buffer: []) }.should raise_error(
- TypeError, "buffer must be String, not Array")
+ it "fills the gap with \\0 if buffer content is shorter than offset" do
+ n = [ 65, 66, 67 ]
+ buffer = "123"
+ n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
end
- context "offset (@) is specified" do
- it 'keeps buffer content if it is longer than offset' do
- n = [ 65, 66, 67 ]
- buffer = "123456"
- n.pack("@3ccc", buffer: buffer).should == "123ABC"
- end
-
- it "fills the gap with \\0 if buffer content is shorter than offset" do
- n = [ 65, 66, 67 ]
- buffer = "123"
- n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
- end
-
- it 'does not keep buffer content if it is longer than offset + result' do
- n = [ 65, 66, 67 ]
- buffer = "1234567890"
- n.pack("@3ccc", buffer: buffer).should == "123ABC"
- end
+ it 'does not keep buffer content if it is longer than offset + result' do
+ n = [ 65, 66, 67 ]
+ buffer = "1234567890"
+ n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
end
end
diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb
index 8bce7ad3bf..6ae2581ff5 100644
--- a/spec/ruby/core/array/reject_spec.rb
+++ b/spec/ruby/core/array/reject_spec.rb
@@ -121,22 +121,20 @@ describe "Array#reject!" do
a.should == [1, 2, 3]
end
- ruby_version_is "2.4" do
- it "only removes elements for which the block returns true, keeping the element which raised an error." do
- a = [1, 2, 3, 4]
- begin
- a.reject! do |x|
- case x
- when 2 then true
- when 3 then raise StandardError, 'Oops'
- else false
- end
+ it "only removes elements for which the block returns true, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.reject! do |x|
+ case x
+ when 2 then true
+ when 3 then raise StandardError, 'Oops'
+ else false
end
- rescue StandardError
end
-
- a.should == [1, 3, 4]
+ rescue StandardError
end
+
+ a.should == [1, 3, 4]
end
it_behaves_like :enumeratorize, :reject!
diff --git a/spec/ruby/core/array/sum_spec.rb b/spec/ruby/core/array/sum_spec.rb
index 7d19c03480..a7e77d8c2e 100644
--- a/spec/ruby/core/array/sum_spec.rb
+++ b/spec/ruby/core/array/sum_spec.rb
@@ -1,44 +1,42 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Array#sum" do
- it "returns the sum of elements" do
- [1, 2, 3].sum.should == 6
- end
-
- it "applies a block to each element before adding if it's given" do
- [1, 2, 3].sum { |i| i * 10 }.should == 60
- end
-
- it "returns init value if array is empty" do
- [].sum(-1).should == -1
- end
-
- it "returns 0 if array is empty and init is omitted" do
- [].sum.should == 0
- end
-
- it "adds init value to the sum of elements" do
- [1, 2, 3].sum(10).should == 16
- end
-
- it "can be used for non-numeric objects by providing init value" do
- ["a", "b", "c"].sum("").should == "abc"
- end
-
- it 'raises TypeError if any element are not numeric' do
- lambda { ["a"].sum }.should raise_error(TypeError)
- end
-
- it 'raises TypeError if any element cannot be added to init value' do
- lambda { [1].sum([]) }.should raise_error(TypeError)
- end
-
- it "calls + to sum the elements" do
- a = mock("a")
- b = mock("b")
- a.should_receive(:+).with(b).and_return(42)
- [b].sum(a).should == 42
- end
+describe "Array#sum" do
+ it "returns the sum of elements" do
+ [1, 2, 3].sum.should == 6
+ end
+
+ it "applies a block to each element before adding if it's given" do
+ [1, 2, 3].sum { |i| i * 10 }.should == 60
+ end
+
+ it "returns init value if array is empty" do
+ [].sum(-1).should == -1
+ end
+
+ it "returns 0 if array is empty and init is omitted" do
+ [].sum.should == 0
+ end
+
+ it "adds init value to the sum of elements" do
+ [1, 2, 3].sum(10).should == 16
+ end
+
+ it "can be used for non-numeric objects by providing init value" do
+ ["a", "b", "c"].sum("").should == "abc"
+ end
+
+ it 'raises TypeError if any element are not numeric' do
+ lambda { ["a"].sum }.should raise_error(TypeError)
+ end
+
+ it 'raises TypeError if any element cannot be added to init value' do
+ lambda { [1].sum([]) }.should raise_error(TypeError)
+ end
+
+ it "calls + to sum the elements" do
+ a = mock("a")
+ b = mock("b")
+ a.should_receive(:+).with(b).and_return(42)
+ [b].sum(a).should == 42
end
end
diff --git a/spec/ruby/core/basicobject/basicobject_spec.rb b/spec/ruby/core/basicobject/basicobject_spec.rb
index 860ad93e89..ccaa9c8593 100644
--- a/spec/ruby/core/basicobject/basicobject_spec.rb
+++ b/spec/ruby/core/basicobject/basicobject_spec.rb
@@ -19,8 +19,12 @@ describe "BasicObject" do
BasicObjectSpecs::BOSubclass.kernel_defined?.should be_nil
end
+ it "is included in Object's list of constants" do
+ Object.constants(false).should include(:BasicObject)
+ end
+
it "includes itself in its list of constants" do
- BasicObject.constants.should include(:BasicObject)
+ BasicObject.constants(false).should include(:BasicObject)
end
end
diff --git a/spec/ruby/core/comparable/clamp_spec.rb b/spec/ruby/core/comparable/clamp_spec.rb
index eb6a0838b9..d3f1022499 100644
--- a/spec/ruby/core/comparable/clamp_spec.rb
+++ b/spec/ruby/core/comparable/clamp_spec.rb
@@ -1,50 +1,48 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe 'Comparable#clamp' do
- it 'raises an Argument error unless given 2 parameters' do
- c = ComparableSpecs::Weird.new(0)
- lambda { c.clamp(c) }.should raise_error(ArgumentError)
- lambda { c.clamp(c, c, c) }.should raise_error(ArgumentError)
- end
-
- it 'raises an Argument error unless the 2 parameters are correctly ordered' do
- one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(3)
-
- lambda { c.clamp(two, one) }.should raise_error(ArgumentError)
- one.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { c.clamp(one, two) }.should raise_error(ArgumentError)
- end
-
- it 'returns self if within the given parameters' do
- one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- three = ComparableSpecs::WithOnlyCompareDefined.new(3)
- c = ComparableSpecs::Weird.new(2)
-
- c.clamp(one, two).should equal(c)
- c.clamp(two, two).should equal(c)
- c.clamp(one, three).should equal(c)
- c.clamp(two, three).should equal(c)
- end
-
- it 'returns the min parameter if smaller than it' do
- one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(0)
-
- c.clamp(one, two).should equal(one)
- end
-
- it 'returns the max parameter if greater than it' do
- one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(3)
-
- c.clamp(one, two).should equal(two)
- end
+describe 'Comparable#clamp' do
+ it 'raises an Argument error unless given 2 parameters' do
+ c = ComparableSpecs::Weird.new(0)
+ lambda { c.clamp(c) }.should raise_error(ArgumentError)
+ lambda { c.clamp(c, c, c) }.should raise_error(ArgumentError)
+ end
+
+ it 'raises an Argument error unless the 2 parameters are correctly ordered' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ lambda { c.clamp(two, one) }.should raise_error(ArgumentError)
+ one.should_receive(:<=>).any_number_of_times.and_return(nil)
+ lambda { c.clamp(one, two) }.should raise_error(ArgumentError)
+ end
+
+ it 'returns self if within the given parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ three = ComparableSpecs::WithOnlyCompareDefined.new(3)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one, two).should equal(c)
+ c.clamp(two, two).should equal(c)
+ c.clamp(one, three).should equal(c)
+ c.clamp(two, three).should equal(c)
+ end
+
+ it 'returns the min parameter if smaller than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one, two).should equal(one)
+ end
+
+ it 'returns the max parameter if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ c.clamp(one, two).should equal(two)
end
end
diff --git a/spec/ruby/core/complex/finite_spec.rb b/spec/ruby/core/complex/finite_spec.rb
index de4ba78246..718848390c 100644
--- a/spec/ruby/core/complex/finite_spec.rb
+++ b/spec/ruby/core/complex/finite_spec.rb
@@ -1,36 +1,32 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Complex#finite?" do
- it "returns true if magnitude is finite" do
- (1+1i).finite?.should == true
- end
+describe "Complex#finite?" do
+ it "returns true if magnitude is finite" do
+ (1+1i).finite?.should == true
+ end
- it "returns false for positive infinity" do
- value = Complex(Float::INFINITY, 42)
- value.finite?.should == false
- end
+ it "returns false for positive infinity" do
+ value = Complex(Float::INFINITY, 42)
+ value.finite?.should == false
+ end
- it "returns false for positive complex with infinite imaginary" do
- value = Complex(1, Float::INFINITY)
- value.finite?.should == false
- end
+ it "returns false for positive complex with infinite imaginary" do
+ value = Complex(1, Float::INFINITY)
+ value.finite?.should == false
+ end
- it "returns false for negative infinity" do
- value = -Complex(Float::INFINITY, 42)
- value.finite?.should == false
- end
+ it "returns false for negative infinity" do
+ value = -Complex(Float::INFINITY, 42)
+ value.finite?.should == false
+ end
- it "returns false for negative complex with infinite imaginary" do
- value = -Complex(1, Float::INFINITY)
- value.finite?.should == false
- end
+ it "returns false for negative complex with infinite imaginary" do
+ value = -Complex(1, Float::INFINITY)
+ value.finite?.should == false
+ end
- ruby_bug "#14014", "2.4"..."2.5" do
- it "returns false for NaN" do
- value = Complex(Float::NAN, Float::NAN)
- value.finite?.should == false
- end
- end
+ it "returns false for NaN" do
+ value = Complex(Float::NAN, Float::NAN)
+ value.finite?.should == false
end
end
diff --git a/spec/ruby/core/complex/infinite_spec.rb b/spec/ruby/core/complex/infinite_spec.rb
index 27aa038cd2..9e48860dee 100644
--- a/spec/ruby/core/complex/infinite_spec.rb
+++ b/spec/ruby/core/complex/infinite_spec.rb
@@ -1,34 +1,32 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Complex#infinite?" do
- it "returns nil if magnitude is finite" do
- (1+1i).infinite?.should == nil
- end
+describe "Complex#infinite?" do
+ it "returns nil if magnitude is finite" do
+ (1+1i).infinite?.should == nil
+ end
- it "returns 1 for positive infinity" do
- value = Complex(Float::INFINITY, 42).infinite?
- value.should == 1
- end
+ it "returns 1 for positive infinity" do
+ value = Complex(Float::INFINITY, 42).infinite?
+ value.should == 1
+ end
- it "returns 1 for positive complex with infinite imaginary" do
- value = Complex(1, Float::INFINITY).infinite?
- value.should == 1
- end
+ it "returns 1 for positive complex with infinite imaginary" do
+ value = Complex(1, Float::INFINITY).infinite?
+ value.should == 1
+ end
- it "returns -1 for negative infinity" do
- value = -Complex(Float::INFINITY, 42).infinite?
- value.should == -1
- end
+ it "returns -1 for negative infinity" do
+ value = -Complex(Float::INFINITY, 42).infinite?
+ value.should == -1
+ end
- it "returns -1 for negative complex with infinite imaginary" do
- value = -Complex(1, Float::INFINITY).infinite?
- value.should == -1
- end
+ it "returns -1 for negative complex with infinite imaginary" do
+ value = -Complex(1, Float::INFINITY).infinite?
+ value.should == -1
+ end
- it "returns nil for NaN" do
- value = Complex(0, Float::NAN).infinite?
- value.should == nil
- end
+ it "returns nil for NaN" do
+ value = Complex(0, Float::NAN).infinite?
+ value.should == nil
end
end
diff --git a/spec/ruby/core/dir/empty_spec.rb b/spec/ruby/core/dir/empty_spec.rb
index ddb955f816..626b228439 100644
--- a/spec/ruby/core/dir/empty_spec.rb
+++ b/spec/ruby/core/dir/empty_spec.rb
@@ -1,33 +1,31 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Dir.empty?" do
- before :all do
- @empty_dir = tmp("empty_dir")
- mkdir_p @empty_dir
- end
+describe "Dir.empty?" do
+ before :all do
+ @empty_dir = tmp("empty_dir")
+ mkdir_p @empty_dir
+ end
- after :all do
- rm_r @empty_dir
- end
+ after :all do
+ rm_r @empty_dir
+ end
- it "returns true for empty directories" do
- result = Dir.empty? @empty_dir
- result.should be_true
- end
+ it "returns true for empty directories" do
+ result = Dir.empty? @empty_dir
+ result.should be_true
+ end
- it "returns false for non-empty directories" do
- result = Dir.empty? __dir__
- result.should be_false
- end
+ it "returns false for non-empty directories" do
+ result = Dir.empty? __dir__
+ result.should be_false
+ end
- it "returns false for a non-directory" do
- result = Dir.empty? __FILE__
- result.should be_false
- end
+ it "returns false for a non-directory" do
+ result = Dir.empty? __FILE__
+ result.should be_false
+ end
- it "raises ENOENT for nonexistent directories" do
- lambda { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT)
- end
+ it "raises ENOENT for nonexistent directories" do
+ lambda { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT)
end
end
diff --git a/spec/ruby/core/enumerable/chunk_spec.rb b/spec/ruby/core/enumerable/chunk_spec.rb
index 34fa651b33..3f8a691da5 100644
--- a/spec/ruby/core/enumerable/chunk_spec.rb
+++ b/spec/ruby/core/enumerable/chunk_spec.rb
@@ -6,21 +6,11 @@ describe "Enumerable#chunk" do
ScratchPad.record []
end
- ruby_version_is ""..."2.4" do
- it "raises an ArgumentError if called without a block" do
- lambda do
- EnumerableSpecs::Numerous.new.chunk
- end.should raise_error(ArgumentError)
- end
- end
-
- ruby_version_is "2.4" do
- it "returns an Enumerator if called without a block" do
- chunk = EnumerableSpecs::Numerous.new(1, 2, 3, 1, 2).chunk
- chunk.should be_an_instance_of(Enumerator)
- result = chunk.with_index {|elt, i| elt - i }.to_a
- result.should == [[1, [1, 2, 3]], [-2, [1, 2]]]
- end
+ it "returns an Enumerator if called without a block" do
+ chunk = EnumerableSpecs::Numerous.new(1, 2, 3, 1, 2).chunk
+ chunk.should be_an_instance_of(Enumerator)
+ result = chunk.with_index {|elt, i| elt - i }.to_a
+ result.should == [[1, [1, 2, 3]], [-2, [1, 2]]]
end
it "returns an Enumerator if given a block" do
diff --git a/spec/ruby/core/enumerable/sum_spec.rb b/spec/ruby/core/enumerable/sum_spec.rb
index 77b66bc1ec..c9d7017b45 100644
--- a/spec/ruby/core/enumerable/sum_spec.rb
+++ b/spec/ruby/core/enumerable/sum_spec.rb
@@ -1,30 +1,28 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-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
+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 '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 '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
+ it 'takes a block to transform the elements' do
+ @enum.sum { |element| element * 2 }.should == 10/3r
end
end
diff --git a/spec/ruby/core/enumerable/uniq_spec.rb b/spec/ruby/core/enumerable/uniq_spec.rb
index eb1e70c208..c286882e92 100644
--- a/spec/ruby/core/enumerable/uniq_spec.rb
+++ b/spec/ruby/core/enumerable/uniq_spec.rb
@@ -1,94 +1,90 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-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
+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
- it "uses eql? semantics" do
- [1.0, 1].to_enum.uniq.should == [1.0, 1]
- end
+ it "uses eql? semantics" do
+ [1.0, 1].to_enum.uniq.should == [1.0, 1]
+ end
- it "compares elements first with hash" do
- x = mock('0')
- x.should_receive(:hash).at_least(1).and_return(0)
- y = mock('0')
- y.should_receive(:hash).at_least(1).and_return(0)
+ it "compares elements first with hash" do
+ x = mock('0')
+ x.should_receive(:hash).at_least(1).and_return(0)
+ y = mock('0')
+ y.should_receive(:hash).at_least(1).and_return(0)
- [x, y].to_enum.uniq.should == [x, y]
- end
-
- it "does not compare elements with different hash codes via eql?" do
- x = mock('0')
- x.should_not_receive(:eql?)
- y = mock('1')
- y.should_not_receive(:eql?)
+ [x, y].to_enum.uniq.should == [x, y]
+ end
- x.should_receive(:hash).at_least(1).and_return(0)
- y.should_receive(:hash).at_least(1).and_return(1)
+ it "does not compare elements with different hash codes via eql?" do
+ x = mock('0')
+ x.should_not_receive(:eql?)
+ y = mock('1')
+ y.should_not_receive(:eql?)
- [x, y].to_enum.uniq.should == [x, y]
- end
+ x.should_receive(:hash).at_least(1).and_return(0)
+ y.should_receive(:hash).at_least(1).and_return(1)
- it "compares elements with matching hash codes with #eql?" do
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
- false
- end
+ [x, y].to_enum.uniq.should == [x, y]
+ end
- obj
+ it "compares elements with matching hash codes with #eql?" do
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
+
+ def obj.eql?(o)
+ # It's undefined whether the impl does a[0].eql?(a[1]) or
+ # a[1].eql?(a[0]) so we taint both.
+ taint
+ o.taint
+ false
end
- a.uniq.should == a
- a[0].tainted?.should == true
- a[1].tainted?.should == true
+ obj
+ end
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
+ a.uniq.should == a
+ a[0].tainted?.should == true
+ a[1].tainted?.should == true
- def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
- true
- end
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
- obj
+ def obj.eql?(o)
+ # It's undefined whether the impl does a[0].eql?(a[1]) or
+ # a[1].eql?(a[0]) so we taint both.
+ taint
+ o.taint
+ true
end
- a.to_enum.uniq.size.should == 1
- a[0].tainted?.should == true
- a[1].tainted?.should == true
+ obj
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
+ a.to_enum.uniq.size.should == 1
+ a[0].tainted?.should == true
+ a[1].tainted?.should == true
+ 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']]
+ 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
+
+ it 'returns all yield arguments as an array' do
+ @enum.uniq { |_, label| label.downcase }.should == [[0, 'foo'], [2, 'bar']]
+ end
end
end
diff --git a/spec/ruby/core/enumerator/lazy/chunk_spec.rb b/spec/ruby/core/enumerator/lazy/chunk_spec.rb
index 3f60c6ea3f..87d2b0c206 100644
--- a/spec/ruby/core/enumerator/lazy/chunk_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/chunk_spec.rb
@@ -25,22 +25,12 @@ describe "Enumerator::Lazy#chunk" do
Enumerator::Lazy.new(Object.new, 100) {}.chunk { |v| v }.size.should == nil
end
- ruby_version_is ""..."2.4" do
- it "raises an ArgumentError if called without a block" do
- lambda do
- @yieldsmixed.chunk
- end.should raise_error(ArgumentError)
- end
- end
+ it "returns an Enumerator if called without a block" do
+ chunk = @yieldsmixed.chunk
+ chunk.should be_an_instance_of(Enumerator::Lazy)
- ruby_version_is "2.4" do
- it "returns an Enumerator if called without a block" do
- chunk = @yieldsmixed.chunk
- chunk.should be_an_instance_of(Enumerator::Lazy)
-
- res = chunk.each { |v| true }.force
- res.should == [[true, EnumeratorLazySpecs::YieldsMixed.gathered_yields]]
- end
+ res = chunk.each { |v| true }.force
+ res.should == [[true, EnumeratorLazySpecs::YieldsMixed.gathered_yields]]
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
diff --git a/spec/ruby/core/enumerator/lazy/lazy_spec.rb b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
index 21fbfc27ab..cde9b31066 100644
--- a/spec/ruby/core/enumerator/lazy/lazy_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
@@ -14,9 +14,7 @@ describe "Enumerator::Lazy" do
:select, :slice_after, :slice_before, :slice_when, :take, :take_while,
:to_enum, :zip
]
- ruby_version_is "2.4" do
- lazy_methods += [:chunk_while, :uniq]
- end
+ lazy_methods += [:chunk_while, :uniq]
Enumerator::Lazy.instance_methods(false).should include(*lazy_methods)
end
diff --git a/spec/ruby/core/enumerator/lazy/select_spec.rb b/spec/ruby/core/enumerator/lazy/select_spec.rb
index c4143c5251..3773d8f0a8 100644
--- a/spec/ruby/core/enumerator/lazy/select_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/select_spec.rb
@@ -5,4 +5,43 @@ require_relative 'shared/select'
describe "Enumerator::Lazy#select" do
it_behaves_like :enumerator_lazy_select, :select
+
+ it "doesn't pre-evaluate the next element" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.next
+ eval_count.should == 1
+ end
+
+ it "doesn't over-evaluate when peeked" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.peek
+ enum.peek
+ eval_count.should == 1
+ end
+
+ it "doesn't re-evaluate after peek" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.peek
+ eval_count.should == 1
+ enum.next
+ eval_count.should == 1
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/uniq_spec.rb b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
index d337d063d6..ce67ace5ab 100644
--- a/spec/ruby/core/enumerator/lazy/uniq_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
@@ -1,82 +1,74 @@
require_relative '../../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe 'Enumerator::Lazy#uniq' do
- context 'without block' do
- before :each do
- @lazy = [0, 1, 0, 1].to_enum.lazy.uniq
- end
-
- it 'returns a lazy enumerator' do
- @lazy.should be_an_instance_of(Enumerator::Lazy)
- @lazy.force.should == [0, 1]
- end
+describe 'Enumerator::Lazy#uniq' do
+ context 'without block' do
+ before :each do
+ @lazy = [0, 1, 0, 1].to_enum.lazy.uniq
+ end
- ruby_bug "#14495", "2.4"..."2.5.2" do
- it 'return same value after rewind' do
- @lazy.force.should == [0, 1]
- @lazy.force.should == [0, 1]
- end
- 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
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.should == [0, 1]
end
- context 'when yielded with an argument' do
- before :each do
- @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
- end
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
- it 'returns a lazy enumerator' do
- @lazy.should be_an_instance_of(Enumerator::Lazy)
- @lazy.force.should == [0, 1]
- end
+ context 'when yielded with an argument' do
+ before :each do
+ @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
+ end
- ruby_bug "#14495", "2.4"..."2.5.2" do
- it 'return same value after rewind' do
- @lazy.force.should == [0, 1]
- @lazy.force.should == [0, 1]
- end
- 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
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.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
- @lazy = enum.lazy
- end
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
- ruby_bug "#14495", "2.4"..."2.5.2" do
- it 'return same value after rewind' do
- enum = @lazy.uniq { |_, label| label.downcase }
- enum.force.should == [[0, 'foo'], [2, 'bar']]
- enum.force.should == [[0, 'foo'], [2, 'bar']]
+ 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
+ it 'return same value after rewind' do
+ enum = @lazy.uniq { |_, label| label.downcase }
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
end
- it "works with an infinite enumerable" do
- s = 0..Float::INFINITY
- s.lazy.uniq.first(100).should ==
- s.first(100).uniq
+ it 'returns all yield arguments as an array' do
+ @lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.uniq.first(100).should ==
+ s.first(100).uniq
+ end
end
diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb
index ea9995a3b0..c8a11430ab 100644
--- a/spec/ruby/core/env/fetch_spec.rb
+++ b/spec/ruby/core/env/fetch_spec.rb
@@ -14,6 +14,12 @@ describe "ENV.fetch" do
context "when the key is not found" do
it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, ENV
+
+ it "formats the object with #inspect in the KeyError message" do
+ -> {
+ ENV.fetch('foo')
+ }.should raise_error(KeyError, 'key not found: "foo"')
+ end
end
it "provides the given default parameter" do
diff --git a/spec/ruby/core/false/dup_spec.rb b/spec/ruby/core/false/dup_spec.rb
index 24360a9fc1..1a569a2f4f 100644
--- a/spec/ruby/core/false/dup_spec.rb
+++ b/spec/ruby/core/false/dup_spec.rb
@@ -1,9 +1,7 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "FalseClass#dup" do
- it "returns self" do
- false.dup.should equal(false)
- end
+describe "FalseClass#dup" do
+ it "returns self" do
+ false.dup.should equal(false)
end
end
diff --git a/spec/ruby/core/fiber/resume_spec.rb b/spec/ruby/core/fiber/resume_spec.rb
index 2f15a834d4..d05e62c455 100644
--- a/spec/ruby/core/fiber/resume_spec.rb
+++ b/spec/ruby/core/fiber/resume_spec.rb
@@ -42,7 +42,7 @@ with_feature :fiber do
f.resume
# When we execute the second #resume call, the ensure block DOES exit,
- # the ensure clause runs. This is Ruby behavior as of 2.3.1.
+ # the ensure clause runs.
f.resume
exit 0
diff --git a/spec/ruby/core/file/empty_spec.rb b/spec/ruby/core/file/empty_spec.rb
index a904f140e6..77f132303e 100644
--- a/spec/ruby/core/file/empty_spec.rb
+++ b/spec/ruby/core/file/empty_spec.rb
@@ -2,14 +2,12 @@ require_relative '../../spec_helper'
require_relative '../../shared/file/zero'
describe "File.empty?" do
- ruby_version_is "2.4" do
- it_behaves_like :file_zero, :empty?, File
- it_behaves_like :file_zero_missing, :empty?, File
+ it_behaves_like :file_zero, :empty?, File
+ it_behaves_like :file_zero_missing, :empty?, File
- platform_is :solaris do
- it "returns false for /dev/null" do
- File.empty?('/dev/null').should == true
- end
+ platform_is :solaris do
+ it "returns false for /dev/null" do
+ File.empty?('/dev/null').should == true
end
end
end
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb
index 6e24e62075..b03bb3a2ca 100644
--- a/spec/ruby/core/file/expand_path_spec.rb
+++ b/spec/ruby/core/file/expand_path_spec.rb
@@ -222,16 +222,14 @@ platform_is_not :windows do
ENV["HOME"] = @home
end
- ruby_version_is ''...'2.4' do
- it "raises an ArgumentError when passed '~' if HOME is nil" do
- ENV.delete "HOME"
- lambda { File.expand_path("~") }.should raise_error(ArgumentError)
- end
+ it "uses the user database when passed '~' if HOME is nil" do
+ ENV.delete "HOME"
+ File.directory?(File.expand_path("~")).should == true
+ end
- it "raises an ArgumentError when passed '~/' if HOME is nil" do
- ENV.delete "HOME"
- lambda { File.expand_path("~/") }.should raise_error(ArgumentError)
- end
+ it "uses the user database when passed '~/' if HOME is nil" do
+ ENV.delete "HOME"
+ File.directory?(File.expand_path("~/")).should == true
end
it "raises an ArgumentError when passed '~' if HOME == ''" do
diff --git a/spec/ruby/core/file/mtime_spec.rb b/spec/ruby/core/file/mtime_spec.rb
index c5d854bb08..833f759eaa 100644
--- a/spec/ruby/core/file/mtime_spec.rb
+++ b/spec/ruby/core/file/mtime_spec.rb
@@ -12,7 +12,7 @@ describe "File.mtime" do
it "returns the modification Time of the file" do
File.mtime(@filename).should be_kind_of(Time)
- File.mtime(@filename).should be_close(@mtime, 60.0)
+ File.mtime(@filename).should be_close(@mtime, TIME_TOLERANCE)
end
guard -> { platform_is :linux or (platform_is :windows and ruby_version_is '2.5') } do
diff --git a/spec/ruby/core/file/stat/dev_major_spec.rb b/spec/ruby/core/file/stat/dev_major_spec.rb
index 845c883a42..4966d609e2 100644
--- a/spec/ruby/core/file/stat/dev_major_spec.rb
+++ b/spec/ruby/core/file/stat/dev_major_spec.rb
@@ -9,11 +9,9 @@ describe "File::Stat#dev_major" do
rm_r @name
end
- ruby_version_is "2.4" do
- platform_is_not :windows do
- it "returns the major part of File::Stat#dev" do
- File.stat(@name).dev_major.should be_kind_of(Integer)
- end
+ platform_is_not :windows do
+ it "returns the major part of File::Stat#dev" do
+ File.stat(@name).dev_major.should be_kind_of(Integer)
end
end
diff --git a/spec/ruby/core/file/stat/dev_minor_spec.rb b/spec/ruby/core/file/stat/dev_minor_spec.rb
index ddfb6a7b6a..ea79c12b99 100644
--- a/spec/ruby/core/file/stat/dev_minor_spec.rb
+++ b/spec/ruby/core/file/stat/dev_minor_spec.rb
@@ -9,11 +9,9 @@ describe "File::Stat#dev_minor" do
rm_r @name
end
- ruby_version_is "2.4" do
- platform_is_not :windows do
- it "returns the minor part of File::Stat#dev" do
- File.stat(@name).dev_minor.should be_kind_of(Integer)
- end
+ platform_is_not :windows do
+ it "returns the minor part of File::Stat#dev" do
+ File.stat(@name).dev_minor.should be_kind_of(Integer)
end
end
diff --git a/spec/ruby/core/file/stat/rdev_major_spec.rb b/spec/ruby/core/file/stat/rdev_major_spec.rb
index 3d7f6ef759..f8a8d1b107 100644
--- a/spec/ruby/core/file/stat/rdev_major_spec.rb
+++ b/spec/ruby/core/file/stat/rdev_major_spec.rb
@@ -17,11 +17,9 @@ describe "File::Stat#rdev_major" do
end
end
- ruby_version_is "2.4" do
- platform_is_not :windows do
- it "returns the major part of File::Stat#rdev" do
- File.stat(@name).rdev_major.should be_kind_of(Integer)
- end
+ platform_is_not :windows do
+ it "returns the major part of File::Stat#rdev" do
+ File.stat(@name).rdev_major.should be_kind_of(Integer)
end
end
diff --git a/spec/ruby/core/file/stat/rdev_minor_spec.rb b/spec/ruby/core/file/stat/rdev_minor_spec.rb
index e25c61ca86..dc30c1f56c 100644
--- a/spec/ruby/core/file/stat/rdev_minor_spec.rb
+++ b/spec/ruby/core/file/stat/rdev_minor_spec.rb
@@ -17,11 +17,9 @@ describe "File::Stat#rdev_minor" do
end
end
- ruby_version_is "2.4" do
- platform_is_not :windows do
- it "returns the minor part of File::Stat#rdev" do
- File.stat(@name).rdev_minor.should be_kind_of(Integer)
- end
+ platform_is_not :windows do
+ it "returns the minor part of File::Stat#rdev" do
+ File.stat(@name).rdev_minor.should be_kind_of(Integer)
end
end
diff --git a/spec/ruby/core/file/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb
index 64af82ef19..03adc76efe 100644
--- a/spec/ruby/core/file/utime_spec.rb
+++ b/spec/ruby/core/file/utime_spec.rb
@@ -27,10 +27,10 @@ describe "File.utime" do
File.atime(@file2).should be_close(@atime, 0.0001)
File.mtime(@file2).should be_close(@mtime, 0.0001)
else
- File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
- File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ File.atime(@file1).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
end
end
@@ -43,10 +43,10 @@ describe "File.utime" do
File.atime(@file2).should be_close(tn, 0.050)
File.mtime(@file2).should be_close(tn, 0.050)
else
- File.atime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.atime(@file2).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file2).to_i.should be_close(Time.now.to_i, 2)
+ File.atime(@file1).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
end
end
@@ -63,10 +63,10 @@ describe "File.utime" do
File.mtime(@file2).should be_close(@mtime, 0.0001)
else
File.utime(@atime.to_i, @mtime.to_i, @file1, @file2)
- File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
- File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
+ File.atime(@file1).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
end
end
diff --git a/spec/ruby/core/float/ceil_spec.rb b/spec/ruby/core/float/ceil_spec.rb
index 8a4f72c70e..7fc18d304c 100644
--- a/spec/ruby/core/float/ceil_spec.rb
+++ b/spec/ruby/core/float/ceil_spec.rb
@@ -11,13 +11,11 @@ describe "Float#ceil" do
+9223372036854775808.1.ceil.should eql(+9223372036854775808)
end
- ruby_version_is "2.4" do
- it "returns the smallest number greater than or equal to self with an optionally given precision" do
- 2.1679.ceil(0).should eql(3)
- 214.94.ceil(-1).should eql(220)
- 7.0.ceil(1).should eql(7.0)
- -1.234.ceil(2).should eql(-1.23)
- 5.123812.ceil(4).should eql(5.1239)
- end
+ it "returns the smallest number greater than or equal to self with an optionally given precision" do
+ 2.1679.ceil(0).should eql(3)
+ 214.94.ceil(-1).should eql(220)
+ 7.0.ceil(1).should eql(7.0)
+ -1.234.ceil(2).should eql(-1.23)
+ 5.123812.ceil(4).should eql(5.1239)
end
end
diff --git a/spec/ruby/core/float/dup_spec.rb b/spec/ruby/core/float/dup_spec.rb
index 8df7260652..294da8e2bc 100644
--- a/spec/ruby/core/float/dup_spec.rb
+++ b/spec/ruby/core/float/dup_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Float#dup" do
- it "returns self" do
- float = 2.4
- float.dup.should equal(float)
- end
+describe "Float#dup" do
+ it "returns self" do
+ float = 2.4
+ float.dup.should equal(float)
end
end
diff --git a/spec/ruby/core/float/floor_spec.rb b/spec/ruby/core/float/floor_spec.rb
index f20eccae73..046216d36d 100644
--- a/spec/ruby/core/float/floor_spec.rb
+++ b/spec/ruby/core/float/floor_spec.rb
@@ -11,13 +11,11 @@ describe "Float#floor" do
+9223372036854775808.1.floor.should eql(+9223372036854775808)
end
- ruby_version_is "2.4" do
- it "returns the largest number less than or equal to self with an optionally given precision" do
- 2.1679.floor(0).should eql(2)
- 214.94.floor(-1).should eql(210)
- 7.0.floor(1).should eql(7.0)
- -1.234.floor(2).should eql(-1.24)
- 5.123812.floor(4).should eql(5.1238)
- end
+ it "returns the largest number less than or equal to self with an optionally given precision" do
+ 2.1679.floor(0).should eql(2)
+ 214.94.floor(-1).should eql(210)
+ 7.0.floor(1).should eql(7.0)
+ -1.234.floor(2).should eql(-1.24)
+ 5.123812.floor(4).should eql(5.1238)
end
end
diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb
index a21173e139..d5ca532c5a 100644
--- a/spec/ruby/core/float/round_spec.rb
+++ b/spec/ruby/core/float/round_spec.rb
@@ -83,17 +83,35 @@ describe "Float#round" do
-2.4e200.round(-200).should eql( -2 * 10 ** 200 )
end
- ruby_version_is "2.4" do
- it "returns different rounded values depending on the half option" do
- 2.5.round(half: :up).should eql(3)
- 2.5.round(half: :down).should eql(2)
- 2.5.round(half: :even).should eql(2)
- 3.5.round(half: :up).should eql(4)
- 3.5.round(half: :down).should eql(3)
- 3.5.round(half: :even).should eql(4)
- (-2.5).round(half: :up).should eql(-3)
- (-2.5).round(half: :down).should eql(-2)
- (-2.5).round(half: :even).should eql(-2)
- end
+ it "returns different rounded values depending on the half option" do
+ 2.5.round(half: nil).should eql(3)
+ 2.5.round(half: :up).should eql(3)
+ 2.5.round(half: :down).should eql(2)
+ 2.5.round(half: :even).should eql(2)
+ 3.5.round(half: nil).should eql(4)
+ 3.5.round(half: :up).should eql(4)
+ 3.5.round(half: :down).should eql(3)
+ 3.5.round(half: :even).should eql(4)
+ (-2.5).round(half: nil).should eql(-3)
+ (-2.5).round(half: :up).should eql(-3)
+ (-2.5).round(half: :down).should eql(-2)
+ (-2.5).round(half: :even).should eql(-2)
+ end
+
+ it "rounds self to an optionally given precision with a half option" do
+ 5.55.round(1, half: nil).should eql(5.6)
+ 5.55.round(1, half: :up).should eql(5.6)
+ 5.55.round(1, half: :down).should eql(5.5)
+ 5.55.round(1, half: :even).should eql(5.6)
+ end
+
+ it "raises FloatDomainError for exceptional values with a half option" do
+ lambda { (+infinity_value).round(half: :up) }.should raise_error(FloatDomainError)
+ lambda { (-infinity_value).round(half: :down) }.should raise_error(FloatDomainError)
+ lambda { nan_value.round(half: :even) }.should raise_error(FloatDomainError)
+ end
+
+ it "raise for a non-existent round mode" do
+ lambda { 14.2.round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
end
end
diff --git a/spec/ruby/core/float/truncate_spec.rb b/spec/ruby/core/float/truncate_spec.rb
index 5c219da960..2c80145f9f 100644
--- a/spec/ruby/core/float/truncate_spec.rb
+++ b/spec/ruby/core/float/truncate_spec.rb
@@ -4,13 +4,11 @@ require_relative 'shared/to_i'
describe "Float#truncate" do
it_behaves_like :float_to_i, :truncate
- ruby_version_is "2.4" do
- it "returns self truncated to an optionally given precision" do
- 2.1679.truncate(0).should eql(2)
- 7.1.truncate(1).should eql(7.1)
- 214.94.truncate(-1).should eql(210)
- -1.234.truncate(2).should eql(-1.23)
- 5.123812.truncate(4).should eql(5.1238)
- end
+ it "returns self truncated to an optionally given precision" do
+ 2.1679.truncate(0).should eql(2)
+ 7.1.truncate(1).should eql(7.1)
+ 214.94.truncate(-1).should eql(210)
+ -1.234.truncate(2).should eql(-1.23)
+ 5.123812.truncate(4).should eql(5.1238)
end
end
diff --git a/spec/ruby/core/hash/compact_spec.rb b/spec/ruby/core/hash/compact_spec.rb
index b75621b4d4..ec9d4b5d79 100644
--- a/spec/ruby/core/hash/compact_spec.rb
+++ b/spec/ruby/core/hash/compact_spec.rb
@@ -1,61 +1,59 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.4" do
- describe "Hash#compact" do
- before :each do
- @hash = { truthy: true, false: false, nil: nil, nil => true }
- @initial_pairs = @hash.dup
- @compact = { truthy: true, false: false, nil => true }
- end
+describe "Hash#compact" do
+ before :each do
+ @hash = { truthy: true, false: false, nil: nil, nil => true }
+ @initial_pairs = @hash.dup
+ @compact = { truthy: true, false: false, nil => true }
+ end
- it "returns new object that rejects pair has nil value" do
- ret = @hash.compact
- ret.should_not equal(@hash)
- ret.should == @compact
- end
+ it "returns new object that rejects pair has nil value" do
+ ret = @hash.compact
+ ret.should_not equal(@hash)
+ ret.should == @compact
+ end
- it "keeps own pairs" do
- @hash.compact
- @hash.should == @initial_pairs
- end
+ it "keeps own pairs" do
+ @hash.compact
+ @hash.should == @initial_pairs
end
+end
- describe "Hash#compact!" do
- before :each do
- @hash = { truthy: true, false: false, nil: nil, nil => true }
- @initial_pairs = @hash.dup
- @compact = { truthy: true, false: false, nil => true }
- end
+describe "Hash#compact!" do
+ before :each do
+ @hash = { truthy: true, false: false, nil: nil, nil => true }
+ @initial_pairs = @hash.dup
+ @compact = { truthy: true, false: false, nil => true }
+ end
- it "returns self" do
- @hash.compact!.should equal(@hash)
- end
+ it "returns self" do
+ @hash.compact!.should equal(@hash)
+ end
- it "rejects own pair has nil value" do
+ it "rejects own pair has nil value" do
+ @hash.compact!
+ @hash.should == @compact
+ end
+
+ context "when each pair does not have nil value" do
+ before :each do
@hash.compact!
- @hash.should == @compact
end
- context "when each pair does not have nil value" do
- before :each do
- @hash.compact!
- end
-
- it "returns nil" do
- @hash.compact!.should be_nil
- end
+ it "returns nil" do
+ @hash.compact!.should be_nil
end
+ end
- describe "on frozen instance" do
- before :each do
- @hash.freeze
- end
+ describe "on frozen instance" do
+ before :each do
+ @hash.freeze
+ end
- it "keeps pairs and raises a #{frozen_error_class}" do
- ->{ @hash.compact! }.should raise_error(frozen_error_class)
- @hash.should == @initial_pairs
- end
+ it "keeps pairs and raises a #{frozen_error_class}" do
+ ->{ @hash.compact! }.should raise_error(frozen_error_class)
+ @hash.should == @initial_pairs
end
end
end
diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb
index e463c311be..33db59124e 100644
--- a/spec/ruby/core/hash/compare_by_identity_spec.rb
+++ b/spec/ruby/core/hash/compare_by_identity_spec.rb
@@ -108,13 +108,11 @@ describe "Hash#compare_by_identity" do
@idh.keys.first.should equal foo
end
- ruby_bug "#12855", ""..."2.4.1" do
- it "gives different identity for string literals" do
- @idh['foo'] = 1
- @idh['foo'] = 2
- @idh.values.should == [1, 2]
- @idh.size.should == 2
- end
+ it "gives different identity for string literals" do
+ @idh['foo'] = 1
+ @idh['foo'] = 2
+ @idh.values.should == [1, 2]
+ @idh.size.should == 2
end
end
diff --git a/spec/ruby/core/hash/fetch_spec.rb b/spec/ruby/core/hash/fetch_spec.rb
index 2fee5d0164..197832e311 100644
--- a/spec/ruby/core/hash/fetch_spec.rb
+++ b/spec/ruby/core/hash/fetch_spec.rb
@@ -8,6 +8,12 @@ describe "Hash#fetch" do
it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, {}
it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new { 5 }
it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new(5)
+
+ it "formats the object with #inspect in the KeyError message" do
+ -> {
+ {}.fetch('foo')
+ }.should raise_error(KeyError, 'key not found: "foo"')
+ end
end
it "returns the value for key" do
diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb
index 5ea70610be..e90beae87a 100644
--- a/spec/ruby/core/hash/merge_spec.rb
+++ b/spec/ruby/core/hash/merge_spec.rb
@@ -69,9 +69,12 @@ describe "Hash#merge" do
result.should == { a: 1, b: 2, c: 3, d: 4 }
end
- it "accepts zero arguments and returns self" do
+ it "accepts zero arguments and returns a copy of self" do
hash = { a: 1 }
- hash.merge.should eql(hash)
+ merged = hash.merge
+
+ merged.should eql(hash)
+ merged.should_not equal(hash)
end
end
end
diff --git a/spec/ruby/core/hash/shared/each.rb b/spec/ruby/core/hash/shared/each.rb
index 1d89cfdd39..d1f2e5f672 100644
--- a/spec/ruby/core/hash/shared/each.rb
+++ b/spec/ruby/core/hash/shared/each.rb
@@ -21,7 +21,7 @@ describe :hash_each, shared: true do
ary.sort.should == ["a", "b", "c"]
end
- it "yields 2 values and not an Array of 2 elements" do
+ it "yields 2 values and not an Array of 2 elements when given a callable of arity 2" do
obj = Object.new
def obj.foo(key, value)
ScratchPad << key << value
diff --git a/spec/ruby/core/hash/transform_values_spec.rb b/spec/ruby/core/hash/transform_values_spec.rb
index 80e875097a..8b53b7a522 100644
--- a/spec/ruby/core/hash/transform_values_spec.rb
+++ b/spec/ruby/core/hash/transform_values_spec.rb
@@ -1,98 +1,96 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Hash#transform_values" do
- before :each do
- @hash = { a: 1, b: 2, c: 3 }
- end
+describe "Hash#transform_values" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
- it "returns new hash" do
- ret = @hash.transform_values(&:succ)
- ret.should_not equal(@hash)
- ret.should be_an_instance_of(Hash)
- end
+ it "returns new hash" do
+ ret = @hash.transform_values(&:succ)
+ ret.should_not equal(@hash)
+ ret.should be_an_instance_of(Hash)
+ end
- it "sets the result as transformed values with the given block" do
- @hash.transform_values(&:succ).should == { a: 2, b: 3, c: 4 }
- end
+ it "sets the result as transformed values with the given block" do
+ @hash.transform_values(&:succ).should == { a: 2, b: 3, c: 4 }
+ end
- it "makes both hashes to share keys" do
- key = [1, 2, 3]
- new_hash = { key => 1 }.transform_values(&:succ)
- new_hash[key].should == 2
- new_hash.keys[0].should equal(key)
- end
+ it "makes both hashes to share keys" do
+ key = [1, 2, 3]
+ new_hash = { key => 1 }.transform_values(&:succ)
+ new_hash[key].should == 2
+ new_hash.keys[0].should equal(key)
+ end
- context "when no block is given" do
- it "returns a sized Enumerator" do
- enumerator = @hash.transform_values
- enumerator.should be_an_instance_of(Enumerator)
- enumerator.size.should == @hash.size
- enumerator.each(&:succ).should == { a: 2, b: 3, c: 4 }
- end
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_values
+ enumerator.should be_an_instance_of(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:succ).should == { a: 2, b: 3, c: 4 }
end
+ end
- it "returns a Hash instance, even on subclasses" do
- klass = Class.new(Hash)
- h = klass.new
- h[:foo] = 42
- r = h.transform_values{|v| 2 * v}
- r[:foo].should == 84
- r.class.should == Hash
- end
+ it "returns a Hash instance, even on subclasses" do
+ klass = Class.new(Hash)
+ h = klass.new
+ h[:foo] = 42
+ r = h.transform_values{|v| 2 * v}
+ r[:foo].should == 84
+ r.class.should == Hash
end
+end
- describe "Hash#transform_values!" do
- before :each do
- @hash = { a: 1, b: 2, c: 3 }
- @initial_pairs = @hash.dup
- end
+describe "Hash#transform_values!" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ @initial_pairs = @hash.dup
+ end
- it "returns self" do
- @hash.transform_values!(&:succ).should equal(@hash)
+ it "returns self" do
+ @hash.transform_values!(&:succ).should equal(@hash)
+ end
+
+ it "updates self as transformed values with the given block" do
+ @hash.transform_values!(&:succ)
+ @hash.should == { a: 2, b: 3, c: 4 }
+ end
+
+ it "partially modifies the contents if we broke from the block" do
+ @hash.transform_values! do |v|
+ break if v == 3
+ 100 + v
end
+ @hash.should == { a: 101, b: 102, c: 3}
+ end
- it "updates self as transformed values with the given block" do
- @hash.transform_values!(&:succ)
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_values!
+ enumerator.should be_an_instance_of(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:succ)
@hash.should == { a: 2, b: 3, c: 4 }
end
+ end
- it "partially modifies the contents if we broke from the block" do
- @hash.transform_values! do |v|
- break if v == 3
- 100 + v
- end
- @hash.should == { a: 101, b: 102, c: 3}
+ describe "on frozen instance" do
+ before :each do
+ @hash.freeze
end
- context "when no block is given" do
- it "returns a sized Enumerator" do
- enumerator = @hash.transform_values!
- enumerator.should be_an_instance_of(Enumerator)
- enumerator.size.should == @hash.size
- enumerator.each(&:succ)
- @hash.should == { a: 2, b: 3, c: 4 }
- end
+ it "raises a #{frozen_error_class} on an empty hash" do
+ ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(frozen_error_class)
end
- describe "on frozen instance" do
- before :each do
- @hash.freeze
- end
-
- it "raises a #{frozen_error_class} on an empty hash" do
- ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(frozen_error_class)
- end
-
- it "keeps pairs and raises a #{frozen_error_class}" do
- ->{ @hash.transform_values!(&:succ) }.should raise_error(frozen_error_class)
- @hash.should == @initial_pairs
- end
+ it "keeps pairs and raises a #{frozen_error_class}" do
+ ->{ @hash.transform_values!(&:succ) }.should raise_error(frozen_error_class)
+ @hash.should == @initial_pairs
+ end
- context "when no block is given" do
- it "does not raise an exception" do
- @hash.transform_values!.should be_an_instance_of(Enumerator)
- end
+ context "when no block is given" do
+ it "does not raise an exception" do
+ @hash.transform_values!.should be_an_instance_of(Enumerator)
end
end
end
diff --git a/spec/ruby/core/integer/ceil_spec.rb b/spec/ruby/core/integer/ceil_spec.rb
index 9e1311bc6d..13bdaf838d 100644
--- a/spec/ruby/core/integer/ceil_spec.rb
+++ b/spec/ruby/core/integer/ceil_spec.rb
@@ -6,16 +6,14 @@ describe "Integer#ceil" do
it_behaves_like :integer_to_i, :ceil
it_behaves_like :integer_rounding_positive_precision, :ceil
- ruby_version_is "2.4" do
- context "precision argument specified as part of the ceil method is negative" do
- it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
- 18.ceil(-1).should eql(20)
- 18.ceil(-2).should eql(100)
- 18.ceil(-3).should eql(1000)
- -1832.ceil(-1).should eql(-1830)
- -1832.ceil(-2).should eql(-1800)
- -1832.ceil(-3).should eql(-1000)
- end
+ context "precision argument specified as part of the ceil method is negative" do
+ it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
+ 18.ceil(-1).should eql(20)
+ 18.ceil(-2).should eql(100)
+ 18.ceil(-3).should eql(1000)
+ -1832.ceil(-1).should eql(-1830)
+ -1832.ceil(-2).should eql(-1800)
+ -1832.ceil(-3).should eql(-1000)
end
end
end
diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb
index 1bc30fe9ce..8db15bbaed 100644
--- a/spec/ruby/core/integer/coerce_spec.rb
+++ b/spec/ruby/core/integer/coerce_spec.rb
@@ -68,38 +68,24 @@ describe "Integer#coerce" do
lambda { a.coerce(:test) }.should raise_error(TypeError)
end
- ruby_version_is ""..."2.4" do
- it "raises a TypeError when passed a String" do
- a = bignum_value
- lambda { a.coerce("123") }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a Float" do
- a = bignum_value
- lambda { a.coerce(12.3) }.should raise_error(TypeError)
- end
+ it "coerces both values to Floats and returns [other, self] when passed a Float" do
+ a = bignum_value
+ a.coerce(1.2).should == [1.2, a.to_f]
end
- ruby_version_is "2.4" do
- it "coerces both values to Floats and returns [other, self] when passed a Float" do
- a = bignum_value
- a.coerce(1.2).should == [1.2, a.to_f]
- end
-
- it "coerces both values to Floats and returns [other, self] when passed a String" do
- a = bignum_value
- a.coerce("123").should == [123.0, a.to_f]
- end
+ it "coerces both values to Floats and returns [other, self] when passed a String" do
+ a = bignum_value
+ a.coerce("123").should == [123.0, a.to_f]
+ end
- it "calls #to_f to coerce other to a Float" do
- b = mock("bignum value")
- b.should_receive(:to_f).and_return(1.2)
+ it "calls #to_f to coerce other to a Float" do
+ b = mock("bignum value")
+ b.should_receive(:to_f).and_return(1.2)
- a = bignum_value
- ary = a.coerce(b)
+ a = bignum_value
+ ary = a.coerce(b)
- ary.should == [1.2, a.to_f]
- end
+ ary.should == [1.2, a.to_f]
end
end
end
diff --git a/spec/ruby/core/integer/digits_spec.rb b/spec/ruby/core/integer/digits_spec.rb
index a60650246b..85afb6f50f 100644
--- a/spec/ruby/core/integer/digits_spec.rb
+++ b/spec/ruby/core/integer/digits_spec.rb
@@ -1,34 +1,32 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Integer#digits" do
- it "returns an array of place values in base-10 by default" do
- 12345.digits.should == [5,4,3,2,1]
- end
+describe "Integer#digits" do
+ it "returns an array of place values in base-10 by default" do
+ 12345.digits.should == [5,4,3,2,1]
+ end
- it "returns digits by place value of a given radix" do
- 12345.digits(7).should == [4,6,6,0,5]
- end
+ it "returns digits by place value of a given radix" do
+ 12345.digits(7).should == [4,6,6,0,5]
+ end
- it "converts the radix with #to_int" do
- 12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
- end
+ it "converts the radix with #to_int" do
+ 12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
+ end
- it "returns [0] when called on 0, regardless of base" do
- 0.digits.should == [0]
- 0.digits(7).should == [0]
- end
+ it "returns [0] when called on 0, regardless of base" do
+ 0.digits.should == [0]
+ 0.digits(7).should == [0]
+ end
- it "raises ArgumentError when calling with a radix less than 2" do
- lambda { 12345.digits(1) }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError when calling with a radix less than 2" do
+ lambda { 12345.digits(1) }.should raise_error(ArgumentError)
+ end
- it "raises ArgumentError when calling with a negative radix" do
- lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError when calling with a negative radix" do
+ lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
+ end
- it "raises Math::DomainError when calling digits on a negative number" do
- lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
- end
+ it "raises Math::DomainError when calling digits on a negative number" do
+ lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
end
end
diff --git a/spec/ruby/core/integer/dup_spec.rb b/spec/ruby/core/integer/dup_spec.rb
index 214367f0b4..7f4d512465 100644
--- a/spec/ruby/core/integer/dup_spec.rb
+++ b/spec/ruby/core/integer/dup_spec.rb
@@ -1,15 +1,13 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Integer#dup" do
- it "returns self for small integers" do
- integer = 1_000
- integer.dup.should equal(integer)
- end
+describe "Integer#dup" do
+ it "returns self for small integers" do
+ integer = 1_000
+ integer.dup.should equal(integer)
+ end
- it "returns self for large integers" do
- integer = 4_611_686_018_427_387_905
- integer.dup.should equal(integer)
- end
+ it "returns self for large integers" do
+ integer = 4_611_686_018_427_387_905
+ integer.dup.should equal(integer)
end
end
diff --git a/spec/ruby/core/integer/floor_spec.rb b/spec/ruby/core/integer/floor_spec.rb
index 58439c98c1..aaa816fdc5 100644
--- a/spec/ruby/core/integer/floor_spec.rb
+++ b/spec/ruby/core/integer/floor_spec.rb
@@ -6,16 +6,14 @@ describe "Integer#floor" do
it_behaves_like :integer_to_i, :floor
it_behaves_like :integer_rounding_positive_precision, :floor
- ruby_version_is "2.4" do
- context "precision argument specified as part of the floor method is negative" do
- it "returns the largest integer less than self with at least precision.abs trailing zeros" do
- 1832.floor(-1).should eql(1830)
- 1832.floor(-2).should eql(1800)
- 1832.floor(-3).should eql(1000)
- -1832.floor(-1).should eql(-1840)
- -1832.floor(-2).should eql(-1900)
- -1832.floor(-3).should eql(-2000)
- end
+ context "precision argument specified as part of the floor method is negative" do
+ it "returns the largest integer less than self with at least precision.abs trailing zeros" do
+ 1832.floor(-1).should eql(1830)
+ 1832.floor(-2).should eql(1800)
+ 1832.floor(-3).should eql(1000)
+ -1832.floor(-1).should eql(-1840)
+ -1832.floor(-2).should eql(-1900)
+ -1832.floor(-3).should eql(-2000)
end
end
end
diff --git a/spec/ruby/core/integer/integer_spec.rb b/spec/ruby/core/integer/integer_spec.rb
index 6db2d50346..f8067cda06 100644
--- a/spec/ruby/core/integer/integer_spec.rb
+++ b/spec/ruby/core/integer/integer_spec.rb
@@ -5,11 +5,9 @@ describe "Integer" do
Integer.include?(Comparable).should == true
end
- ruby_version_is "2.4" do
- it "is the class of both small and large integers" do
- 42.class.should equal(Integer)
- bignum_value.class.should equal(Integer)
- end
+ it "is the class of both small and large integers" do
+ 42.class.should equal(Integer)
+ bignum_value.class.should equal(Integer)
end
end
diff --git a/spec/ruby/core/integer/pow_spec.rb b/spec/ruby/core/integer/pow_spec.rb
index fb0ba996bc..ed14c40a27 100644
--- a/spec/ruby/core/integer/pow_spec.rb
+++ b/spec/ruby/core/integer/pow_spec.rb
@@ -16,13 +16,11 @@ ruby_version_is "2.5" do
2.pow(8, 15).should == 1
end
- ruby_bug '#13669', '2.5'...'2.5.1' do
- it "works well with bignums" do
- 2.pow(61, 5843009213693951).should eql 3697379018277258
- 2.pow(62, 5843009213693952).should eql 1551748822859776
- 2.pow(63, 5843009213693953).should eql 3103497645717974
- 2.pow(64, 5843009213693954).should eql 363986077738838
- end
+ it "works well with bignums" do
+ 2.pow(61, 5843009213693951).should eql 3697379018277258
+ 2.pow(62, 5843009213693952).should eql 1551748822859776
+ 2.pow(63, 5843009213693953).should eql 3103497645717974
+ 2.pow(64, 5843009213693954).should eql 363986077738838
end
it "handles sign like #divmod does" do
diff --git a/spec/ruby/core/integer/round_spec.rb b/spec/ruby/core/integer/round_spec.rb
index aa6345fda5..622a55280e 100644
--- a/spec/ruby/core/integer/round_spec.rb
+++ b/spec/ruby/core/integer/round_spec.rb
@@ -63,18 +63,16 @@ describe "Integer#round" do
lambda { 42.round(obj) }.should raise_error(TypeError)
end
- ruby_version_is "2.4" do
- it "returns different rounded values depending on the half option" do
- 25.round(-1, half: :up).should eql(30)
- 25.round(-1, half: :down).should eql(20)
- 25.round(-1, half: :even).should eql(20)
- 35.round(-1, half: :up).should eql(40)
- 35.round(-1, half: :down).should eql(30)
- 35.round(-1, half: :even).should eql(40)
- (-25).round(-1, half: :up).should eql(-30)
- (-25).round(-1, half: :down).should eql(-20)
- (-25).round(-1, half: :even).should eql(-20)
- end
+ it "returns different rounded values depending on the half option" do
+ 25.round(-1, half: :up).should eql(30)
+ 25.round(-1, half: :down).should eql(20)
+ 25.round(-1, half: :even).should eql(20)
+ 35.round(-1, half: :up).should eql(40)
+ 35.round(-1, half: :down).should eql(30)
+ 35.round(-1, half: :even).should eql(40)
+ (-25).round(-1, half: :up).should eql(-30)
+ (-25).round(-1, half: :down).should eql(-20)
+ (-25).round(-1, half: :even).should eql(-20)
end
ruby_version_is "2.4"..."2.5" do
diff --git a/spec/ruby/core/integer/shared/integer_rounding.rb b/spec/ruby/core/integer/shared/integer_rounding.rb
index ecbda1bb4a..3fb6e830ef 100644
--- a/spec/ruby/core/integer/shared/integer_rounding.rb
+++ b/spec/ruby/core/integer/shared/integer_rounding.rb
@@ -5,11 +5,9 @@ describe :integer_rounding_positive_precision, shared: true do
end
end
- ruby_version_is "2.4" do
- it "returns self if passed a precision of zero" do
- [2, -4, 10**70, -10**100].each do |v|
- v.send(@method, 0).should eql(v)
- end
+ it "returns self if passed a precision of zero" do
+ [2, -4, 10**70, -10**100].each do |v|
+ v.send(@method, 0).should eql(v)
end
end
diff --git a/spec/ruby/core/integer/truncate_spec.rb b/spec/ruby/core/integer/truncate_spec.rb
index 761a3dbd31..db16e74be4 100644
--- a/spec/ruby/core/integer/truncate_spec.rb
+++ b/spec/ruby/core/integer/truncate_spec.rb
@@ -6,16 +6,14 @@ describe "Integer#truncate" do
it_behaves_like :integer_to_i, :truncate
it_behaves_like :integer_rounding_positive_precision, :truncate
- ruby_version_is "2.4" do
- context "precision argument specified as part of the truncate method is negative" do
- it "returns an integer with at least precision.abs trailing zeros" do
- 1832.truncate(-1).should eql(1830)
- 1832.truncate(-2).should eql(1800)
- 1832.truncate(-3).should eql(1000)
- -1832.truncate(-1).should eql(-1830)
- -1832.truncate(-2).should eql(-1800)
- -1832.truncate(-3).should eql(-1000)
- end
+ context "precision argument specified as part of the truncate method is negative" do
+ it "returns an integer with at least precision.abs trailing zeros" do
+ 1832.truncate(-1).should eql(1830)
+ 1832.truncate(-2).should eql(1800)
+ 1832.truncate(-3).should eql(1000)
+ -1832.truncate(-1).should eql(-1830)
+ -1832.truncate(-2).should eql(-1800)
+ -1832.truncate(-3).should eql(-1000)
end
end
end
diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb
index b22b226beb..525c7547cd 100644
--- a/spec/ruby/core/io/gets_spec.rb
+++ b/spec/ruby/core/io/gets_spec.rb
@@ -139,11 +139,9 @@ describe "IO#gets" do
end
end
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "returns the first line without a trailing newline character" do
- @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
- end
+ describe "when passed chomp" do
+ it "returns the first line without a trailing newline character" do
+ @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
end
end
end
diff --git a/spec/ruby/core/io/readline_spec.rb b/spec/ruby/core/io/readline_spec.rb
index f82ba36a1d..3eae6bfa47 100644
--- a/spec/ruby/core/io/readline_spec.rb
+++ b/spec/ruby/core/io/readline_spec.rb
@@ -43,11 +43,9 @@ describe "IO#readline" do
end
end
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "returns the first line without a trailing newline character" do
- @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
- end
+ describe "when passed chomp" do
+ it "returns the first line without a trailing newline character" do
+ @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
end
end
end
diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb
index ac01a49df1..da562e03b1 100644
--- a/spec/ruby/core/io/shared/each.rb
+++ b/spec/ruby/core/io/shared/each.rb
@@ -156,12 +156,10 @@ describe :io_each, shared: true do
end
end
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "yields each line without trailing newline characters to the passed block" do
- @io.send(@method, chomp: true) { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
- end
+ describe "when passed chomp" do
+ it "yields each line without trailing newline characters to the passed block" do
+ @io.send(@method, chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
end
end
end
diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb
index f545d8876a..08d41e0a4c 100644
--- a/spec/ruby/core/io/shared/readlines.rb
+++ b/spec/ruby/core/io/shared/readlines.rb
@@ -18,11 +18,9 @@ describe :io_readlines, shared: true do
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_empty_separator
end
- ruby_version_is "2.4" do
- it "yields a sequence of lines without trailing newline characters when chomp is passed" do
- result = IO.send(@method, @name, chomp: true, &@object)
- (result ? result : ScratchPad.recorded).should == IOSpecs.lines_without_newline_characters
- end
+ it "yields a sequence of lines without trailing newline characters when chomp is passed" do
+ result = IO.send(@method, @name, chomp: true, &@object)
+ (result ? result : ScratchPad.recorded).should == IOSpecs.lines_without_newline_characters
end
end
diff --git a/spec/ruby/core/kernel/Complex_spec.rb b/spec/ruby/core/kernel/Complex_spec.rb
index e5435a56e6..cb90718759 100644
--- a/spec/ruby/core/kernel/Complex_spec.rb
+++ b/spec/ruby/core/kernel/Complex_spec.rb
@@ -175,13 +175,11 @@ describe "Kernel.Complex()" do
end
end
- ruby_bug "#15525", "2.6"..."2.6.1" do
- describe "and nil arguments" do
- it "swallows an error" do
- Complex(nil, exception: false).should == nil
- Complex(0, nil, exception: false).should == nil
- Complex(nil, 0, exception: false).should == nil
- end
+ describe "and nil arguments" do
+ it "swallows an error" do
+ Complex(nil, exception: false).should == nil
+ Complex(0, nil, exception: false).should == nil
+ Complex(nil, 0, exception: false).should == nil
end
end
end
diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb
index 72e33fc737..b7e05e701b 100644
--- a/spec/ruby/core/kernel/Integer_spec.rb
+++ b/spec/ruby/core/kernel/Integer_spec.rb
@@ -125,17 +125,15 @@ describe :kernel_integer, shared: true do
end
end
- ruby_bug "#15525", "2.6"..."2.6.1" do
- describe "and passed NaN" do
- it "swallows an error" do
- Integer(nan_value, exception: false).should == nil
- end
+ describe "and passed NaN" do
+ it "swallows an error" do
+ Integer(nan_value, exception: false).should == nil
end
+ end
- describe "and passed Infinity" do
- it "swallows an error" do
- Integer(infinity_value, exception: false).should == nil
- end
+ describe "and passed Infinity" do
+ it "swallows an error" do
+ Integer(infinity_value, exception: false).should == nil
end
end
diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb
index ed426c2927..eb8739d571 100644
--- a/spec/ruby/core/kernel/clone_spec.rb
+++ b/spec/ruby/core/kernel/clone_spec.rb
@@ -37,14 +37,12 @@ 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
+ 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
it "copies instance variables" do
diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb
index 116989958b..37890f2981 100644
--- a/spec/ruby/core/kernel/shared/dup_clone.rb
+++ b/spec/ruby/core/kernel/shared/dup_clone.rb
@@ -79,48 +79,24 @@ describe :kernel_dup_clone, shared: true do
o3.untrusted?.should == true
end
- ruby_version_is ''...'2.4' do
- it "raises a TypeError for NilClass" do
- lambda { nil.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for TrueClass" do
- lambda { true.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for FalseClass" do
- lambda { false.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for Fixnum" do
- lambda { 1.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for Symbol" do
- lambda { :my_symbol.send(@method) }.should raise_error(TypeError)
- end
+ it "returns nil for NilClass" do
+ nil.send(@method).should == nil
end
- ruby_version_is '2.4' do
- it "returns nil for NilClass" do
- nil.send(@method).should == nil
- end
-
- it "returns true for TrueClass" do
- true.send(@method).should == true
- end
+ it "returns true for TrueClass" do
+ true.send(@method).should == true
+ end
- it "returns false for FalseClass" do
- false.send(@method).should == false
- end
+ it "returns false for FalseClass" do
+ false.send(@method).should == false
+ end
- it "returns the same Integer for Integer" do
- 1.send(@method).should == 1
- end
+ it "returns the same Integer for Integer" do
+ 1.send(@method).should == 1
+ end
- it "returns the same Symbol for Symbol" do
- :my_symbol.send(@method).should == :my_symbol
- end
+ it "returns the same Symbol for Symbol" do
+ :my_symbol.send(@method).should == :my_symbol
end
ruby_version_is ''...'2.5' do
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index b502476bc3..56377684fb 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -553,6 +553,15 @@ describe :kernel_require, shared: true do
required = ruby_exe(code, options: '--disable-gems')
required.should == "false\n" * provided.size
end
+
+ it "unicode_normalize is part of core and not $LOADED_FEATURES" do
+ features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
+ features.lines.each { |feature|
+ feature.should_not include("unicode_normalize")
+ }
+
+ -> { @object.require("unicode_normalize") }.should raise_error(LoadError)
+ end
end
end
diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb
index 0b461ec25a..7e0a57fa9a 100644
--- a/spec/ruby/core/kernel/warn_spec.rb
+++ b/spec/ruby/core/kernel/warn_spec.rb
@@ -101,11 +101,9 @@ describe "Kernel#warn" do
-> { w.f4("foo", 3) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f3_call_lineno}: warning: foo|)
end
- ruby_bug "#14846", "2.5"..."2.6" do
- it "does not prepend caller information if line number is too big" do
- w = KernelSpecs::WarnInNestedCall.new
- -> { w.f4("foo", 100) }.should output(nil, "warning: foo\n")
- end
+ it "does not prepend caller information if line number is too big" do
+ w = KernelSpecs::WarnInNestedCall.new
+ -> { w.f4("foo", 100) }.should output(nil, "warning: foo\n")
end
it "prepends even if a message is empty or nil" do
@@ -127,10 +125,8 @@ describe "Kernel#warn" do
-> { warn "", uplevel: -100 }.should raise_error(ArgumentError)
end
- ruby_bug "#14846", "2.5"..."2.6" do
- it "raises ArgumentError if passed -1" do
- -> { warn "", uplevel: -1 }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError if passed -1" do
+ -> { warn "", uplevel: -1 }.should raise_error(ArgumentError)
end
it "raises TypeError if passed not Integer" do
diff --git a/spec/ruby/core/matchdata/named_captures_spec.rb b/spec/ruby/core/matchdata/named_captures_spec.rb
index 0b0771355f..9b1e324a24 100644
--- a/spec/ruby/core/matchdata/named_captures_spec.rb
+++ b/spec/ruby/core/matchdata/named_captures_spec.rb
@@ -1,17 +1,15 @@
require_relative '../../spec_helper'
-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
+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
+ it 'prefers later captures' do
+ /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
+ end
- it 'returns the latest matched capture, even if a later one that does not match exists' do
- /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' }
- end
+ it 'returns the latest matched capture, even if a later one that does not match exists' do
+ /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' }
end
end
diff --git a/spec/ruby/core/matchdata/values_at_spec.rb b/spec/ruby/core/matchdata/values_at_spec.rb
index af844904f6..8f7fdf557c 100644
--- a/spec/ruby/core/matchdata/values_at_spec.rb
+++ b/spec/ruby/core/matchdata/values_at_spec.rb
@@ -11,13 +11,11 @@ describe "MatchData#values_at" do
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 '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
+ 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
diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb
index 7104f2aa21..a20d0a4f2f 100644
--- a/spec/ruby/core/math/lgamma_spec.rb
+++ b/spec/ruby/core/math/lgamma_spec.rb
@@ -11,10 +11,8 @@ describe "Math.lgamma" do
end
end
- ruby_version_is "2.4" do
- it "returns [Infinity, -1] when passed -0.0" do
- Math.lgamma(-0.0).should == [infinity_value, -1]
- end
+ it "returns [Infinity, -1] when passed -0.0" do
+ Math.lgamma(-0.0).should == [infinity_value, -1]
end
it "returns [log(sqrt(PI)), 1] when passed 0.5" do
diff --git a/spec/ruby/core/method/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb
index 750abe13d0..1de3901040 100644
--- a/spec/ruby/core/method/parameters_spec.rb
+++ b/spec/ruby/core/method/parameters_spec.rb
@@ -243,17 +243,19 @@ describe "Method#parameters" do
end
it "returns [[:rest]] for core methods with variable-length argument lists" do
- m = "foo"
-
- # match takes rest args
- m.method(:match).parameters.should == [[:rest]]
+ # delete! takes rest args
+ "foo".method(:delete!).parameters.should == [[:rest]]
+ end
- # [] takes 1 to 3 args
- m.method(:[]).parameters.should == [[:rest]]
+ it "returns [[:rest]] or [[:opt]] for core methods with optional arguments" do
+ # pop takes 1 optional argument
+ [
+ [[:rest]],
+ [[:opt]]
+ ].should include([].method(:pop).parameters)
end
it "returns [[:req]] for each parameter for core methods with fixed-length argument lists" do
- m = "foo"
- m.method(:+).parameters.should == [[:req]]
+ "foo".method(:+).parameters.should == [[:req]]
end
end
diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb
index 2a31afa59a..ece86bfe00 100644
--- a/spec/ruby/core/module/include_spec.rb
+++ b/spec/ruby/core/module/include_spec.rb
@@ -165,24 +165,12 @@ describe "Module#include" do
}.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.4' do
- it "accepts no-arguments" do
- lambda {
- Module.new do
- include
- end
- }.should_not raise_error
- end
- end
-
- ruby_version_is '2.4' do
- it "doesn't accept no-arguments" do
- lambda {
- Module.new do
- include
- end
- }.should raise_error(ArgumentError)
- end
+ it "doesn't accept no-arguments" do
+ lambda {
+ Module.new do
+ include
+ end
+ }.should raise_error(ArgumentError)
end
it "returns the class it's included into" do
diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb
index ca80eb360f..b186381640 100644
--- a/spec/ruby/core/module/prepend_spec.rb
+++ b/spec/ruby/core/module/prepend_spec.rb
@@ -231,24 +231,12 @@ describe "Module#prepend" do
}.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.4' do
- it "accepts no-arguments" do
- lambda {
- Module.new do
- prepend
- end
- }.should_not raise_error
- end
- end
-
- ruby_version_is '2.4' do
- it "doesn't accept no-arguments" do
- lambda {
- Module.new do
- prepend
- end
- }.should raise_error(ArgumentError)
- end
+ it "doesn't accept no-arguments" do
+ lambda {
+ Module.new do
+ prepend
+ end
+ }.should raise_error(ArgumentError)
end
it "returns the class it's included into" do
diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb
index d476c6f54e..5d85c34855 100644
--- a/spec/ruby/core/module/private_spec.rb
+++ b/spec/ruby/core/module/private_spec.rb
@@ -52,44 +52,42 @@ describe "Module#private" do
end.should raise_error(NameError)
end
- ruby_bug "#14604", ""..."2.5.1" do
- it "only makes the method private in the class it is called on" do
- base = Class.new do
- def wrapped
- 1
- end
+ it "only makes the method private in the class it is called on" do
+ base = Class.new do
+ def wrapped
+ 1
end
+ end
- klass = Class.new(base) do
- def wrapped
- super + 1
- end
- private :wrapped
+ klass = Class.new(base) do
+ def wrapped
+ super + 1
end
-
- base.new.wrapped.should == 1
- lambda do
- klass.new.wrapped
- end.should raise_error(NameError)
+ private :wrapped
end
- it "continues to allow a prepended module method to call super" do
- wrapper = Module.new do
- def wrapped
- super + 1
- end
+ base.new.wrapped.should == 1
+ lambda do
+ klass.new.wrapped
+ end.should raise_error(NameError)
+ end
+
+ it "continues to allow a prepended module method to call super" do
+ wrapper = Module.new do
+ def wrapped
+ super + 1
end
+ end
- klass = Class.new do
- prepend wrapper
+ klass = Class.new do
+ prepend wrapper
- def wrapped
- 1
- end
- private :wrapped
+ def wrapped
+ 1
end
-
- klass.new.wrapped.should == 2
+ private :wrapped
end
+
+ klass.new.wrapped.should == 2
end
end
diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb
index 4f34062343..7a1b2fc5fc 100644
--- a/spec/ruby/core/module/refine_spec.rb
+++ b/spec/ruby/core/module/refine_spec.rb
@@ -74,29 +74,17 @@ describe "Module#refine" do
end.should raise_error(TypeError)
end
- ruby_version_is "" ... "2.4" do
- it "raises TypeError if passed a module" do
- lambda do
- Module.new do
- refine(Enumerable) {}
- end
- end.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.4" do
- it "accepts a module as argument" do
- inner_self = nil
- Module.new do
- refine(Enumerable) do
- def blah
- end
- inner_self = self
+ it "accepts a module as argument" do
+ inner_self = nil
+ Module.new do
+ refine(Enumerable) do
+ def blah
end
+ inner_self = self
end
-
- inner_self.public_instance_methods.should include(:blah)
end
+
+ inner_self.public_instance_methods.should include(:blah)
end
it "raises ArgumentError if not given a block" do
@@ -319,108 +307,54 @@ describe "Module#refine" do
end
context "for methods accessed indirectly" do
- ruby_version_is "" ... "2.4" do
- it "is not honored by Kernel#send" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.send :foo
+ it "is honored by Kernel#send" do
+ refinement = Module.new do
+ refine ModuleSpecs::ClassWithFoo do
+ def foo; "foo from refinement"; end
end
-
- result.should == "foo"
end
- it "is not honored by BasicObject#__send__" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.__send__ :foo
- end
-
- result.should == "foo"
+ result = nil
+ Module.new do
+ using refinement
+ result = ModuleSpecs::ClassWithFoo.new.send :foo
end
- it "is not honored by Symbol#to_proc" do
- refinement = Module.new do
- refine Integer do
- def to_s
- "(#{super})"
- end
- end
- end
+ result.should == "foo from refinement"
+ end
- result = nil
- Module.new do
- using refinement
- result = [1, 2, 3].map(&:to_s)
+ it "is honored by BasicObject#__send__" do
+ refinement = Module.new do
+ refine ModuleSpecs::ClassWithFoo do
+ def foo; "foo from refinement"; end
end
+ end
- result.should == ["1", "2", "3"]
+ result = nil
+ Module.new do
+ using refinement
+ result = ModuleSpecs::ClassWithFoo.new.__send__ :foo
end
+
+ result.should == "foo from refinement"
end
- ruby_version_is "2.4" do
- it "is honored by Kernel#send" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
+ it "is honored by Symbol#to_proc" do
+ refinement = Module.new do
+ refine Integer do
+ def to_s
+ "(#{super})"
end
end
-
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.send :foo
- end
-
- result.should == "foo from refinement"
end
- it "is honored by BasicObject#__send__" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.__send__ :foo
- end
-
- result.should == "foo from refinement"
+ result = nil
+ Module.new do
+ using refinement
+ result = [1, 2, 3].map(&:to_s)
end
- it "is honored by Symbol#to_proc" do
- refinement = Module.new do
- refine Integer do
- def to_s
- "(#{super})"
- end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = [1, 2, 3].map(&:to_s)
- end
-
- result.should == ["(1)", "(2)", "(3)"]
- end
+ result.should == ["(1)", "(2)", "(3)"]
end
ruby_version_is "" ... "2.6" do
diff --git a/spec/ruby/core/nil/dup_spec.rb b/spec/ruby/core/nil/dup_spec.rb
index 21b2c92220..0324b3f1f4 100644
--- a/spec/ruby/core/nil/dup_spec.rb
+++ b/spec/ruby/core/nil/dup_spec.rb
@@ -1,9 +1,7 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "NilClass#dup" do
- it "returns self" do
- nil.dup.should equal(nil)
- end
+describe "NilClass#dup" do
+ it "returns self" do
+ nil.dup.should equal(nil)
end
end
diff --git a/spec/ruby/core/numeric/finite_spec.rb b/spec/ruby/core/numeric/finite_spec.rb
index a4df23602b..05b5eebbd6 100644
--- a/spec/ruby/core/numeric/finite_spec.rb
+++ b/spec/ruby/core/numeric/finite_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#finite?" do
- it "returns true by default" do
- o = mock_numeric("finite")
- o.finite?.should be_true
- end
+describe "Numeric#finite?" do
+ it "returns true by default" do
+ o = mock_numeric("finite")
+ o.finite?.should be_true
end
end
diff --git a/spec/ruby/core/numeric/infinite_spec.rb b/spec/ruby/core/numeric/infinite_spec.rb
index 7ed2f6d125..3ea7825c8c 100644
--- a/spec/ruby/core/numeric/infinite_spec.rb
+++ b/spec/ruby/core/numeric/infinite_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#infinite?" do
- it "returns nil by default" do
- o = mock_numeric("infinite")
- o.infinite?.should == nil
- end
+describe "Numeric#infinite?" do
+ it "returns nil by default" do
+ o = mock_numeric("infinite")
+ o.infinite?.should == nil
end
end
diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb
index 066f499dc5..5dcaa4b253 100644
--- a/spec/ruby/core/numeric/shared/step.rb
+++ b/spec/ruby/core/numeric/shared/step.rb
@@ -224,9 +224,6 @@ describe :numeric_step, :shared => true do
describe "when step is a String" do
error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
ruby_version_is "2.4"..."2.5" do
error = TypeError
end
@@ -305,9 +302,6 @@ describe :numeric_step, :shared => true do
describe "size" do
describe "when step is a String" do
error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
ruby_version_is "2.4"..."2.5" do
error = TypeError
end
diff --git a/spec/ruby/core/objectspace/each_object_spec.rb b/spec/ruby/core/objectspace/each_object_spec.rb
index c827867fdc..09a582afaf 100644
--- a/spec/ruby/core/objectspace/each_object_spec.rb
+++ b/spec/ruby/core/objectspace/each_object_spec.rb
@@ -201,7 +201,6 @@ describe "ObjectSpace.each_object" do
expected = [ a, b, c, d ]
- # singleton classes should be walked only on >= 2.3
expected << c_sclass
c_sclass.should be_kind_of(a.singleton_class)
diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb
index f60ae1b086..9077e44c34 100644
--- a/spec/ruby/core/proc/element_reference_spec.rb
+++ b/spec/ruby/core/proc/element_reference_spec.rb
@@ -17,13 +17,11 @@ describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
it_behaves_like :proc_call_on_proc_or_lambda, :call
end
-ruby_bug "#15118", ""..."2.6" do
- describe "Proc#[] with frozen_string_literals" do
- it "doesn't duplicate frozen strings" do
- ProcArefSpecs.aref.frozen?.should be_false
- ProcArefSpecs.aref_freeze.frozen?.should be_true
- ProcArefFrozenSpecs.aref.frozen?.should be_true
- ProcArefFrozenSpecs.aref_freeze.frozen?.should be_true
- end
+describe "Proc#[] with frozen_string_literals" do
+ it "doesn't duplicate frozen strings" do
+ ProcArefSpecs.aref.frozen?.should be_false
+ ProcArefSpecs.aref_freeze.frozen?.should be_true
+ ProcArefFrozenSpecs.aref.frozen?.should be_true
+ ProcArefFrozenSpecs.aref_freeze.frozen?.should be_true
end
end
diff --git a/spec/ruby/core/process/clock_getres_spec.rb b/spec/ruby/core/process/clock_getres_spec.rb
new file mode 100644
index 0000000000..35180bc81b
--- /dev/null
+++ b/spec/ruby/core/process/clock_getres_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/clocks'
+
+describe "Process.clock_getres" do
+ ProcessSpecs.clock_constants.each do |name, value|
+ it "matches the clock in practice for Process::#{name}" do
+ times = []
+ 10_000.times do
+ times << Process.clock_gettime(value, :nanosecond)
+ end
+ reported = Process.clock_getres(value, :nanosecond)
+
+ # The clock should not be more accurate than reported (times should be
+ # a multiple of reported precision.)
+ times.select { |t| t % reported > 0 }.should be_empty
+
+ # We're assuming precision is a multiple of ten - it may or may not
+ # be an incompatibility if it isn't but we'd like to notice this,
+ # and the spec following these wouldn't work if it isn't.
+ reported.should > 0
+ (reported == 1 || reported % 10 == 0).should be_true
+
+ # The clock should not be less accurate than reported (times should
+ # not all be a multiple of the next precision up, assuming precisions
+ # are multiples of ten.)
+ times.select { |t| t % (reported * 10) == 0 }.size.should_not == times.size
+ end
+ end
+
+ # These are documented
+
+ it "with :GETTIMEOFDAY_BASED_CLOCK_REALTIME reports 1 microsecond" do
+ Process.clock_getres(:GETTIMEOFDAY_BASED_CLOCK_REALTIME, :nanosecond).should == 1_000
+ end
+
+ it "with :TIME_BASED_CLOCK_REALTIME reports 1 second" do
+ Process.clock_getres(:TIME_BASED_CLOCK_REALTIME, :nanosecond).should == 1_000_000_000
+ end
+
+ platform_is_not :windows do
+ it "with :GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID reports 1 microsecond" do
+ Process.clock_getres(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID, :nanosecond).should == 1_000
+ end
+ end
+
+ # These are observed
+
+ it "with Process::CLOCK_REALTIME reports at least 1 microsecond" do
+ Process.clock_getres(Process::CLOCK_REALTIME, :nanosecond).should <= 1_000
+ end
+
+ it "with Process::CLOCK_MONOTONIC reports at least 1 microsecond" do
+ Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond).should <= 1_000
+ end
+end
diff --git a/spec/ruby/core/process/clock_gettime_spec.rb b/spec/ruby/core/process/clock_gettime_spec.rb
index a7b6bd2b02..4cd13857ea 100644
--- a/spec/ruby/core/process/clock_gettime_spec.rb
+++ b/spec/ruby/core/process/clock_gettime_spec.rb
@@ -1,18 +1,10 @@
require_relative '../../spec_helper'
+require_relative 'fixtures/clocks'
describe "Process.clock_gettime" do
- platform_is_not :windows, :solaris do
- Process.constants.select { |c|
- c.to_s.start_with?('CLOCK_') &&
- # These require CAP_WAKE_ALARM and are not documented in clock_gettime(),
- # they return EINVAL if the permission is not granted.
- c != :CLOCK_BOOTTIME_ALARM &&
- c != :CLOCK_REALTIME_ALARM
- }.each do |c|
- it "can be called with Process::#{c}" do
- value = Process.const_get(c)
- Process.clock_gettime(value).should be_an_instance_of(Float)
- end
+ ProcessSpecs.clock_constants.each do |name, value|
+ it "can be called with Process::#{name}" do
+ Process.clock_gettime(value).should be_an_instance_of(Float)
end
end
@@ -36,7 +28,8 @@ describe "Process.clock_gettime" do
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
t1.should be_an_instance_of(Float)
- t2.should be_close(t1, 2.0) # 2.0 is chosen arbitrarily to allow for time skew without admitting failure cases, which would be off by an order of magnitude.
+ t2.should be_an_instance_of(Float)
+ t2.should be_close(t1, TIME_TOLERANCE)
end
it 'uses the default time unit (:float_second) when passed nil' do
@@ -44,7 +37,8 @@ describe "Process.clock_gettime" do
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
t1.should be_an_instance_of(Float)
- t2.should be_close(t1, 2.0) # 2.0 is chosen arbitrarily to allow for time skew without admitting failure cases, which would be off by an order of magnitude.
+ t2.should be_an_instance_of(Float)
+ t2.should be_close(t1, TIME_TOLERANCE)
end
end
end
diff --git a/spec/ruby/core/process/fixtures/clocks.rb b/spec/ruby/core/process/fixtures/clocks.rb
new file mode 100644
index 0000000000..5f45e8065b
--- /dev/null
+++ b/spec/ruby/core/process/fixtures/clocks.rb
@@ -0,0 +1,24 @@
+module ProcessSpecs
+ def self.clock_constants
+ clocks = []
+
+ platform_is_not :windows, :solaris do
+ clocks += Process.constants.select { |c| c.to_s.start_with?('CLOCK_') }
+
+ # These require CAP_WAKE_ALARM and are not documented in
+ # Process#clock_gettime they return EINVAL if the permission
+ # is not granted.
+ clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM]
+
+ # These clocks in practice on Linux do not seem to match
+ # their reported resolution.
+ clocks -= [:CLOCK_REALTIME_COARSE, :CLOCK_MONOTONIC_COARSE]
+
+ clocks.map! { |c|
+ [c, Process.const_get(c)]
+ }
+ end
+
+ clocks
+ end
+end
diff --git a/spec/ruby/core/process/wait2_spec.rb b/spec/ruby/core/process/wait2_spec.rb
index d0163f80af..18bf4be432 100644
--- a/spec/ruby/core/process/wait2_spec.rb
+++ b/spec/ruby/core/process/wait2_spec.rb
@@ -13,10 +13,8 @@ describe "Process.wait2" do
end
leaked = Process.waitall
$stderr.puts "leaked before wait2 specs: #{leaked}" unless leaked.empty?
- with_feature :mjit do
- # Ruby-space should not see PIDs used by mjit
- leaked.should be_empty
- end
+ # Ruby-space should not see PIDs used by mjit
+ leaked.should be_empty
rescue Errno::ECHILD # No child processes
rescue NotImplementedError
end
diff --git a/spec/ruby/core/process/wait_spec.rb b/spec/ruby/core/process/wait_spec.rb
index 099fcdc518..000ff684d4 100644
--- a/spec/ruby/core/process/wait_spec.rb
+++ b/spec/ruby/core/process/wait_spec.rb
@@ -8,10 +8,8 @@ describe "Process.wait" do
begin
leaked = Process.waitall
puts "leaked before wait specs: #{leaked}" unless leaked.empty?
- with_feature :mjit do
- # Ruby-space should not see PIDs used by mjit
- leaked.should be_empty
- end
+ # Ruby-space should not see PIDs used by mjit
+ leaked.should be_empty
rescue NotImplementedError
end
end
diff --git a/spec/ruby/core/rational/round_spec.rb b/spec/ruby/core/rational/round_spec.rb
index deb0caf1b9..36614a552d 100644
--- a/spec/ruby/core/rational/round_spec.rb
+++ b/spec/ruby/core/rational/round_spec.rb
@@ -1,3 +1,4 @@
+require_relative '../../spec_helper'
require_relative '../../shared/rational/round'
describe "Rational#round" do
diff --git a/spec/ruby/core/regexp/match_spec.rb b/spec/ruby/core/regexp/match_spec.rb
index edac0d1d42..45ed4a5932 100644
--- a/spec/ruby/core/regexp/match_spec.rb
+++ b/spec/ruby/core/regexp/match_spec.rb
@@ -111,32 +111,30 @@ describe "Regexp#match" do
end
end
-ruby_version_is "2.4" do
- describe "Regexp#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "Regexp#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given value" do
- it "returns true but does not set Regexp.last_match" do
- /string/i.match?('string').should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given value" do
+ it "returns true but does not set Regexp.last_match" do
+ /string/i.match?('string').should be_true
+ Regexp.last_match.should be_nil
end
+ end
- it "returns false when does not match the given value" do
- /STRING/.match?('string').should be_false
- end
+ it "returns false when does not match the given value" do
+ /STRING/.match?('string').should be_false
+ end
- it "takes matching position as the 2nd argument" do
- /str/i.match?('string', 0).should be_true
- /str/i.match?('string', 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ /str/i.match?('string', 0).should be_true
+ /str/i.match?('string', 1).should be_false
+ end
- it "returns false when given nil" do
- /./.match?(nil).should be_false
- end
+ it "returns false when given nil" do
+ /./.match?(nil).should be_false
end
end
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb
index 10f9ab00a1..c7f4aed20c 100644
--- a/spec/ruby/core/string/capitalize_spec.rb
+++ b/spec/ruby/core/string/capitalize_spec.rb
@@ -17,77 +17,67 @@ describe "String#capitalize" do
"hello".taint.capitalize.tainted?.should == true
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
- "ÄÖÜ".capitalize.should == "ÄÖÜ"
- "ärger".capitalize.should == "ärger"
- "BÄR".capitalize.should == "BÄr"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöÜ".capitalize.should == "Äöü"
end
- end
-
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "works for all of Unicode with no option" do
- "äöÜ".capitalize.should == "Äöü"
- end
- it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
- "ß".capitalize.should == "Ss"
- end
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ "ß".capitalize.should == "Ss"
+ end
- it "updates string metadata" do
- capitalized = "ßeT".capitalize
+ it "updates string metadata" do
+ capitalized = "ßeT".capitalize
- capitalized.should == "Sset"
- capitalized.size.should == 4
- capitalized.bytesize.should == 4
- capitalized.ascii_only?.should be_true
- end
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should be_true
end
+ end
- describe "ASCII-only case mapping" do
- it "does not capitalize non-ASCII characters" do
- "ßet".capitalize(:ascii).should == "ßet"
- end
+ describe "ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ "ßet".capitalize(:ascii).should == "ßet"
end
+ end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "capitalizes ASCII characters according to Turkic semantics" do
- "iSa".capitalize(:turkic).should == "İsa"
- end
-
- it "allows Lithuanian as an extra option" do
- "iSa".capitalize(:turkic, :lithuanian).should == "İsa"
- end
-
- it "does not allow any other additional option" do
- lambda { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ "iSa".capitalize(:turkic).should == "İsa"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- "iß".capitalize(:lithuanian).should == "Iß"
- end
+ it "allows Lithuanian as an extra option" do
+ "iSa".capitalize(:turkic, :lithuanian).should == "İsa"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- "iß".capitalize(:lithuanian, :turkic).should == "İß"
- end
+ it "does not allow any other additional option" do
+ lambda { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".capitalize(:lithuanian).should == "Iß"
end
- it "does not allow the :fold option for upcasing" do
- lambda { "abc".capitalize(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".capitalize(:lithuanian, :turkic).should == "İß"
end
- it "does not allow invalid options" do
- lambda { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".capitalize(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "returns subclass instances when called on a subclass" do
StringSpecs::MyString.new("hello").capitalize.should be_an_instance_of(StringSpecs::MyString)
StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(StringSpecs::MyString)
@@ -101,84 +91,82 @@ describe "String#capitalize!" do
a.should == "Hello"
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "modifies self in place for all of Unicode with no option" do
- a = "äöÜ"
- a.capitalize!
- a.should == "Äöü"
- end
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äöÜ"
+ a.capitalize!
+ a.should == "Äöü"
+ end
- it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
- a = "ß"
- a.capitalize!
- a.should == "Ss"
- end
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ a = "ß"
+ a.capitalize!
+ a.should == "Ss"
+ end
- it "updates string metadata" do
- capitalized = "ßeT"
- capitalized.capitalize!
+ it "updates string metadata" do
+ capitalized = "ßeT"
+ capitalized.capitalize!
- capitalized.should == "Sset"
- capitalized.size.should == 4
- capitalized.bytesize.should == 4
- capitalized.ascii_only?.should be_true
- end
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should be_true
end
+ end
- describe "modifies self in place for ASCII-only case mapping" do
- it "does not capitalize non-ASCII characters" do
- a = "ßet"
- a.capitalize!(:ascii)
- a.should == "ßet"
- end
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ a = "ßet"
+ a.capitalize!(:ascii)
+ a.should == "ßet"
end
+ end
- describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
- it "capitalizes ASCII characters according to Turkic semantics" do
- a = "iSa"
- a.capitalize!(:turkic)
- a.should == "İsa"
- end
-
- it "allows Lithuanian as an extra option" do
- a = "iSa"
- a.capitalize!(:turkic, :lithuanian)
- a.should == "İsa"
- end
-
- it "does not allow any other additional option" do
- lambda { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ a = "iSa"
+ a.capitalize!(:turkic)
+ a.should == "İsa"
end
- describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- a = "iß"
- a.capitalize!(:lithuanian)
- a.should == "Iß"
- end
+ it "allows Lithuanian as an extra option" do
+ a = "iSa"
+ a.capitalize!(:turkic, :lithuanian)
+ a.should == "İsa"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- a = "iß"
- a.capitalize!(:lithuanian, :turkic)
- a.should == "İß"
- end
+ it "does not allow any other additional option" do
+ lambda { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "iß"
+ a.capitalize!(:lithuanian)
+ a.should == "Iß"
end
- it "does not allow the :fold option for upcasing" do
- lambda { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iß"
+ a.capitalize!(:lithuanian, :turkic)
+ a.should == "İß"
end
- it "does not allow invalid options" do
- lambda { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "returns nil when no changes are made" do
a = "Hello"
a.capitalize!.should == nil
diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb
index 87be999964..35afcc0152 100644
--- a/spec/ruby/core/string/casecmp_spec.rb
+++ b/spec/ruby/core/string/casecmp_spec.rb
@@ -101,10 +101,8 @@ describe "String#casecmp independent of case" do
@lower_a_tilde.casecmp(@upper_a_tilde).should == 1
end
- ruby_version_is "2.4" do
- it "does not case fold" do
- "ß".casecmp("ss").should == 1
- end
+ it "does not case fold" do
+ "ß".casecmp("ss").should == 1
end
end
@@ -129,88 +127,84 @@ describe "String#casecmp independent of case" do
end
end
-ruby_version_is "2.4" do
- describe 'String#casecmp? independent of case' do
- it 'returns true when equal to other' do
- 'abc'.casecmp?('abc').should == true
- 'abc'.casecmp?('ABC').should == true
- end
+describe 'String#casecmp? independent of case' do
+ it 'returns true when equal to other' do
+ 'abc'.casecmp?('abc').should == true
+ 'abc'.casecmp?('ABC').should == true
+ end
- it 'returns false when not equal to other' do
- 'abc'.casecmp?('DEF').should == false
- 'abc'.casecmp?('def').should == false
- end
+ it 'returns false when not equal to other' do
+ 'abc'.casecmp?('DEF').should == false
+ 'abc'.casecmp?('def').should == false
+ end
+
+ it "tries to convert other to string using to_str" do
+ other = mock('x')
+ other.should_receive(:to_str).and_return("abc")
- it "tries to convert other to string using to_str" do
- other = mock('x')
- other.should_receive(:to_str).and_return("abc")
+ "abc".casecmp?(other).should == true
+ end
+
+ it "returns nil if incompatible encodings" do
+ "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should be_nil
+ end
- "abc".casecmp?(other).should == true
+ describe 'for UNICODE characters' do
+ it 'returns true when downcase(:fold) on unicode' do
+ 'äöü'.casecmp?('ÄÖÜ').should == true
end
+ end
- it "returns nil if incompatible encodings" do
- "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should be_nil
+ describe "when comparing a subclass instance" do
+ it 'returns true when equal to other' do
+ a = StringSpecs::MyString.new "a"
+ 'a'.casecmp?(a).should == true
+ 'A'.casecmp?(a).should == true
end
- describe 'for UNICODE characters' do
- it 'returns true when downcase(:fold) on unicode' do
- 'äöü'.casecmp?('ÄÖÜ').should == true
- end
+ it 'returns false when not equal to other' do
+ b = StringSpecs::MyString.new "a"
+ 'b'.casecmp?(b).should == false
+ 'B'.casecmp?(b).should == false
end
+ end
- describe "when comparing a subclass instance" do
- it 'returns true when equal to other' do
- a = StringSpecs::MyString.new "a"
- 'a'.casecmp?(a).should == true
- 'A'.casecmp?(a).should == true
+ describe "in UTF-8 mode" do
+ describe "for non-ASCII characters" do
+ before :each do
+ @upper_a_tilde = "Ã"
+ @lower_a_tilde = "ã"
+ @upper_a_umlaut = "Ä"
+ @lower_a_umlaut = "ä"
end
- it 'returns false when not equal to other' do
- b = StringSpecs::MyString.new "a"
- 'b'.casecmp?(b).should == false
- 'B'.casecmp?(b).should == false
+ it "returns true when they are the same with normalized case" do
+ @upper_a_tilde.casecmp?(@lower_a_tilde).should == true
end
- end
-
- describe "in UTF-8 mode" do
- describe "for non-ASCII characters" do
- before :each do
- @upper_a_tilde = "Ã"
- @lower_a_tilde = "ã"
- @upper_a_umlaut = "Ä"
- @lower_a_umlaut = "ä"
- end
-
- it "returns true when they are the same with normalized case" do
- @upper_a_tilde.casecmp?(@lower_a_tilde).should == true
- end
-
- it "returns false when they are unrelated" do
- @upper_a_tilde.casecmp?(@upper_a_umlaut).should == false
- end
- it "returns true when they have the same bytes" do
- @upper_a_tilde.casecmp?(@upper_a_tilde).should == true
- end
+ it "returns false when they are unrelated" do
+ @upper_a_tilde.casecmp?(@upper_a_umlaut).should == false
end
- end
- ruby_version_is "2.4" do
- it "case folds" do
- "ß".casecmp?("ss").should be_true
+ it "returns true when they have the same bytes" do
+ @upper_a_tilde.casecmp?(@upper_a_tilde).should == true
end
end
+ end
- ruby_version_is "2.4" ... "2.5" do
- it "raises a TypeError if other can't be converted to a string" do
- lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError)
- end
+ it "case folds" do
+ "ß".casecmp?("ss").should be_true
+ end
+
+ ruby_version_is "2.4"..."2.5" do
+ it "raises a TypeError if other can't be converted to a string" do
+ lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError)
end
+ end
- ruby_version_is "2.5" do
- it "returns nil if other can't be converted to a string" do
- "abc".casecmp?(mock('abc')).should be_nil
- end
+ ruby_version_is "2.5" do
+ it "returns nil if other can't be converted to a string" do
+ "abc".casecmp?(mock('abc')).should be_nil
end
end
end
diff --git a/spec/ruby/core/string/concat_spec.rb b/spec/ruby/core/string/concat_spec.rb
index 27917d6c85..5f6daadad7 100644
--- a/spec/ruby/core/string/concat_spec.rb
+++ b/spec/ruby/core/string/concat_spec.rb
@@ -6,23 +6,21 @@ describe "String#concat" do
it_behaves_like :string_concat, :concat
it_behaves_like :string_concat_encoding, :concat
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- str = "hello "
- str.concat "wo", "", "rld"
- str.should == "hello world"
- end
+ it "takes multiple arguments" do
+ str = "hello "
+ str.concat "wo", "", "rld"
+ str.should == "hello world"
+ end
- it "concatenates the initial value when given arguments contain 2 self" do
- str = "hello"
- str.concat str, str
- str.should == "hellohellohello"
- end
+ it "concatenates the initial value when given arguments contain 2 self" do
+ str = "hello"
+ str.concat str, str
+ str.should == "hellohellohello"
+ end
- it "returns self when given no arguments" do
- str = "hello"
- str.concat.should equal(str)
- str.should == "hello"
- end
+ it "returns self when given no arguments" do
+ str = "hello"
+ str.concat.should equal(str)
+ str.should == "hello"
end
end
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 9fb93902b1..241bd8c147 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -8,82 +8,66 @@ describe "String#downcase" do
"hello".downcase.should == "hello"
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only replaces A-Z)" do
- "ÄÖÜ".downcase.should == "ÄÖÜ"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "ÄÖÜ".downcase.should == "äöü"
+ end
- str = Array.new(256) { |c| c.chr }.join
- expected = Array.new(256) do |i|
- c = i.chr
- c.between?("A", "Z") ? c.downcase : c
- end.join
+ it "updates string metadata" do
+ downcased = "\u{212A}ING".downcase
- str.downcase.should == expected
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should be_true
end
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "works for all of Unicode with no option" do
- "ÄÖÜ".downcase.should == "äöü"
- end
-
- it "updates string metadata" do
- downcased = "\u{212A}ING".downcase
-
- downcased.should == "king"
- downcased.size.should == 4
- downcased.bytesize.should == 4
- downcased.ascii_only?.should be_true
- end
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ "CÅR".downcase(:ascii).should == "cÅr"
end
+ end
- describe "ASCII-only case mapping" do
- it "does not downcase non-ASCII characters" do
- "CÅR".downcase(:ascii).should == "cÅr"
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ "İ".downcase(:turkic).should == "i"
end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "downcases characters according to Turkic semantics" do
- "İ".downcase(:turkic).should == "i"
- end
-
- it "allows Lithuanian as an extra option" do
- "İ".downcase(:turkic, :lithuanian).should == "i"
- end
-
- it "does not allow any other additional option" do
- lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ it "allows Lithuanian as an extra option" do
+ "İ".downcase(:turkic, :lithuanian).should == "i"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- "İS".downcase(:lithuanian).should == "i\u{307}s"
- end
+ it "does not allow any other additional option" do
+ lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- "İS".downcase(:lithuanian, :turkic).should == "is"
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "İS".downcase(:lithuanian).should == "i\u{307}s"
+ end
- it "does not allow any other additional option" do
- lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "İS".downcase(:lithuanian, :turkic).should == "is"
end
- describe "case folding" do
- it "case folds special characters" do
- "ß".downcase.should == "ß"
- "ß".downcase(:fold).should == "ss"
- end
+ it "does not allow any other additional option" do
+ lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
+ end
- it "does not allow invalid options" do
- lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
+ describe "case folding" do
+ it "case folds special characters" do
+ "ß".downcase.should == "ß"
+ "ß".downcase(:fold).should == "ss"
end
end
+ it "does not allow invalid options" do
+ lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "taints result when self is tainted" do
"".taint.downcase.tainted?.should == true
"x".taint.downcase.tainted?.should == true
@@ -102,83 +86,81 @@ describe "String#downcase!" do
a.should == "hello"
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "modifies self in place for all of Unicode with no option" do
- a = "ÄÖÜ"
- a.downcase!
- a.should == "äöü"
- end
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "ÄÖÜ"
+ a.downcase!
+ a.should == "äöü"
+ end
- it "updates string metadata" do
- downcased = "\u{212A}ING"
- downcased.downcase!
+ it "updates string metadata" do
+ downcased = "\u{212A}ING"
+ downcased.downcase!
- downcased.should == "king"
- downcased.size.should == 4
- downcased.bytesize.should == 4
- downcased.ascii_only?.should be_true
- end
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should be_true
end
+ end
- describe "ASCII-only case mapping" do
- it "does not downcase non-ASCII characters" do
- a = "CÅR"
- a.downcase!(:ascii)
- a.should == "cÅr"
- end
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ a = "CÅR"
+ a.downcase!(:ascii)
+ a.should == "cÅr"
end
+ end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "downcases characters according to Turkic semantics" do
- a = "İ"
- a.downcase!(:turkic)
- a.should == "i"
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ a = "İ"
+ a.downcase!(:turkic)
+ a.should == "i"
+ end
- it "allows Lithuanian as an extra option" do
- a = "İ"
- a.downcase!(:turkic, :lithuanian)
- a.should == "i"
- end
+ it "allows Lithuanian as an extra option" do
+ a = "İ"
+ a.downcase!(:turkic, :lithuanian)
+ a.should == "i"
+ end
- it "does not allow any other additional option" do
- lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ it "does not allow any other additional option" do
+ lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
end
+ end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- a = "İS"
- a.downcase!(:lithuanian)
- a.should == "i\u{307}s"
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "İS"
+ a.downcase!(:lithuanian)
+ a.should == "i\u{307}s"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- a = "İS"
- a.downcase!(:lithuanian, :turkic)
- a.should == "is"
- end
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "İS"
+ a.downcase!(:lithuanian, :turkic)
+ a.should == "is"
+ end
- it "does not allow any other additional option" do
- lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ it "does not allow any other additional option" do
+ lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
+ end
- describe "case folding" do
- it "case folds special characters" do
- a = "ß"
- a.downcase!
- a.should == "ß"
+ describe "case folding" do
+ it "case folds special characters" do
+ a = "ß"
+ a.downcase!
+ a.should == "ß"
- a.downcase!(:fold)
- a.should == "ss"
- end
+ a.downcase!(:fold)
+ a.should == "ss"
end
+ end
- it "does not allow invalid options" do
- lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
- end
+ it "does not allow invalid options" do
+ lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
end
it "returns nil if no modifications were made" do
diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb
index e67367b5b0..aa91114893 100644
--- a/spec/ruby/core/string/dump_spec.rb
+++ b/spec/ruby/core/string/dump_spec.rb
@@ -352,78 +352,39 @@ describe "String#dump" do
].should be_computed_by(:dump)
end
- ruby_version_is ''...'2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with lower-case hex digits" do
- [ [0200.chr('utf-8'), '"\u{80}"'],
- [0201.chr('utf-8'), '"\u{81}"'],
- [0202.chr('utf-8'), '"\u{82}"'],
- [0203.chr('utf-8'), '"\u{83}"'],
- [0204.chr('utf-8'), '"\u{84}"'],
- [0206.chr('utf-8'), '"\u{86}"'],
- [0207.chr('utf-8'), '"\u{87}"'],
- [0210.chr('utf-8'), '"\u{88}"'],
- [0211.chr('utf-8'), '"\u{89}"'],
- [0212.chr('utf-8'), '"\u{8a}"'],
- [0213.chr('utf-8'), '"\u{8b}"'],
- [0214.chr('utf-8'), '"\u{8c}"'],
- [0215.chr('utf-8'), '"\u{8d}"'],
- [0216.chr('utf-8'), '"\u{8e}"'],
- [0217.chr('utf-8'), '"\u{8f}"'],
- [0220.chr('utf-8'), '"\u{90}"'],
- [0221.chr('utf-8'), '"\u{91}"'],
- [0222.chr('utf-8'), '"\u{92}"'],
- [0223.chr('utf-8'), '"\u{93}"'],
- [0224.chr('utf-8'), '"\u{94}"'],
- [0225.chr('utf-8'), '"\u{95}"'],
- [0226.chr('utf-8'), '"\u{96}"'],
- [0227.chr('utf-8'), '"\u{97}"'],
- [0230.chr('utf-8'), '"\u{98}"'],
- [0231.chr('utf-8'), '"\u{99}"'],
- [0232.chr('utf-8'), '"\u{9a}"'],
- [0233.chr('utf-8'), '"\u{9b}"'],
- [0234.chr('utf-8'), '"\u{9c}"'],
- [0235.chr('utf-8'), '"\u{9d}"'],
- [0236.chr('utf-8'), '"\u{9e}"'],
- [0237.chr('utf-8'), '"\u{9f}"'],
- ].should be_computed_by(:dump)
- end
- end
-
- ruby_version_is '2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with upper-case hex digits" do
- [ [0200.chr('utf-8'), '"\u0080"'],
- [0201.chr('utf-8'), '"\u0081"'],
- [0202.chr('utf-8'), '"\u0082"'],
- [0203.chr('utf-8'), '"\u0083"'],
- [0204.chr('utf-8'), '"\u0084"'],
- [0206.chr('utf-8'), '"\u0086"'],
- [0207.chr('utf-8'), '"\u0087"'],
- [0210.chr('utf-8'), '"\u0088"'],
- [0211.chr('utf-8'), '"\u0089"'],
- [0212.chr('utf-8'), '"\u008A"'],
- [0213.chr('utf-8'), '"\u008B"'],
- [0214.chr('utf-8'), '"\u008C"'],
- [0215.chr('utf-8'), '"\u008D"'],
- [0216.chr('utf-8'), '"\u008E"'],
- [0217.chr('utf-8'), '"\u008F"'],
- [0220.chr('utf-8'), '"\u0090"'],
- [0221.chr('utf-8'), '"\u0091"'],
- [0222.chr('utf-8'), '"\u0092"'],
- [0223.chr('utf-8'), '"\u0093"'],
- [0224.chr('utf-8'), '"\u0094"'],
- [0225.chr('utf-8'), '"\u0095"'],
- [0226.chr('utf-8'), '"\u0096"'],
- [0227.chr('utf-8'), '"\u0097"'],
- [0230.chr('utf-8'), '"\u0098"'],
- [0231.chr('utf-8'), '"\u0099"'],
- [0232.chr('utf-8'), '"\u009A"'],
- [0233.chr('utf-8'), '"\u009B"'],
- [0234.chr('utf-8'), '"\u009C"'],
- [0235.chr('utf-8'), '"\u009D"'],
- [0236.chr('utf-8'), '"\u009E"'],
- [0237.chr('utf-8'), '"\u009F"'],
- ].should be_computed_by(:dump)
- end
+ it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with upper-case hex digits" do
+ [ [0200.chr('utf-8'), '"\u0080"'],
+ [0201.chr('utf-8'), '"\u0081"'],
+ [0202.chr('utf-8'), '"\u0082"'],
+ [0203.chr('utf-8'), '"\u0083"'],
+ [0204.chr('utf-8'), '"\u0084"'],
+ [0206.chr('utf-8'), '"\u0086"'],
+ [0207.chr('utf-8'), '"\u0087"'],
+ [0210.chr('utf-8'), '"\u0088"'],
+ [0211.chr('utf-8'), '"\u0089"'],
+ [0212.chr('utf-8'), '"\u008A"'],
+ [0213.chr('utf-8'), '"\u008B"'],
+ [0214.chr('utf-8'), '"\u008C"'],
+ [0215.chr('utf-8'), '"\u008D"'],
+ [0216.chr('utf-8'), '"\u008E"'],
+ [0217.chr('utf-8'), '"\u008F"'],
+ [0220.chr('utf-8'), '"\u0090"'],
+ [0221.chr('utf-8'), '"\u0091"'],
+ [0222.chr('utf-8'), '"\u0092"'],
+ [0223.chr('utf-8'), '"\u0093"'],
+ [0224.chr('utf-8'), '"\u0094"'],
+ [0225.chr('utf-8'), '"\u0095"'],
+ [0226.chr('utf-8'), '"\u0096"'],
+ [0227.chr('utf-8'), '"\u0097"'],
+ [0230.chr('utf-8'), '"\u0098"'],
+ [0231.chr('utf-8'), '"\u0099"'],
+ [0232.chr('utf-8'), '"\u009A"'],
+ [0233.chr('utf-8'), '"\u009B"'],
+ [0234.chr('utf-8'), '"\u009C"'],
+ [0235.chr('utf-8'), '"\u009D"'],
+ [0236.chr('utf-8'), '"\u009E"'],
+ [0237.chr('utf-8'), '"\u009F"'],
+ ].should be_computed_by(:dump)
end
it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do
diff --git a/spec/ruby/core/string/lines_spec.rb b/spec/ruby/core/string/lines_spec.rb
index 1c13936c30..ad4b119074 100644
--- a/spec/ruby/core/string/lines_spec.rb
+++ b/spec/ruby/core/string/lines_spec.rb
@@ -11,12 +11,10 @@ describe "String#lines" do
ary.should == ["hello ", "world"]
end
- ruby_version_is '2.4' do
- context "when `chomp` keyword argument is passed" do
- it "removes new line characters" do
- "hello \nworld\n".lines(chomp: true).should == ["hello ", "world"]
- "hello \r\nworld\r\n".lines(chomp: true).should == ["hello ", "world"]
- end
+ context "when `chomp` keyword argument is passed" do
+ it "removes new line characters" do
+ "hello \nworld\n".lines(chomp: true).should == ["hello ", "world"]
+ "hello \r\nworld\r\n".lines(chomp: true).should == ["hello ", "world"]
end
end
end
diff --git a/spec/ruby/core/string/match_spec.rb b/spec/ruby/core/string/match_spec.rb
index 7f3d9ebae5..67e015f23d 100644
--- a/spec/ruby/core/string/match_spec.rb
+++ b/spec/ruby/core/string/match_spec.rb
@@ -149,27 +149,25 @@ describe "String#match" do
end
end
-ruby_version_is "2.4" do
- describe "String#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "String#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given regex" do
- it "returns true but does not set Regexp.last_match" do
- 'string'.match?(/string/i).should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given regex" do
+ it "returns true but does not set Regexp.last_match" do
+ 'string'.match?(/string/i).should be_true
+ Regexp.last_match.should be_nil
end
+ end
- it "returns false when does not match the given regex" do
- 'string'.match?(/STRING/).should be_false
- end
+ it "returns false when does not match the given regex" do
+ 'string'.match?(/STRING/).should be_false
+ end
- it "takes matching position as the 2nd argument" do
- 'string'.match?(/str/i, 0).should be_true
- 'string'.match?(/str/i, 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ 'string'.match?(/str/i, 0).should be_true
+ 'string'.match?(/str/i, 1).should be_false
end
end
diff --git a/spec/ruby/core/string/new_spec.rb b/spec/ruby/core/string/new_spec.rb
index a65c6da2d1..f65daf2dd2 100644
--- a/spec/ruby/core/string/new_spec.rb
+++ b/spec/ruby/core/string/new_spec.rb
@@ -13,11 +13,9 @@ describe "String.new" do
str.encoding.should == Encoding::EUC_JP
end
- ruby_version_is "2.4" do
- it "accepts a capacity argument" do
- String.new("", capacity: 100_000).should == ""
- String.new("abc", capacity: 100_000).should == "abc"
- end
+ it "accepts a capacity argument" do
+ String.new("", capacity: 100_000).should == ""
+ String.new("abc", capacity: 100_000).should == "abc"
end
it "returns a fully-formed String" do
diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb
index cbe83524b8..e2c29de836 100644
--- a/spec/ruby/core/string/prepend_spec.rb
+++ b/spec/ruby/core/string/prepend_spec.rb
@@ -42,23 +42,21 @@ describe "String#prepend" do
x.prepend("y".taint).tainted?.should be_true
end
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- str = " world"
- str.prepend "he", "", "llo"
- str.should == "hello world"
- end
+ it "takes multiple arguments" do
+ str = " world"
+ str.prepend "he", "", "llo"
+ str.should == "hello world"
+ end
- it "prepends the initial value when given arguments contain 2 self" do
- str = "hello"
- str.prepend str, str
- str.should == "hellohellohello"
- end
+ it "prepends the initial value when given arguments contain 2 self" do
+ str = "hello"
+ str.prepend str, str
+ str.should == "hellohellohello"
+ end
- it "returns self when given no arguments" do
- str = "hello"
- str.prepend.should equal(str)
- str.should == "hello"
- end
+ it "returns self when given no arguments" do
+ str = "hello"
+ str.prepend.should equal(str)
+ str.should == "hello"
end
end
diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb
index 066b0c1040..86c966e50b 100644
--- a/spec/ruby/core/string/shared/each_line.rb
+++ b/spec/ruby/core/string/shared/each_line.rb
@@ -145,34 +145,32 @@ describe :string_each_line, shared: true do
lambda { "hello world".send(@method, :o).to_a }.should raise_error(TypeError)
end
- ruby_version_is '2.4' do
- context "when `chomp` keyword argument is passed" do
- it "removes new line characters when separator is not specified" do
- a = []
- "hello \nworld\n".send(@method, chomp: true) { |s| a << s }
- a.should == ["hello ", "world"]
-
- a = []
- "hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
- a.should == ["hello ", "world"]
- end
+ context "when `chomp` keyword argument is passed" do
+ it "removes new line characters when separator is not specified" do
+ a = []
+ "hello \nworld\n".send(@method, chomp: true) { |s| a << s }
+ a.should == ["hello ", "world"]
- it "removes only specified separator" do
- a = []
- "hello world".send(@method, ' ', chomp: true) { |s| a << s }
- a.should == ["hello", "world"]
- end
+ a = []
+ "hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
+ a.should == ["hello ", "world"]
+ end
- # https://bugs.ruby-lang.org/issues/14257
- it "ignores new line characters when separator is specified" do
- a = []
- "hello\n world\n".send(@method, ' ', chomp: true) { |s| a << s }
- a.should == ["hello\n", "world\n"]
+ it "removes only specified separator" do
+ a = []
+ "hello world".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello", "world"]
+ end
- a = []
- "hello\r\n world\r\n".send(@method, ' ', chomp: true) { |s| a << s }
- a.should == ["hello\r\n", "world\r\n"]
- end
+ # https://bugs.ruby-lang.org/issues/14257
+ it "ignores new line characters when separator is specified" do
+ a = []
+ "hello\n world\n".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello\n", "world\n"]
+
+ a = []
+ "hello\r\n world\r\n".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello\r\n", "world\r\n"]
end
end
end
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index 7d5a591790..82f261b8df 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -65,28 +65,26 @@ describe "String#split with String" do
end
it "defaults to $; when string isn't given or nil" do
- begin
- verbose = $VERBOSE
- $VERBOSE = nil
+ suppress_warning do
old_fs = $;
+ begin
+ [",", ":", "", "XY", nil].each do |fs|
+ $; = fs
- [",", ":", "", "XY", nil].each do |fs|
- $; = fs
+ ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
+ expected = str.split(fs || " ")
- ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
- expected = str.split(fs || " ")
+ str.split(nil).should == expected
+ str.split.should == expected
- str.split(nil).should == expected
- str.split.should == expected
-
- str.split(nil, -1).should == str.split(fs || " ", -1)
- str.split(nil, 0).should == str.split(fs || " ", 0)
- str.split(nil, 2).should == str.split(fs || " ", 2)
+ str.split(nil, -1).should == str.split(fs || " ", -1)
+ str.split(nil, 0).should == str.split(fs || " ", 0)
+ str.split(nil, 2).should == str.split(fs || " ", 2)
+ end
end
+ ensure
+ $; = old_fs
end
- ensure
- $; = old_fs
- $VERBOSE = verbose
end
end
@@ -241,28 +239,26 @@ describe "String#split with Regexp" do
end
it "defaults to $; when regexp isn't given or nil" do
- begin
- verbose = $VERBOSE
- $VERBOSE = nil
+ suppress_warning do
old_fs = $;
+ begin
+ [/,/, /:/, //, /XY/, /./].each do |fs|
+ $; = fs
- [/,/, /:/, //, /XY/, /./].each do |fs|
- $; = fs
+ ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
+ expected = str.split(fs)
- ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
- expected = str.split(fs)
+ str.split(nil).should == expected
+ str.split.should == expected
- str.split(nil).should == expected
- str.split.should == expected
-
- str.split(nil, -1).should == str.split(fs, -1)
- str.split(nil, 0).should == str.split(fs, 0)
- str.split(nil, 2).should == str.split(fs, 2)
+ str.split(nil, -1).should == str.split(fs, -1)
+ str.split(nil, 0).should == str.split(fs, 0)
+ str.split(nil, 2).should == str.split(fs, 2)
+ end
end
+ ensure
+ $; = old_fs
end
- ensure
- $; = old_fs
- $VERBOSE = verbose
end
end
diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb
index bb89dee48f..c35751859e 100644
--- a/spec/ruby/core/string/swapcase_spec.rb
+++ b/spec/ruby/core/string/swapcase_spec.rb
@@ -14,73 +14,63 @@ describe "String#swapcase" do
"hello".taint.swapcase.tainted?.should == true
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
- "ÄÖÜ".swapcase.should == "ÄÖÜ"
- "ärger".swapcase.should == "äRGER"
- "BÄR".swapcase.should == "bÄr"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äÖü".swapcase.should == "ÄöÜ"
end
- end
-
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "works for all of Unicode with no option" do
- "äÖü".swapcase.should == "ÄöÜ"
- end
- it "updates string metadata" do
- swapcased = "Aßet".swapcase
+ it "updates string metadata" do
+ swapcased = "Aßet".swapcase
- swapcased.should == "aSSET"
- swapcased.size.should == 5
- swapcased.bytesize.should == 5
- swapcased.ascii_only?.should be_true
- end
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should be_true
end
+ end
- describe "ASCII-only case mapping" do
- it "does not swapcase non-ASCII characters" do
- "aßet".swapcase(:ascii).should == "AßET"
- end
+ describe "ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ "aßet".swapcase(:ascii).should == "AßET"
end
+ end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "swaps case of ASCII characters according to Turkic semantics" do
- "aiS".swapcase(:turkic).should == "Aİs"
- end
-
- it "allows Lithuanian as an extra option" do
- "aiS".swapcase(:turkic, :lithuanian).should == "Aİs"
- end
-
- it "does not allow any other additional option" do
- lambda { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ "aiS".swapcase(:turkic).should == "Aİs"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- "Iß".swapcase(:lithuanian).should == "iSS"
- end
+ it "allows Lithuanian as an extra option" do
+ "aiS".swapcase(:turkic, :lithuanian).should == "Aİs"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- "iS".swapcase(:lithuanian, :turkic).should == "İs"
- end
+ it "does not allow any other additional option" do
+ lambda { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "Iß".swapcase(:lithuanian).should == "iSS"
end
- it "does not allow the :fold option for upcasing" do
- lambda { "abc".swapcase(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iS".swapcase(:lithuanian, :turkic).should == "İs"
end
- it "does not allow invalid options" do
- lambda { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".swapcase(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "returns subclass instances when called on a subclass" do
StringSpecs::MyString.new("").swapcase.should be_an_instance_of(StringSpecs::MyString)
StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(StringSpecs::MyString)
@@ -94,78 +84,76 @@ describe "String#swapcase!" do
a.should == "CyBeR_pUnK11"
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "modifies self in place for all of Unicode with no option" do
- a = "äÖü"
- a.swapcase!
- a.should == "ÄöÜ"
- end
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äÖü"
+ a.swapcase!
+ a.should == "ÄöÜ"
+ end
- it "updates string metadata" do
- swapcased = "Aßet"
- swapcased.swapcase!
+ it "updates string metadata" do
+ swapcased = "Aßet"
+ swapcased.swapcase!
- swapcased.should == "aSSET"
- swapcased.size.should == 5
- swapcased.bytesize.should == 5
- swapcased.ascii_only?.should be_true
- end
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should be_true
end
+ end
- describe "modifies self in place for ASCII-only case mapping" do
- it "does not swapcase non-ASCII characters" do
- a = "aßet"
- a.swapcase!(:ascii)
- a.should == "AßET"
- end
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ a = "aßet"
+ a.swapcase!(:ascii)
+ a.should == "AßET"
end
+ end
- describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
- it "swaps case of ASCII characters according to Turkic semantics" do
- a = "aiS"
- a.swapcase!(:turkic)
- a.should == "Aİs"
- end
-
- it "allows Lithuanian as an extra option" do
- a = "aiS"
- a.swapcase!(:turkic, :lithuanian)
- a.should == "Aİs"
- end
-
- it "does not allow any other additional option" do
- lambda { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ a = "aiS"
+ a.swapcase!(:turkic)
+ a.should == "Aİs"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- a = "Iß"
- a.swapcase!(:lithuanian)
- a.should == "iSS"
- end
+ it "allows Lithuanian as an extra option" do
+ a = "aiS"
+ a.swapcase!(:turkic, :lithuanian)
+ a.should == "Aİs"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- a = "iS"
- a.swapcase!(:lithuanian, :turkic)
- a.should == "İs"
- end
+ it "does not allow any other additional option" do
+ lambda { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "Iß"
+ a.swapcase!(:lithuanian)
+ a.should == "iSS"
end
- it "does not allow the :fold option for upcasing" do
- lambda { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iS"
+ a.swapcase!(:lithuanian, :turkic)
+ a.should == "İs"
end
- it "does not allow invalid options" do
- lambda { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "returns nil if no modifications were made" do
a = "+++---111222???"
a.swapcase!.should == nil
diff --git a/spec/ruby/core/string/to_f_spec.rb b/spec/ruby/core/string/to_f_spec.rb
index ca8536c30e..cf64ecfc5d 100644
--- a/spec/ruby/core/string/to_f_spec.rb
+++ b/spec/ruby/core/string/to_f_spec.rb
@@ -12,6 +12,7 @@ describe "String#to_f" do
".5".to_f.should == 0.5
".5e1".to_f.should == 5.0
+ "5.".to_f.should == 5.0
"5e".to_f.should == 5.0
"5E".to_f.should == 5.0
end
diff --git a/spec/ruby/core/string/unpack1_spec.rb b/spec/ruby/core/string/unpack1_spec.rb
index 5b2157d85a..5fe81733fb 100644
--- a/spec/ruby/core/string/unpack1_spec.rb
+++ b/spec/ruby/core/string/unpack1_spec.rb
@@ -1,12 +1,10 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "String#unpack1" do
- it "returns the first value of #unpack" do
- "ABCD".unpack1('x3C').should == "ABCD".unpack('x3C')[0]
- "\u{3042 3044 3046}".unpack1("U*").should == 0x3042
- "aG9nZWZ1Z2E=".unpack1("m").should == "hogefuga"
- "A".unpack1("B*").should == "01000001"
- end
+describe "String#unpack1" do
+ it "returns the first value of #unpack" do
+ "ABCD".unpack1('x3C').should == "ABCD".unpack('x3C')[0]
+ "\u{3042 3044 3046}".unpack1("U*").should == 0x3042
+ "aG9nZWZ1Z2E=".unpack1("m").should == "hogefuga"
+ "A".unpack1("B*").should == "01000001"
end
end
diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb
index 347f567be9..eb736ebfa1 100644
--- a/spec/ruby/core/string/upcase_spec.rb
+++ b/spec/ruby/core/string/upcase_spec.rb
@@ -8,79 +8,63 @@ describe "String#upcase" do
"hello".upcase.should == "HELLO"
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only replaces a-z)" do
- "äöü".upcase.should == "äöü"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöü".upcase.should == "ÄÖÜ"
+ end
- str = Array.new(256) { |c| c.chr }.join
- expected = Array.new(256) do |i|
- c = i.chr
- c.between?("a", "z") ? c.upcase : c
- end.join
+ it "updates string metadata" do
+ upcased = "aßet".upcase
- str.upcase.should == expected
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should be_true
end
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "works for all of Unicode with no option" do
- "äöü".upcase.should == "ÄÖÜ"
- end
-
- it "updates string metadata" do
- upcased = "aßet".upcase
-
- upcased.should == "ASSET"
- upcased.size.should == 5
- upcased.bytesize.should == 5
- upcased.ascii_only?.should be_true
- end
+ describe "ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ "aßet".upcase(:ascii).should == "AßET"
end
+ end
- describe "ASCII-only case mapping" do
- it "does not upcase non-ASCII characters" do
- "aßet".upcase(:ascii).should == "AßET"
- end
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ "i".upcase(:turkic).should == "İ"
end
- describe "full Unicode case mapping adapted for Turkic languages" do
- it "upcases ASCII characters according to Turkic semantics" do
- "i".upcase(:turkic).should == "İ"
- end
-
- it "allows Lithuanian as an extra option" do
- "i".upcase(:turkic, :lithuanian).should == "İ"
- end
-
- it "does not allow any other additional option" do
- lambda { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ it "allows Lithuanian as an extra option" do
+ "i".upcase(:turkic, :lithuanian).should == "İ"
end
- describe "full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- "iß".upcase(:lithuanian).should == "ISS"
- end
-
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- "iß".upcase(:lithuanian, :turkic).should == "İSS"
- end
+ it "does not allow any other additional option" do
+ lambda { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".upcase(:lithuanian).should == "ISS"
end
- it "does not allow the :fold option for upcasing" do
- lambda { "abc".upcase(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".upcase(:lithuanian, :turkic).should == "İSS"
end
- it "does not allow invalid options" do
- lambda { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".upcase(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "taints result when self is tainted" do
"".taint.upcase.tainted?.should == true
"X".taint.upcase.tainted?.should == true
@@ -99,78 +83,76 @@ describe "String#upcase!" do
a.should == "HELLO"
end
- ruby_version_is '2.4' do
- describe "full Unicode case mapping" do
- it "modifies self in place for all of Unicode with no option" do
- a = "äöü"
- a.upcase!
- a.should == "ÄÖÜ"
- end
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äöü"
+ a.upcase!
+ a.should == "ÄÖÜ"
+ end
- it "updates string metadata for self" do
- upcased = "aßet"
- upcased.upcase!
+ it "updates string metadata for self" do
+ upcased = "aßet"
+ upcased.upcase!
- upcased.should == "ASSET"
- upcased.size.should == 5
- upcased.bytesize.should == 5
- upcased.ascii_only?.should be_true
- end
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should be_true
end
+ end
- describe "modifies self in place for ASCII-only case mapping" do
- it "does not upcase non-ASCII characters" do
- a = "aßet"
- a.upcase!(:ascii)
- a.should == "AßET"
- end
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ a = "aßet"
+ a.upcase!(:ascii)
+ a.should == "AßET"
end
+ end
- describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
- it "upcases ASCII characters according to Turkic semantics" do
- a = "i"
- a.upcase!(:turkic)
- a.should == "İ"
- end
-
- it "allows Lithuanian as an extra option" do
- a = "i"
- a.upcase!(:turkic, :lithuanian)
- a.should == "İ"
- end
-
- it "does not allow any other additional option" do
- lambda { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ a = "i"
+ a.upcase!(:turkic)
+ a.should == "İ"
end
- describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
- it "currently works the same as full Unicode case mapping" do
- a = "iß"
- a.upcase!(:lithuanian)
- a.should == "ISS"
- end
+ it "allows Lithuanian as an extra option" do
+ a = "i"
+ a.upcase!(:turkic, :lithuanian)
+ a.should == "İ"
+ end
- it "allows Turkic as an extra option (and applies Turkic semantics)" do
- a = "iß"
- a.upcase!(:lithuanian, :turkic)
- a.should == "İSS"
- end
+ it "does not allow any other additional option" do
+ lambda { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
- it "does not allow any other additional option" do
- lambda { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
- end
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "iß"
+ a.upcase!(:lithuanian)
+ a.should == "ISS"
end
- it "does not allow the :fold option for upcasing" do
- lambda { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError)
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iß"
+ a.upcase!(:lithuanian, :turkic)
+ a.should == "İSS"
end
- it "does not allow invalid options" do
- lambda { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError)
+ it "does not allow any other additional option" do
+ lambda { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
end
end
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError)
+ end
+
it "returns nil if no modifications were made" do
a = "HELLO"
a.upcase!.should == nil
diff --git a/spec/ruby/core/symbol/capitalize_spec.rb b/spec/ruby/core/symbol/capitalize_spec.rb
index 54aebf21ca..a84bcf280a 100644
--- a/spec/ruby/core/symbol/capitalize_spec.rb
+++ b/spec/ruby/core/symbol/capitalize_spec.rb
@@ -14,18 +14,9 @@ describe "Symbol#capitalize" do
:"£1.20".capitalize.should == :"£1.20"
end
- ruby_version_is ''...'2.4' do
- it "leaves the first character alone if it is not an alphabetical ASCII character" do
- "\u{00DE}c".to_sym.capitalize.should == :"Þc"
- "\u{00DF}C".to_sym.capitalize.should == :"ßc"
- end
- end
-
- ruby_version_is '2.4' do
- it "capitalizes the first character if it is Unicode" do
- :"äöü".capitalize.should == :"Äöü"
- :"aou".capitalize.should == :"Aou"
- end
+ it "capitalizes the first character if it is Unicode" do
+ :"äöü".capitalize.should == :"Äöü"
+ :"aou".capitalize.should == :"Aou"
end
it "converts subsequent uppercase ASCII characters to their lowercase equivalents" do
@@ -40,12 +31,6 @@ describe "Symbol#capitalize" do
:mIxEd.capitalize.should == :Mixed
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "a\u{00DE}c".to_sym.capitalize.should == :"AÞc"
- end
- end
-
it "leaves lowercase Unicode characters (except in first position) as they were" do
"a\u{00DF}C".to_sym.capitalize.should == :"Aßc"
end
diff --git a/spec/ruby/core/symbol/casecmp_spec.rb b/spec/ruby/core/symbol/casecmp_spec.rb
index 232399b664..b485101d63 100644
--- a/spec/ruby/core/symbol/casecmp_spec.rb
+++ b/spec/ruby/core/symbol/casecmp_spec.rb
@@ -73,74 +73,72 @@ describe "Symbol#casecmp" do
end
end
-ruby_version_is "2.4" do
- describe 'Symbol#casecmp?' do
- it "compares symbols without regard to case" do
- :abcdef.casecmp?(:abcde).should == false
- :aBcDeF.casecmp?(:abcdef).should == true
- :abcdef.casecmp?(:abcdefg).should == false
- :abcdef.casecmp?(:ABCDEF).should == true
- end
-
- it "doesn't consider non-ascii characters equal that aren't" do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
- upper_a_umlaut = "\xC4".b.to_sym
- lower_a_tilde = "\xE3".b.to_sym
- lower_a_umlaut = "\xE4".b.to_sym
-
- lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
- lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
- upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
- upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
-
- # -- UTF-8 --
- upper_a_tilde = :"Ã"
- lower_a_tilde = :"ã"
- upper_a_umlaut = :"Ä"
- lower_a_umlaut = :"ä"
-
- lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
- lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
- upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
- upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
- end
-
- it "doesn't do case mapping for non-ascii and non-unicode characters" do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
- upper_a_umlaut = "\xC4".b.to_sym
- lower_a_tilde = "\xE3".b.to_sym
- lower_a_umlaut = "\xE4".b.to_sym
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == false
- upper_a_umlaut.casecmp?(lower_a_umlaut).should == false
- lower_a_tilde.casecmp?(upper_a_tilde).should == false
- lower_a_umlaut.casecmp?(upper_a_umlaut).should == false
- end
-
- it 'does case mapping for unicode characters' do
- # -- UTF-8 --
- upper_a_tilde = :"Ã"
- lower_a_tilde = :"ã"
- upper_a_umlaut = :"Ä"
- lower_a_umlaut = :"ä"
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == true
- upper_a_umlaut.casecmp?(lower_a_umlaut).should == true
- lower_a_tilde.casecmp?(upper_a_tilde).should == true
- lower_a_umlaut.casecmp?(upper_a_umlaut).should == true
- end
-
- it 'returns nil when comparing characters with different encodings' do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
-
- # -- UTF-8 --
- lower_a_tilde = :"ã"
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == nil
- lower_a_tilde.casecmp?(upper_a_tilde).should == nil
- end
+describe 'Symbol#casecmp?' do
+ it "compares symbols without regard to case" do
+ :abcdef.casecmp?(:abcde).should == false
+ :aBcDeF.casecmp?(:abcdef).should == true
+ :abcdef.casecmp?(:abcdefg).should == false
+ :abcdef.casecmp?(:ABCDEF).should == true
+ end
+
+ it "doesn't consider non-ascii characters equal that aren't" do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+ upper_a_umlaut = "\xC4".b.to_sym
+ lower_a_tilde = "\xE3".b.to_sym
+ lower_a_umlaut = "\xE4".b.to_sym
+
+ lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
+ lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
+ upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
+ upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
+
+ # -- UTF-8 --
+ upper_a_tilde = :"Ã"
+ lower_a_tilde = :"ã"
+ upper_a_umlaut = :"Ä"
+ lower_a_umlaut = :"ä"
+
+ lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
+ lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
+ upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
+ upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
+ end
+
+ it "doesn't do case mapping for non-ascii and non-unicode characters" do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+ upper_a_umlaut = "\xC4".b.to_sym
+ lower_a_tilde = "\xE3".b.to_sym
+ lower_a_umlaut = "\xE4".b.to_sym
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == false
+ upper_a_umlaut.casecmp?(lower_a_umlaut).should == false
+ lower_a_tilde.casecmp?(upper_a_tilde).should == false
+ lower_a_umlaut.casecmp?(upper_a_umlaut).should == false
+ end
+
+ it 'does case mapping for unicode characters' do
+ # -- UTF-8 --
+ upper_a_tilde = :"Ã"
+ lower_a_tilde = :"ã"
+ upper_a_umlaut = :"Ä"
+ lower_a_umlaut = :"ä"
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == true
+ upper_a_umlaut.casecmp?(lower_a_umlaut).should == true
+ lower_a_tilde.casecmp?(upper_a_tilde).should == true
+ lower_a_umlaut.casecmp?(upper_a_umlaut).should == true
+ end
+
+ it 'returns nil when comparing characters with different encodings' do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+
+ # -- UTF-8 --
+ lower_a_tilde = :"ã"
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == nil
+ lower_a_tilde.casecmp?(upper_a_tilde).should == nil
end
end
diff --git a/spec/ruby/core/symbol/downcase_spec.rb b/spec/ruby/core/symbol/downcase_spec.rb
index eb81c90d05..7e94c669cc 100644
--- a/spec/ruby/core/symbol/downcase_spec.rb
+++ b/spec/ruby/core/symbol/downcase_spec.rb
@@ -14,17 +14,9 @@ describe "Symbol#downcase" do
"\u{E0}Bc".to_sym.downcase.should == :"àbc"
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "\u{DE}Bc".to_sym.downcase.should == :"Þbc"
- end
- end
-
- ruby_version_is '2.4' do
- it "uncapitalizes all Unicode characters" do
- "ÄÖÜ".to_sym.downcase.should == :"äöü"
- "AOU".to_sym.downcase.should == :"aou"
- end
+ it "uncapitalizes all Unicode characters" do
+ "ÄÖÜ".to_sym.downcase.should == :"äöü"
+ "AOU".to_sym.downcase.should == :"aou"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/symbol/dup_spec.rb b/spec/ruby/core/symbol/dup_spec.rb
index 202720e8f5..8b35917c27 100644
--- a/spec/ruby/core/symbol/dup_spec.rb
+++ b/spec/ruby/core/symbol/dup_spec.rb
@@ -1,9 +1,7 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Symbol#dup" do
- it "returns self" do
- :a_symbol.dup.should equal(:a_symbol)
- end
+describe "Symbol#dup" do
+ it "returns self" do
+ :a_symbol.dup.should equal(:a_symbol)
end
end
diff --git a/spec/ruby/core/symbol/match_spec.rb b/spec/ruby/core/symbol/match_spec.rb
index c26d0569ed..d37155537b 100644
--- a/spec/ruby/core/symbol/match_spec.rb
+++ b/spec/ruby/core/symbol/match_spec.rb
@@ -19,52 +19,42 @@ describe "Symbol#=~" do
it_behaves_like :symbol_match, :=~
end
-ruby_version_is ""..."2.4" do
- describe "Symbol#match" do
- it_behaves_like :symbol_match, :match
+describe "Symbol#match" do
+ it "returns the MatchData" do
+ result = :abc.match(/b/)
+ result.should be_kind_of(MatchData)
+ result[0].should == 'b'
end
-end
-
-ruby_version_is "2.4" do
- describe "Symbol#match" do
- it "returns the MatchData" do
- result = :abc.match(/b/)
- result.should be_kind_of(MatchData)
- result[0].should == 'b'
- end
- it "returns nil if there is no match" do
- :a.match(/b/).should be_nil
- end
+ it "returns nil if there is no match" do
+ :a.match(/b/).should be_nil
+ end
- it "sets the last match pseudo-variables" do
- :a.match(/(.)/)[0].should == 'a'
- $1.should == "a"
- end
+ it "sets the last match pseudo-variables" do
+ :a.match(/(.)/)[0].should == 'a'
+ $1.should == "a"
end
end
-ruby_version_is "2.4" do
- describe "Symbol#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "Symbol#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given regex" do
- it "returns true but does not set Regexp.last_match" do
- :string.match?(/string/i).should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given regex" do
+ it "returns true but does not set Regexp.last_match" do
+ :string.match?(/string/i).should be_true
+ Regexp.last_match.should be_nil
end
+ end
- it "returns false when does not match the given regex" do
- :string.match?(/STRING/).should be_false
- end
+ it "returns false when does not match the given regex" do
+ :string.match?(/STRING/).should be_false
+ end
- it "takes matching position as the 2nd argument" do
- :string.match?(/str/i, 0).should be_true
- :string.match?(/str/i, 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ :string.match?(/str/i, 0).should be_true
+ :string.match?(/str/i, 1).should be_false
end
end
diff --git a/spec/ruby/core/symbol/swapcase_spec.rb b/spec/ruby/core/symbol/swapcase_spec.rb
index 9aec87a6d2..24709cac30 100644
--- a/spec/ruby/core/symbol/swapcase_spec.rb
+++ b/spec/ruby/core/symbol/swapcase_spec.rb
@@ -18,21 +18,9 @@ describe "Symbol#swapcase" do
:mIxEd.swapcase.should == :MiXeD
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "\u{00DE}Bc".to_sym.swapcase.should == :"ÞbC"
- end
-
- it "leaves lowercase Unicode characters as they were" do
- "\u{00DF}Bc".to_sym.swapcase.should == :"ßbC"
- end
- end
-
- ruby_version_is '2.4' do
- it "swaps the case for Unicode characters" do
- "äÖü".to_sym.swapcase.should == :"ÄöÜ"
- "aOu".to_sym.swapcase.should == :"AoU"
- end
+ it "swaps the case for Unicode characters" do
+ "äÖü".to_sym.swapcase.should == :"ÄöÜ"
+ "aOu".to_sym.swapcase.should == :"AoU"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/symbol/upcase_spec.rb b/spec/ruby/core/symbol/upcase_spec.rb
index 6183f3b754..f704bdcbf3 100644
--- a/spec/ruby/core/symbol/upcase_spec.rb
+++ b/spec/ruby/core/symbol/upcase_spec.rb
@@ -10,17 +10,9 @@ describe "Symbol#upcase" do
:lOwEr.upcase.should == :LOWER
end
- ruby_version_is ''...'2.4' do
- it "leaves lowercase Unicode characters as they were" do
- "\u{E0}Bc".to_sym.upcase.should == :"àBC"
- end
- end
-
- ruby_version_is '2.4' do
- it "capitalizes all Unicode characters" do
- "äöü".to_sym.upcase.should == :"ÄÖÜ"
- "aou".to_sym.upcase.should == :"AOU"
- end
+ it "capitalizes all Unicode characters" do
+ "äöü".to_sym.upcase.should == :"ÄÖÜ"
+ "aou".to_sym.upcase.should == :"AOU"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/thread/report_on_exception_spec.rb b/spec/ruby/core/thread/report_on_exception_spec.rb
index 16597f3a4b..a6042ba759 100644
--- a/spec/ruby/core/thread/report_on_exception_spec.rb
+++ b/spec/ruby/core/thread/report_on_exception_spec.rb
@@ -1,120 +1,116 @@
require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Thread.report_on_exception" do
- ruby_version_is "2.4"..."2.5" do
- it "defaults to false" do
- ruby_exe("p Thread.report_on_exception").should == "false\n"
- end
+describe "Thread.report_on_exception" do
+ ruby_version_is "2.4"..."2.5" do
+ it "defaults to false" do
+ ruby_exe("p Thread.report_on_exception").should == "false\n"
end
+ end
- ruby_version_is "2.5" do
- it "defaults to true" do
- ruby_exe("p Thread.report_on_exception").should == "true\n"
- end
+ ruby_version_is "2.5" do
+ it "defaults to true" do
+ ruby_exe("p Thread.report_on_exception").should == "true\n"
end
end
+end
- describe "Thread.report_on_exception=" do
- before :each do
- @report_on_exception = Thread.report_on_exception
- end
+describe "Thread.report_on_exception=" do
+ before :each do
+ @report_on_exception = Thread.report_on_exception
+ end
- after :each do
- Thread.report_on_exception = @report_on_exception
- end
+ after :each do
+ Thread.report_on_exception = @report_on_exception
+ end
- it "changes the default value for new threads" do
- Thread.report_on_exception = true
- Thread.report_on_exception.should == true
- t = Thread.new {}
- t.join
- t.report_on_exception.should == true
- end
+ it "changes the default value for new threads" do
+ Thread.report_on_exception = true
+ Thread.report_on_exception.should == true
+ t = Thread.new {}
+ t.join
+ t.report_on_exception.should == true
end
+end
- describe "Thread#report_on_exception" do
- ruby_version_is "2.5" do
- it "returns true for the main Thread" do
- Thread.current.report_on_exception.should == true
- end
+describe "Thread#report_on_exception" do
+ ruby_version_is "2.5" do
+ it "returns true for the main Thread" do
+ Thread.current.report_on_exception.should == true
+ end
- it "returns true for new Threads" do
- Thread.new { Thread.current.report_on_exception }.value.should == true
- end
+ it "returns true for new Threads" do
+ Thread.new { Thread.current.report_on_exception }.value.should == true
end
+ end
- it "returns whether the Thread will print a backtrace if it exits with an exception" do
- t = Thread.new { Thread.current.report_on_exception = true }
- t.join
- t.report_on_exception.should == true
+ it "returns whether the Thread will print a backtrace if it exits with an exception" do
+ t = Thread.new { Thread.current.report_on_exception = true }
+ t.join
+ t.report_on_exception.should == true
- t = Thread.new { Thread.current.report_on_exception = false }
- t.join
- t.report_on_exception.should == false
- end
+ t = Thread.new { Thread.current.report_on_exception = false }
+ t.join
+ t.report_on_exception.should == false
end
+end
- describe "Thread#report_on_exception=" do
- describe "when set to true" do
- it "prints a backtrace on $stderr if it terminates with an exception" do
- t = nil
- -> {
- t = Thread.new {
- Thread.current.report_on_exception = true
- raise RuntimeError, "Thread#report_on_exception specs"
- }
- Thread.pass while t.alive?
- }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
+describe "Thread#report_on_exception=" do
+ describe "when set to true" do
+ it "prints a backtrace on $stderr if it terminates with an exception" do
+ t = nil
+ -> {
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
+ Thread.pass while t.alive?
+ }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
+
+ -> {
+ t.join
+ }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
+ end
+ end
- -> {
- t.join
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- end
+ describe "when set to false" do
+ it "lets the thread terminates silently with an exception" do
+ t = nil
+ -> {
+ t = Thread.new {
+ Thread.current.report_on_exception = false
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
+ Thread.pass while t.alive?
+ }.should output("", "")
+
+ -> {
+ t.join
+ }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
end
+ end
- describe "when set to false" do
- it "lets the thread terminates silently with an exception" do
- t = nil
- -> {
- t = Thread.new {
- Thread.current.report_on_exception = false
- raise RuntimeError, "Thread#report_on_exception specs"
- }
- Thread.pass while t.alive?
- }.should output("", "")
+ describe "when used in conjunction with Thread#abort_on_exception" do
+ it "first reports then send the exception back to the main Thread" do
+ t = nil
+ mutex = Mutex.new
+ mutex.lock
+ -> {
+ t = Thread.new {
+ Thread.current.abort_on_exception = true
+ Thread.current.report_on_exception = true
+ mutex.lock
+ mutex.unlock
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
-> {
- t.join
+ mutex.sleep(5)
}.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- end
- end
+ }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
- ruby_bug "#13163", "2.4"..."2.5" do
- describe "when used in conjunction with Thread#abort_on_exception" do
- it "first reports then send the exception back to the main Thread" do
- t = nil
- mutex = Mutex.new
- mutex.lock
- -> {
- t = Thread.new {
- Thread.current.abort_on_exception = true
- Thread.current.report_on_exception = true
- mutex.lock
- mutex.unlock
- raise RuntimeError, "Thread#report_on_exception specs"
- }
-
- -> {
- mutex.sleep(5)
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
-
- -> {
- t.join
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- end
- end
+ -> {
+ t.join
+ }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
end
end
end
diff --git a/spec/ruby/core/time/shared/now.rb b/spec/ruby/core/time/shared/now.rb
index c548be283f..80f66a1134 100644
--- a/spec/ruby/core/time/shared/now.rb
+++ b/spec/ruby/core/time/shared/now.rb
@@ -8,7 +8,7 @@ describe :time_now, shared: true do
it "sets the current time" do
now = TimeSpecs::MethodHolder.send(@method)
- now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), 10.0)
+ now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), TIME_TOLERANCE)
end
it "uses the local timezone" do
@@ -17,4 +17,17 @@ describe :time_now, shared: true do
now.utc_offset.should == (-8 * 60 * 60)
end
end
+
+ it "has at least microsecond precision" do
+ times = []
+ 10_000.times do
+ times << Time.now.nsec
+ end
+
+ # The clock should not be less accurate than expected (times should
+ # not all be a multiple of the next precision up, assuming precisions
+ # are multiples of ten.)
+ expected = 1_000
+ times.select { |t| t % (expected * 10) == 0 }.size.should_not == times.size
+ end
end
diff --git a/spec/ruby/core/tracepoint/callee_id_spec.rb b/spec/ruby/core/tracepoint/callee_id_spec.rb
index 39a7413648..d340290d8b 100644
--- a/spec/ruby/core/tracepoint/callee_id_spec.rb
+++ b/spec/ruby/core/tracepoint/callee_id_spec.rb
@@ -1,19 +1,17 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe "TracePoint#callee_id" do
- it "returns the called name of the method being called" do
- a = []
- obj = TracePointSpec::ClassWithMethodAlias.new
+describe "TracePoint#callee_id" do
+ it "returns the called name of the method being called" do
+ a = []
+ obj = TracePointSpec::ClassWithMethodAlias.new
- TracePoint.new(:call) do |tp|
- a << tp.callee_id
- end.enable do
- obj.m_alias
- end
-
- a.should == [:m_alias]
+ TracePoint.new(:call) do |tp|
+ a << tp.callee_id
+ end.enable do
+ obj.m_alias
end
+
+ a.should == [:m_alias]
end
end
diff --git a/spec/ruby/core/tracepoint/disable_spec.rb b/spec/ruby/core/tracepoint/disable_spec.rb
index 25d54502ab..612ca3c25a 100644
--- a/spec/ruby/core/tracepoint/disable_spec.rb
+++ b/spec/ruby/core/tracepoint/disable_spec.rb
@@ -58,18 +58,16 @@ describe 'TracePoint#disable' do
end
end
- ruby_bug "#14057", ""..."2.5" do
- it 'can accept param within a block but it should not yield arguments' do
- trace = TracePoint.new(:line) {}
- trace.enable
- begin
- trace.disable do |*args|
- args.should == []
- end
- trace.enabled?.should == true
- ensure
- trace.disable
+ it 'can accept param within a block but it should not yield arguments' do
+ trace = TracePoint.new(:line) {}
+ trace.enable
+ begin
+ trace.disable do |*args|
+ args.should == []
end
+ trace.enabled?.should == true
+ ensure
+ trace.disable
end
end
end
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
index 52c2248656..6eeec1d5db 100644
--- a/spec/ruby/core/tracepoint/enable_spec.rb
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -58,16 +58,14 @@ describe 'TracePoint#enable' do
end.enable { event_name.should equal(:line) }
end
- ruby_bug "#14057", ""..."2.5" do
- it 'can accept arguments within a block but it should not yield arguments' do
- event_name = nil
- trace = TracePoint.new(:line) { |tp| event_name = tp.event }
- trace.enable do |*args|
- event_name.should equal(:line)
- args.should == []
- end
- trace.enabled?.should == false
+ it 'can accept arguments within a block but it should not yield arguments' do
+ event_name = nil
+ trace = TracePoint.new(:line) { |tp| event_name = tp.event }
+ trace.enable do |*args|
+ event_name.should equal(:line)
+ args.should == []
end
+ trace.enabled?.should == false
end
it 'enables trace object on calling with a block if it was already enabled' do
@@ -193,7 +191,7 @@ describe 'TracePoint#enable' do
end
describe 'option value' do
- it 'excepts Method' do
+ it 'accepts Method' do
trace = TracePoint.new(:call) do |tp|
ScratchPad << tp.method_id
end
@@ -208,7 +206,7 @@ describe 'TracePoint#enable' do
ScratchPad.recorded.should == [:foo]
end
- it 'excepts UnboundMethod' do
+ it 'accepts UnboundMethod' do
trace = TracePoint.new(:call) do |tp|
ScratchPad << tp.method_id
end
@@ -225,7 +223,7 @@ describe 'TracePoint#enable' do
ScratchPad.recorded.should == [:foo]
end
- it 'excepts Proc' do
+ it 'accepts Proc' do
trace = TracePoint.new(:b_call) do |tp|
ScratchPad << tp.lineno
end
@@ -240,36 +238,6 @@ describe 'TracePoint#enable' do
ScratchPad.recorded.should == [lineno]
lineno.should be_kind_of(Integer)
end
-
- it 'excepts RubyVM::InstructionSequence' do
- trace = TracePoint.new(:call) do |tp|
- ScratchPad << tp.method_id
- end
-
- obj = Object.new
- def obj.foo; end
-
- iseq = RubyVM::InstructionSequence.of(obj.method(:foo))
- trace.enable(target: iseq) do
- obj.foo
- end
-
- ScratchPad.recorded.should == [:foo]
- end
- end
-
- it "raises ArgumentError when passed object isn't consisted of InstructionSequence (iseq)" do
- trace = TracePoint.new(:call) do |tp|
- ScratchPad << tp.method_id
- end
-
- core_method = 'foo bar'.method(:bytes)
- RubyVM::InstructionSequence.of(core_method).should == nil
-
- lambda {
- trace.enable(target: core_method) do
- end
- }.should raise_error(ArgumentError, /specified target is not supported/)
end
it "raises ArgumentError if target object cannot trigger specified event" do
@@ -286,7 +254,7 @@ describe 'TracePoint#enable' do
}.should raise_error(ArgumentError, /can not enable any hooks/)
end
- it "raises ArgumentError if passed not Method/UnboundMethod/Proc/RubyVM::InstructionSequence" do
+ it "raises ArgumentError if passed not Method/UnboundMethod/Proc" do
trace = TracePoint.new(:call) do |tp|
end
@@ -490,7 +458,7 @@ describe 'TracePoint#enable' do
}.should raise_error(ArgumentError, /can not enable any hooks/)
end
- it "excepts value that could be coerced to Integer" do
+ it "accepts value that could be coerced to Integer" do
trace = TracePoint.new(:line) do |tp|
ScratchPad << tp.lineno
end
diff --git a/spec/ruby/core/tracepoint/instruction_sequence_spec.rb b/spec/ruby/core/tracepoint/instruction_sequence_spec.rb
deleted file mode 100644
index 3e3b73cccc..0000000000
--- a/spec/ruby/core/tracepoint/instruction_sequence_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-
-ruby_version_is "2.6" do
- describe "TracePoint#instruction_sequence" do
- it "is an instruction sequence" do
- ScratchPad.record []
-
- script = <<-CODE
- def foo
- p :hello
- end
- CODE
-
- TracePoint.new(:script_compiled) do |e|
- ScratchPad << e.instruction_sequence
- end.enable do
- eval script
- end
-
- ScratchPad.recorded.size.should == 1
- ScratchPad.recorded[0].class.should == RubyVM::InstructionSequence
- end
- end
-end
diff --git a/spec/ruby/core/tracepoint/new_spec.rb b/spec/ruby/core/tracepoint/new_spec.rb
index d333fd069a..916d826fdf 100644
--- a/spec/ruby/core/tracepoint/new_spec.rb
+++ b/spec/ruby/core/tracepoint/new_spec.rb
@@ -55,7 +55,7 @@ describe 'TracePoint.new' do
-> { TracePoint.new(o) {}}.should raise_error(TypeError)
end
- ruby_bug "#140740", ""..."2.5" do
+ ruby_version_is "2.5" do
it 'expects to be called with a block' do
-> { TracePoint.new(:line) }.should raise_error(ArgumentError, "must be called with a block")
end
diff --git a/spec/ruby/core/true/dup_spec.rb b/spec/ruby/core/true/dup_spec.rb
index 369910ab2c..351457ed22 100644
--- a/spec/ruby/core/true/dup_spec.rb
+++ b/spec/ruby/core/true/dup_spec.rb
@@ -1,9 +1,7 @@
require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "TrueClass#dup" do
- it "returns self" do
- true.dup.should equal(true)
- end
+describe "TrueClass#dup" do
+ it "returns self" do
+ true.dup.should equal(true)
end
end
diff --git a/spec/ruby/core/warning/warn_spec.rb b/spec/ruby/core/warning/warn_spec.rb
index 2844d97e76..7daf6323c3 100644
--- a/spec/ruby/core/warning/warn_spec.rb
+++ b/spec/ruby/core/warning/warn_spec.rb
@@ -1,61 +1,59 @@
require_relative '../../spec_helper'
describe "Warning.warn" do
- ruby_version_is "2.4" do
- it "complains" do
- -> {
- Warning.warn("Chunky bacon!")
- }.should complain("Chunky bacon!")
- end
+ it "complains" do
+ -> {
+ Warning.warn("Chunky bacon!")
+ }.should complain("Chunky bacon!")
+ end
- it "does not add a newline" do
- ruby_exe("Warning.warn('test')", args: "2>&1").should == "test"
- end
+ it "does not add a newline" do
+ ruby_exe("Warning.warn('test')", args: "2>&1").should == "test"
+ end
- it "returns nil" do
- ruby_exe("p Warning.warn('test')", args: "2>&1").should == "testnil\n"
- end
+ it "returns nil" do
+ ruby_exe("p Warning.warn('test')", args: "2>&1").should == "testnil\n"
+ end
- it "extends itself" do
- Warning.singleton_class.ancestors.should include(Warning)
- end
+ it "extends itself" do
+ Warning.singleton_class.ancestors.should include(Warning)
+ end
- it "has Warning as the method owner" do
- ruby_exe("p Warning.method(:warn).owner").should == "Warning\n"
- end
+ it "has Warning as the method owner" do
+ ruby_exe("p Warning.method(:warn).owner").should == "Warning\n"
+ end
- it "can be overridden" do
- code = <<-RUBY
- $stdout.sync = true
- $stderr.sync = true
- def Warning.warn(msg)
- if msg.start_with?("A")
- puts msg.upcase
- else
- super
- end
+ it "can be overridden" do
+ code = <<-RUBY
+ $stdout.sync = true
+ $stderr.sync = true
+ def Warning.warn(msg)
+ if msg.start_with?("A")
+ puts msg.upcase
+ else
+ super
end
- Warning.warn("A warning!")
- Warning.warn("warning from stderr\n")
- RUBY
- ruby_exe(code, args: "2>&1").should == %Q[A WARNING!\nwarning from stderr\n]
- end
-
- it "is called by parser warnings" do
- Warning.should_receive(:warn)
- verbose = $VERBOSE
- $VERBOSE = false
- begin
- eval "{ key: :value, key: :value2 }"
- ensure
- $VERBOSE = verbose
end
+ Warning.warn("A warning!")
+ Warning.warn("warning from stderr\n")
+ RUBY
+ ruby_exe(code, args: "2>&1").should == %Q[A WARNING!\nwarning from stderr\n]
+ end
+
+ it "is called by parser warnings" do
+ Warning.should_receive(:warn)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ eval "{ key: :value, key: :value2 }"
+ ensure
+ $VERBOSE = verbose
end
end
ruby_version_is "2.5" do
it "is called by Kernel.warn" do
- Warning.should_receive(:warn)
+ Warning.should_receive(:warn).with("Chunky bacon!\n")
verbose = $VERBOSE
$VERBOSE = false
begin
diff --git a/spec/ruby/default.mspec b/spec/ruby/default.mspec
index 051cd8d5f7..80d71c21e7 100644
--- a/spec/ruby/default.mspec
+++ b/spec/ruby/default.mspec
@@ -36,12 +36,12 @@ class MSpecScript
set :backtrace_filter, /mspec\//
set :tags_patterns, [
- [%r(language/), 'tags/1.9/language/'],
- [%r(core/), 'tags/1.9/core/'],
- [%r(command_line/), 'tags/1.9/command_line/'],
- [%r(library/), 'tags/1.9/library/'],
- [%r(security/), 'tags/1.9/security/'],
- [/_spec.rb$/, '_tags.txt']
+ [%r(language/), 'tags/language/'],
+ [%r(core/), 'tags/core/'],
+ [%r(command_line/), 'tags/command_line/'],
+ [%r(library/), 'tags/library/'],
+ [%r(security/), 'tags/security/'],
+ [/_spec\.rb$/, '_tags.txt']
]
set :toplevel_constants_excludes, [
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index 8f3c39df31..bf613433e7 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -217,6 +217,12 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { 1 }.should == 1
end
+
+ ruby_version_is "2.5" do
+ it "may include a rescue clause" do
+ eval("@y.z do raise ArgumentError; rescue ArgumentError; 7; end").should == 7
+ end
+ end
end
describe "taking || arguments" do
@@ -227,6 +233,12 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { || 1 }.should == 1
end
+
+ ruby_version_is "2.5" do
+ it "may include a rescue clause" do
+ eval('@y.z do || raise ArgumentError; rescue ArgumentError; 7; end').should == 7
+ end
+ end
end
describe "taking |a| arguments" do
@@ -252,6 +264,12 @@ describe "A block" do
it "does not destructure a single Array value" do
@y.s([1, 2]) { |a| a }.should == [1, 2]
end
+
+ ruby_version_is "2.5" do
+ it "may include a rescue clause" do
+ eval('@y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end').should == 7
+ end
+ end
end
describe "taking |a, b| arguments" do
@@ -626,6 +644,12 @@ describe "A block" do
end
end
+ describe "taking |*a, b:|" do
+ it "merges the hash into the splatted array" do
+ @y.k { |*a, b:| [a, b] }.should == [[], true]
+ end
+ end
+
describe "arguments with _" do
it "extracts arguments with _" do
@y.m([[1, 2, 3], 4]) { |(_, a, _), _| a }.should == 2
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index 354cc4b9a3..4d848ae889 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -655,9 +655,7 @@ describe "Module#private_constant marked constants" do
lambda do
ConstantVisibility::PrivConstModuleChild::PRIVATE_CONSTANT_MODULE
end.should raise_error(NameError) {|e|
- ruby_bug "#14853", ""..."2.5.2" do
- e.receiver.should == ConstantVisibility::PrivConstModule
- end
+ e.receiver.should == ConstantVisibility::PrivConstModule
e.name.should == :PRIVATE_CONSTANT_MODULE
}
end
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index a36ebf9a74..02c69d27b8 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -763,10 +763,8 @@ describe "The defined? keyword for a scoped constant" do
end
ruby_version_is "2.5" do
- ruby_bug "#14407", "2.5.0"..."2.5.1" do
- it "returns nil when a constant is defined on top-level but not on the class" do
- defined?(DefinedSpecs::Basic::String).should be_nil
- end
+ it "returns nil when a constant is defined on top-level but not on the class" do
+ defined?(DefinedSpecs::Basic::String).should be_nil
end
end
diff --git a/spec/ruby/language/fixtures/block.rb b/spec/ruby/language/fixtures/block.rb
index 9848d18776..33baac6aeb 100644
--- a/spec/ruby/language/fixtures/block.rb
+++ b/spec/ruby/language/fixtures/block.rb
@@ -15,6 +15,10 @@ module BlockSpecs
def r(a)
yield(*a)
end
+
+ def k(*a)
+ yield(*a, b: true)
+ end
end
# TODO: rewrite all specs that use Yield to use Yielder
diff --git a/spec/ruby/language/fixtures/yield.rb b/spec/ruby/language/fixtures/yield.rb
index a195616640..9f7a2ba238 100644
--- a/spec/ruby/language/fixtures/yield.rb
+++ b/spec/ruby/language/fixtures/yield.rb
@@ -21,6 +21,10 @@ module YieldSpecs
yield(*a)
end
+ def k(a)
+ yield(*a, b: true)
+ end
+
def rs(a, b, c)
yield(a, b, *c)
end
diff --git a/spec/ruby/language/if_spec.rb b/spec/ruby/language/if_spec.rb
index bdb2d1e6ac..4d809019c9 100644
--- a/spec/ruby/language/if_spec.rb
+++ b/spec/ruby/language/if_spec.rb
@@ -1,22 +1,20 @@
require_relative '../spec_helper'
describe "The if expression" do
- ruby_version_is '2.4' do
- describe "accepts multiple assignments in conditional expression" do
- before(:each) { ScratchPad.record([]) }
- after(:each) { ScratchPad.clear }
-
- it 'with non-nil values' do
- ary = [1, 2]
- eval "if (a, b = ary); ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [1, 2]
- end
+ describe "accepts multiple assignments in conditional expression" do
+ before(:each) { ScratchPad.record([]) }
+ after(:each) { ScratchPad.clear }
+
+ it 'with non-nil values' do
+ ary = [1, 2]
+ eval "if (a, b = ary); ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [1, 2]
+ end
- it 'with nil values' do
- ary = nil
- eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [nil, nil]
- end
+ it 'with nil values' do
+ ary = nil
+ eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [nil, nil]
end
end
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 7114a38e5c..a1140552bf 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -22,6 +22,16 @@ describe "A lambda literal -> () { }" do
-> () { }.lambda?.should be_true
end
+ ruby_version_is "2.6" do
+ it "may include a rescue clause" do
+ eval('-> do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
+ end
+
+ it "may include a ensure clause" do
+ eval('-> do 1; ensure; 2; end').should be_an_instance_of(Proc)
+ end
+ end
+
it "has its own scope for local variables" do
l = -> arg {
var = arg
@@ -305,6 +315,13 @@ describe "A lambda expression 'lambda { ... }'" do
lambda { lambda }.should raise_error(ArgumentError)
end
+ ruby_version_is "2.5" do
+ it "may include a rescue clause" do
+ eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should be_an_instance_of(Proc)
+ end
+ end
+
+
context "with an implicit block" do
before do
def meth; lambda; end
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index 36392c7b8a..58201b8cbd 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -1088,44 +1088,25 @@ TRUE TrueClass Synonym for true.
=end
describe "The predefined global constants" do
- ruby_version_is ""..."2.4" do
- it "includes TRUE" do
- Object.const_defined?(:TRUE).should == true
+ it "includes TRUE" do
+ Object.const_defined?(:TRUE).should == true
+ -> {
TRUE.should equal(true)
- end
+ }.should complain(/constant ::TRUE is deprecated/)
+ end
- it "includes FALSE" do
- Object.const_defined?(:FALSE).should == true
+ it "includes FALSE" do
+ Object.const_defined?(:FALSE).should == true
+ -> {
FALSE.should equal(false)
- end
-
- it "includes NIL" do
- Object.const_defined?(:NIL).should == true
- NIL.should equal(nil)
- end
+ }.should complain(/constant ::FALSE is deprecated/)
end
- ruby_version_is "2.4" do
- it "includes TRUE" do
- Object.const_defined?(:TRUE).should == true
- -> {
- TRUE.should equal(true)
- }.should complain(/constant ::TRUE is deprecated/)
- end
-
- it "includes FALSE" do
- Object.const_defined?(:FALSE).should == true
- -> {
- FALSE.should equal(false)
- }.should complain(/constant ::FALSE is deprecated/)
- end
-
- it "includes NIL" do
- Object.const_defined?(:NIL).should == true
- -> {
- NIL.should equal(nil)
- }.should complain(/constant ::NIL is deprecated/)
- end
+ it "includes NIL" do
+ Object.const_defined?(:NIL).should == true
+ -> {
+ NIL.should equal(nil)
+ }.should complain(/constant ::NIL is deprecated/)
end
it "includes STDIN" do
diff --git a/spec/ruby/language/regexp/character_classes_spec.rb b/spec/ruby/language/regexp/character_classes_spec.rb
index a466f745ae..c0f69bea9b 100644
--- a/spec/ruby/language/regexp/character_classes_spec.rb
+++ b/spec/ruby/language/regexp/character_classes_spec.rb
@@ -609,25 +609,23 @@ describe "Regexp with character classes" do
"루비(Ruby)".match(/\p{Hangul}+/u).to_a.should == ["루비"]
end
- ruby_version_is "2.4" do
- it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
- # simple emoji without any fancy modifier or ZWJ
- /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
+ it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
+ # simple emoji without any fancy modifier or ZWJ
+ /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
- # skin tone modifier
- /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘🏽"]
+ # skin tone modifier
+ /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘🏽"]
- # emoji joined with ZWJ
- /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["🏳️‍🌈"]
- /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩‍👩‍👧‍👦"]
+ # emoji joined with ZWJ
+ /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["🏳️‍🌈"]
+ /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩‍👩‍👧‍👦"]
- # without the ZWJ
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["🏳️🌈"]
- /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
+ # without the ZWJ
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["🏳️🌈"]
+ /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
- # both of the ZWJ combined
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
- .to_a.should == ["🏳️‍🌈👩‍👩‍👧‍👦"]
- end
+ # both of the ZWJ combined
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
+ .to_a.should == ["🏳️‍🌈👩‍👩‍👧‍👦"]
end
end
diff --git a/spec/ruby/language/regexp/modifiers_spec.rb b/spec/ruby/language/regexp/modifiers_spec.rb
index 7c78e67e2b..f0051ca55d 100644
--- a/spec/ruby/language/regexp/modifiers_spec.rb
+++ b/spec/ruby/language/regexp/modifiers_spec.rb
@@ -39,11 +39,9 @@ describe "Regexps with modifiers" do
lambda { eval('/foo/a') }.should raise_error(SyntaxError)
end
- ruby_version_is "2.4" do
- it "supports (?~) (absent operator)" do
- Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
- "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
- end
+ it "supports (?~) (absent operator)" do
+ Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
+ "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
end
it "supports (?imx-imx) (inline modifiers)" do
diff --git a/spec/ruby/language/regexp/repetition_spec.rb b/spec/ruby/language/regexp/repetition_spec.rb
index 5d400dec6f..7bb767ccaf 100644
--- a/spec/ruby/language/regexp/repetition_spec.rb
+++ b/spec/ruby/language/regexp/repetition_spec.rb
@@ -34,20 +34,11 @@ describe "Regexps with repetition" do
/.([0-9]){3,5}?foo/.match("9876543210foo").to_a.should == ["543210foo", "0"]
end
- ruby_version_is ""..."2.4" do
- it "does not treat {m,n}+ as possessive" do
+ it "does not treat {m,n}+ as possessive" do
+ -> {
@regexp = eval "/foo(A{0,1}+)Abar/"
- @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
- end
- end
-
- ruby_version_is "2.4" do
- it "does not treat {m,n}+ as possessive" do
- -> {
- @regexp = eval "/foo(A{0,1}+)Abar/"
- }.should complain(/nested repeat operator/)
- @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
- end
+ }.should complain(/nested repeat operator/)
+ @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
end
it "supports ? (0 or 1 of previous subexpression)" do
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index 6fcf81107c..aae5156dcd 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -168,30 +168,10 @@ describe "Literal Regexps" do
end
end
- ruby_version_is '2.4' do
- it "support handling unicode 9.0 characters with POSIX bracket expressions" do
- char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A
- /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase
- char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A
- /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase
- end
- end
-
- ruby_version_is ""..."2.4" do
- it "does not support handling unicode 9.0 characters with POSIX bracket expressions" do
- char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A
- /[[:lower:]]/.match(char_lowercase).should == nil
-
- char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A
- /[[:upper:]]/.match(char_lowercase).should == nil
- end
-
- it "supports handling unicode 8.0 characters with POSIX bracket expressions" do
- char_lowercase = "\u{A7B5}" # LATIN SMALL LETTER BETA
- /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase
-
- char_uppercase = "\u{A7B4}" # LATIN CAPITAL LETTER BETA
- /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase
- end
+ it "support handling unicode 9.0 characters with POSIX bracket expressions" do
+ char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A
+ /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase
+ char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A
+ /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase
end
end
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index 7df8b6db90..b0eb949c1a 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -449,22 +449,14 @@ describe "The rescue keyword" do
end
end
- ruby_version_is ""..."2.4" do
- it "fails when using 'rescue' in method arguments" do
- lambda { eval '1.+ (1 rescue 1)' }.should raise_error(SyntaxError)
- end
+ it "allows 'rescue' in method arguments" do
+ two = eval '1.+ (raise("Error") rescue 1)'
+ two.should == 2
end
- ruby_version_is "2.4" do
- it "allows 'rescue' in method arguments" do
- two = eval '1.+ (raise("Error") rescue 1)'
- two.should == 2
- end
-
- it "requires the 'rescue' in method arguments to be wrapped in parens" do
- lambda { eval '1.+(1 rescue 1)' }.should raise_error(SyntaxError)
- eval('1.+((1 rescue 1))').should == 2
- end
+ it "requires the 'rescue' in method arguments to be wrapped in parens" do
+ lambda { eval '1.+(1 rescue 1)' }.should raise_error(SyntaxError)
+ eval('1.+((1 rescue 1))').should == 2
end
describe "inline form" do
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 12c178fc88..e697b0b44c 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -362,7 +362,7 @@ describe "The return keyword" do
END_OF_CODE
end
- ruby_bug "#14061", "2.4"..."2.6" do
+ ruby_bug "#14061", "2.4"..."2.5" do
it "fires ensure block before returning while loads file" do
File.write(@filename, <<-END_OF_CODE)
ScratchPad << "before begin"
diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb
index 8a2aa81819..e4e8448174 100644
--- a/spec/ruby/language/yield_spec.rb
+++ b/spec/ruby/language/yield_spec.rb
@@ -69,12 +69,10 @@ describe "The yield call" do
}.should raise_error(ArgumentError)
end
- ruby_bug "#12705", ""..."2.5" do
- it "should not destructure an Array into multiple arguments" do
- lambda {
- @y.s([1, 2], &lambda { |a,b| [a,b] })
- }.should raise_error(ArgumentError)
- end
+ it "should not destructure an Array into multiple arguments" do
+ lambda {
+ @y.s([1, 2], &lambda { |a,b| [a,b] })
+ }.should raise_error(ArgumentError)
end
end
end
@@ -172,6 +170,12 @@ describe "The yield call" do
end
end
+ describe "taking a splat and a keyword argument" do
+ it "passes it as an array of the values and a hash" do
+ @y.k([1, 2]) { |*a| a }.should == [1, 2, {:b=>true}]
+ end
+ end
+
it "uses captured block of a block used in define_method" do
@y.deep(2).should == 4
end
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 03f0c0adfd..2312a4e910 100644
--- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -58,18 +58,9 @@ describe "Kernel#BigDecimal" do
end
end
- ruby_version_is ""..."2.4" do
- it "treats invalid strings as 0.0" do
- BigDecimal("ruby").should == BigDecimal("0.0")
- BigDecimal(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal("0.0")
- end
- end
-
- ruby_version_is "2.4" do
- it "raises ArgumentError for invalid strings" do
- lambda { BigDecimal("ruby") }.should raise_error(ArgumentError)
- lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError for invalid strings" do
+ lambda { BigDecimal("ruby") }.should raise_error(ArgumentError)
+ lambda { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError)
end
it "allows omitting the integer part" do
diff --git a/spec/ruby/library/bigdecimal/gt_spec.rb b/spec/ruby/library/bigdecimal/gt_spec.rb
index c815aa0353..8ebb631cb8 100644
--- a/spec/ruby/library/bigdecimal/gt_spec.rb
+++ b/spec/ruby/library/bigdecimal/gt_spec.rb
@@ -68,15 +68,13 @@ 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
+ 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
it "properly handles NaN values" do
diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb
index 14534eec80..6b0b7f41e9 100644
--- a/spec/ruby/library/bigdecimal/gte_spec.rb
+++ b/spec/ruby/library/bigdecimal/gte_spec.rb
@@ -72,15 +72,13 @@ 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
+ 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
it "properly handles NaN values" do
diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb
index 7e1a8297e2..cd2f1a3cd4 100644
--- a/spec/ruby/library/bigdecimal/inspect_spec.rb
+++ b/spec/ruby/library/bigdecimal/inspect_spec.rb
@@ -11,37 +11,7 @@ describe "BigDecimal#inspect" do
@bigdec.inspect.kind_of?(String).should == true
end
- ruby_version_is ""..."2.4" do
- it "returns String starting with #" do
- @bigdec.inspect[0].should == ?#
- end
-
- it "encloses information in angle brackets" do
- @bigdec.inspect.should =~ /^.<.*>$/
- end
-
- it "is comma separated list of three items" do
- @bigdec.inspect.should =~ /...*,.*,.*/
- end
-
- it "value after first comma is value as string" do
- @bigdec.inspect.split(",")[1].should == "\'0.12345678E4\'"
- end
-
- it "last part is number of significant digits" do
- signific_string = "#{@bigdec.precs[0]}(#{@bigdec.precs[1]})"
- @bigdec.inspect.split(",")[2].should == signific_string + ">"
- end
-
- it "looks like this" do
- regex = /^\#\<BigDecimal\:.*,'0\.12345678E4',[0-9]+\([0-9]+\)>$/
- @bigdec.inspect.should =~ regex
- end
- end
-
- ruby_version_is "2.4" do
- it "looks like this" do
- @bigdec.inspect.should == "0.12345678e4"
- end
+ it "looks like this" do
+ @bigdec.inspect.should == "0.12345678e4"
end
end
diff --git a/spec/ruby/library/bigdecimal/lt_spec.rb b/spec/ruby/library/bigdecimal/lt_spec.rb
index 8cf92fedd2..1894daf17f 100644
--- a/spec/ruby/library/bigdecimal/lt_spec.rb
+++ b/spec/ruby/library/bigdecimal/lt_spec.rb
@@ -66,15 +66,13 @@ 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
+ 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
it "properly handles NaN values" do
diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb
index eff6547369..56d3caa3b1 100644
--- a/spec/ruby/library/bigdecimal/lte_spec.rb
+++ b/spec/ruby/library/bigdecimal/lte_spec.rb
@@ -72,15 +72,13 @@ 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
+ 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
it "properly handles NaN values" do
diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb
index 07b96acb2b..467e2c5563 100644
--- a/spec/ruby/library/bigdecimal/round_spec.rb
+++ b/spec/ruby/library/bigdecimal/round_spec.rb
@@ -62,129 +62,157 @@ describe "BigDecimal#round" do
@n2_49.round(0).should == @neg_two
end
- describe "BigDecimal::ROUND_UP" do
- it "rounds values away from zero" do
- @p1_50.round(0, BigDecimal::ROUND_UP).should == @two
- @p1_51.round(0, BigDecimal::ROUND_UP).should == @two
- @p1_49.round(0, BigDecimal::ROUND_UP).should == @two
- @n1_50.round(0, BigDecimal::ROUND_UP).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_UP).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_UP).should == @neg_two
-
- @p2_50.round(0, BigDecimal::ROUND_UP).should == @three
- @p2_51.round(0, BigDecimal::ROUND_UP).should == @three
- @p2_49.round(0, BigDecimal::ROUND_UP).should == @three
- @n2_50.round(0, BigDecimal::ROUND_UP).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_UP).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_UP).should == @neg_three
+ ["BigDecimal::ROUND_UP", ":up"].each do |way|
+ describe way do
+ it "rounds values away from zero" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @two
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_two
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @three
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_three
+ end
end
end
- describe "BigDecimal::ROUND_DOWN" do
- it "rounds values towards zero" do
- @p1_50.round(0, BigDecimal::ROUND_DOWN).should == @one
- @p1_51.round(0, BigDecimal::ROUND_DOWN).should == @one
- @p1_49.round(0, BigDecimal::ROUND_DOWN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
- @n1_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_DOWN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_DOWN).should == @two
- @p2_49.round(0, BigDecimal::ROUND_DOWN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
- @n2_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
+ ["BigDecimal::ROUND_DOWN", ":down", ":truncate"].each do |way|
+ describe way do
+ it "rounds values towards zero" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @one
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_one
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @two
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_two
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_HALF_UP" do
- it "rounds values >= 5 up, otherwise down" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @p1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @three
- @p2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
+ ["BigDecimal::ROUND_HALF_UP", ":half_up", ":default"].each do |way|
+ describe way do
+ it "rounds values >= 5 up, otherwise down" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_HALF_DOWN" do
- it "rounds values > 5 up, otherwise down" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one
- @p1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
+ ["BigDecimal::ROUND_HALF_DOWN", ":half_down"].each do |way|
+ describe way do
+ it "rounds values > 5 up, otherwise down" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_CEILING" do
- it "rounds values towards +infinity" do
- @p1_50.round(0, BigDecimal::ROUND_CEILING).should == @two
- @p1_51.round(0, BigDecimal::ROUND_CEILING).should == @two
- @p1_49.round(0, BigDecimal::ROUND_CEILING).should == @two
- @n1_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
- @n1_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_CEILING).should == @three
- @p2_51.round(0, BigDecimal::ROUND_CEILING).should == @three
- @p2_49.round(0, BigDecimal::ROUND_CEILING).should == @three
- @n2_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
- @n2_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
+ ["BigDecimal::ROUND_CEILING", ":ceiling", ":ceil"].each do |way|
+ describe way do
+ it "rounds values towards +infinity" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @two
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_one
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @three
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_two
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_FLOOR" do
- it "rounds values towards -infinity" do
- @p1_50.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @p1_51.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @p1_49.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @n1_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
-
- @p2_50.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @p2_51.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @p2_49.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @n2_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
+ ["BigDecimal::ROUND_FLOOR", ":floor"].each do |way|
+ describe way do
+ it "rounds values towards -infinity" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @one
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_two
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @two
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_three
+ end
end
end
- describe "BigDecimal::ROUND_HALF_EVEN" do
- it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
+ ["BigDecimal::ROUND_HALF_EVEN", ":half_even", ":banker"].each do |way|
+ describe way do
+ it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
@@ -199,4 +227,8 @@ describe "BigDecimal#round" do
lambda { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError)
lambda { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
end
+
+ it "raise for a non-existent round mode" do
+ lambda { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode")
+ end
end
diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb
index 75741c5050..247db1a5d2 100644
--- a/spec/ruby/library/bigdecimal/to_s_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_s_spec.rb
@@ -15,16 +15,8 @@ describe "BigDecimal#to_s" do
@bigneg.to_s.kind_of?(String).should == true
end
- ruby_version_is ''...'2.4' do
- it "the default format looks like 0.xxxxEnn" do
- @bigdec.to_s.should =~ /^0\.[0-9]*E[0-9]*$/
- end
- end
-
- ruby_version_is '2.4' do
- it "the default format looks like 0.xxxxenn" do
- @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
- end
+ it "the default format looks like 0.xxxxenn" do
+ @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
end
it "takes an optional argument" do
diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb
index c714aab300..90d2c3d148 100644
--- a/spec/ruby/library/cgi/cookie/parse_spec.rb
+++ b/spec/ruby/library/cgi/cookie/parse_spec.rb
@@ -10,25 +10,12 @@ describe "CGI::Cookie.parse" do
CGI::Cookie.parse("first cookie=one&two;second cookie=three&four").should == expected
end
- ruby_version_is ""..."2.4" do
- it "uses , for cookie separators" do
- expected = {
- "first cookie" => ["one", "two"],
- "second cookie" => ["three", "four"],
- "third_cookie" => ["five", "six"]
- }
- CGI::Cookie.parse("first cookie=one&two;second cookie=three&four,third_cookie=five&six").should == expected
- end
- end
-
- ruby_version_is "2.4" do
- it "does not use , for cookie separators" do
- expected = {
- "first cookie" => ["one", "two"],
- "second cookie" => ["three", "four,third_cookie=five", "six"]
- }
- CGI::Cookie.parse("first cookie=one&two;second cookie=three&four,third_cookie=five&six").should == expected
- end
+ it "does not use , for cookie separators" do
+ expected = {
+ "first cookie" => ["one", "two"],
+ "second cookie" => ["three", "four,third_cookie=five", "six"]
+ }
+ CGI::Cookie.parse("first cookie=one&two;second cookie=three&four,third_cookie=five&six").should == expected
end
it "unescapes the Cookie values" do
diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb
index 8bdb7829d3..f57ab4c778 100644
--- a/spec/ruby/library/conditionvariable/wait_spec.rb
+++ b/spec/ruby/library/conditionvariable/wait_spec.rb
@@ -2,6 +2,15 @@ require_relative '../../spec_helper'
require 'thread'
describe "ConditionVariable#wait" do
+ it "calls #sleep on the given object" do
+ o = Object.new
+ o.should_receive(:sleep).with(1234)
+
+ cv = ConditionVariable.new
+
+ cv.wait(o, 1234)
+ end
+
it "returns self" do
m = Mutex.new
cv = ConditionVariable.new
diff --git a/spec/ruby/library/coverage/fixtures/spec_helper.rb b/spec/ruby/library/coverage/fixtures/spec_helper.rb
deleted file mode 100644
index 19094e5c36..0000000000
--- a/spec/ruby/library/coverage/fixtures/spec_helper.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module CoverageSpecs
- # Clear old results from the result hash
- # https://bugs.ruby-lang.org/issues/12220
- def self.filtered_result
- result = Coverage.result
- ruby_version_is ""..."2.4" do
- result = result.reject { |_k, v| v.empty? }
- end
- result
- end
-end
diff --git a/spec/ruby/library/coverage/peek_result_spec.rb b/spec/ruby/library/coverage/peek_result_spec.rb
index 897fc4d978..9d7c890faa 100644
--- a/spec/ruby/library/coverage/peek_result_spec.rb
+++ b/spec/ruby/library/coverage/peek_result_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require fixture __FILE__, 'spec_helper'
require 'coverage'
describe 'Coverage.peek_result' do
diff --git a/spec/ruby/library/coverage/result_spec.rb b/spec/ruby/library/coverage/result_spec.rb
index f964c9457a..ebfa5538b4 100644
--- a/spec/ruby/library/coverage/result_spec.rb
+++ b/spec/ruby/library/coverage/result_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require fixture __FILE__, 'spec_helper'
require 'coverage'
describe 'Coverage.result' do
@@ -16,7 +15,7 @@ describe 'Coverage.result' do
it 'gives the covered files as a hash with arrays of count or nil' do
Coverage.start
require @class_file.chomp('.rb')
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {
@class_file => [
@@ -27,7 +26,7 @@ describe 'Coverage.result' do
it 'no requires/loads should give empty hash' do
Coverage.start
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {}
end
@@ -43,11 +42,11 @@ describe 'Coverage.result' do
it 'second run should give same result' do
Coverage.start
load @class_file
- result1 = CoverageSpecs.filtered_result
+ result1 = Coverage.result
Coverage.start
load @class_file
- result2 = CoverageSpecs.filtered_result
+ result2 = Coverage.result
result2.should == result1
end
@@ -58,7 +57,7 @@ describe 'Coverage.result' do
Coverage.result
Coverage.start
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {}
end
@@ -66,13 +65,13 @@ describe 'Coverage.result' do
it 'second Coverage.start does nothing' do
Coverage.start
require @config_file.chomp('.rb')
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == { @config_file => [1, 1, 1] }
end
it 'does not include the file starting coverage since it is not tracked' do
require @config_file.chomp('.rb')
- CoverageSpecs.filtered_result.should_not include(@config_file)
+ Coverage.result.should_not include(@config_file)
end
end
diff --git a/spec/ruby/library/csv/liberal_parsing_spec.rb b/spec/ruby/library/csv/liberal_parsing_spec.rb
index a2dda36c99..2929d6e2aa 100644
--- a/spec/ruby/library/csv/liberal_parsing_spec.rb
+++ b/spec/ruby/library/csv/liberal_parsing_spec.rb
@@ -1,21 +1,19 @@
require_relative '../../spec_helper'
require 'csv'
-ruby_version_is '2.4' do
- describe "CSV#liberal_parsing?" do
- it "returns true if illegal input is handled" do
- csv = CSV.new("", liberal_parsing: true)
- csv.liberal_parsing?.should == true
- end
+describe "CSV#liberal_parsing?" do
+ it "returns true if illegal input is handled" do
+ csv = CSV.new("", liberal_parsing: true)
+ csv.liberal_parsing?.should == true
+ end
- it "returns false if illegal input is not handled" do
- csv = CSV.new("", liberal_parsing: false)
- csv.liberal_parsing?.should == false
- end
+ it "returns false if illegal input is not handled" do
+ csv = CSV.new("", liberal_parsing: false)
+ csv.liberal_parsing?.should == false
+ end
- it "returns false by default" do
- csv = CSV.new("")
- csv.liberal_parsing?.should == false
- end
+ it "returns false by default" do
+ csv = CSV.new("")
+ csv.liberal_parsing?.should == false
end
end
diff --git a/spec/ruby/library/csv/parse_spec.rb b/spec/ruby/library/csv/parse_spec.rb
index fc3f04378b..ef5d4ea3ca 100644
--- a/spec/ruby/library/csv/parse_spec.rb
+++ b/spec/ruby/library/csv/parse_spec.rb
@@ -85,11 +85,9 @@ describe "CSV.parse" do
}.should raise_error(CSV::MalformedCSVError)
end
- ruby_version_is '2.4' do
- it "handles illegal input with the liberal_parsing option" do
- illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
- result = CSV.parse(illegal_input, liberal_parsing: true)
- result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
- end
+ it "handles illegal input with the liberal_parsing option" do
+ illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
+ result = CSV.parse(illegal_input, liberal_parsing: true)
+ result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
end
end
diff --git a/spec/ruby/library/csv/readlines_spec.rb b/spec/ruby/library/csv/readlines_spec.rb
index 882266657e..14dea34381 100644
--- a/spec/ruby/library/csv/readlines_spec.rb
+++ b/spec/ruby/library/csv/readlines_spec.rb
@@ -26,12 +26,10 @@ describe "CSV#readlines" do
-> { csv.readlines }.should raise_error(CSV::MalformedCSVError)
end
- ruby_version_is '2.4' do
- it "handles illegal input with the liberal_parsing option" do
- illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
- csv = CSV.new(illegal_input, liberal_parsing: true)
- result = csv.readlines
- result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
- end
+ it "handles illegal input with the liberal_parsing option" do
+ illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
+ csv = CSV.new(illegal_input, liberal_parsing: true)
+ result = csv.readlines
+ result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
end
end
diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb
index 9cdce80ef3..9f22153c15 100644
--- a/spec/ruby/library/datetime/now_spec.rb
+++ b/spec/ruby/library/datetime/now_spec.rb
@@ -7,13 +7,13 @@ describe "DateTime.now" do
end
it "sets the current date" do
- (DateTime.now - Date.today).to_f.should be_close(0.0, 2.0)
+ (DateTime.now - Date.today).to_f.should be_close(0.0, TIME_TOLERANCE)
end
it "sets the current time" do
dt = DateTime.now
now = Time.now
- (dt.to_time - now).should be_close(0.0, 10.0)
+ (dt.to_time - now).should be_close(0.0, TIME_TOLERANCE)
end
it "grabs the local timezone" do
diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb
index 3bda369ca7..a11b6e30e1 100644
--- a/spec/ruby/library/datetime/to_time_spec.rb
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -18,21 +18,19 @@ describe "DateTime#to_time" do
time.sec.should == 59
end
- ruby_version_is "2.4" do
- it "preserves the same time regardless of local time or zone" do
- date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00')
+ it "preserves the same time regardless of local time or zone" do
+ date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00')
- with_timezone("Pacific/Pago_Pago", -11) do
- time = date.to_time
+ with_timezone("Pacific/Pago_Pago", -11) do
+ time = date.to_time
- time.utc_offset.should == 3 * 3600
- time.year.should == date.year
- time.mon.should == date.mon
- time.day.should == date.day
- time.hour.should == date.hour
- time.min.should == date.min
- time.sec.should == date.sec
- end
+ time.utc_offset.should == 3 * 3600
+ time.year.should == date.year
+ time.mon.should == date.mon
+ time.day.should == date.day
+ time.hour.should == date.hour
+ time.min.should == date.min
+ time.sec.should == date.sec
end
end
end
diff --git a/spec/ruby/library/ipaddr/operator_spec.rb b/spec/ruby/library/ipaddr/operator_spec.rb
index a0984bfcfe..f90c56009c 100644
--- a/spec/ruby/library/ipaddr/operator_spec.rb
+++ b/spec/ruby/library/ipaddr/operator_spec.rb
@@ -54,11 +54,9 @@ describe "IPAddr Operator" do
@a.should_not == IPAddr.new("3ffe:505:3::")
end
- ruby_version_is '2.4' do
- # https://bugs.ruby-lang.org/issues/12799
- it "tests for equality correctly if object cannot be converted to IPAddr" do
- IPAddr.new("1.1.1.1").should_not == "sometext"
- end
+ # https://bugs.ruby-lang.org/issues/12799
+ it "tests for equality correctly if object cannot be converted to IPAddr" do
+ IPAddr.new("1.1.1.1").should_not == "sometext"
end
it "sets a mask" do
diff --git a/spec/ruby/library/logger/logger/new_spec.rb b/spec/ruby/library/logger/logger/new_spec.rb
index 3a83968eb1..43f701a3dd 100644
--- a/spec/ruby/library/logger/logger/new_spec.rb
+++ b/spec/ruby/library/logger/logger/new_spec.rb
@@ -61,60 +61,58 @@ describe "Logger#new" do
rm_r path, "#{path}.0"
end
- ruby_version_is "2.4" do
- it "receives level symbol as keyword argument" do
- logger = Logger.new(STDERR, level: :info)
- logger.level.should == Logger::INFO
- end
+ it "receives level symbol as keyword argument" do
+ logger = Logger.new(STDERR, level: :info)
+ logger.level.should == Logger::INFO
+ end
- it "receives level as keyword argument" do
- logger = Logger.new(STDERR, level: Logger::INFO)
- logger.level.should == Logger::INFO
- end
+ it "receives level as keyword argument" do
+ logger = Logger.new(STDERR, level: Logger::INFO)
+ logger.level.should == Logger::INFO
+ end
- it "receives progname as keyword argument" do
- progname = "progname"
+ it "receives progname as keyword argument" do
+ progname = "progname"
- logger = Logger.new(STDERR, progname: progname)
- logger.progname.should == progname
- end
+ logger = Logger.new(STDERR, progname: progname)
+ logger.progname.should == progname
+ end
- it "receives datetime_format as keyword argument" do
- datetime_format = "%H:%M:%S"
+ it "receives datetime_format as keyword argument" do
+ datetime_format = "%H:%M:%S"
- logger = Logger.new(STDERR, datetime_format: datetime_format)
- logger.datetime_format.should == datetime_format
- end
+ logger = Logger.new(STDERR, datetime_format: datetime_format)
+ logger.datetime_format.should == datetime_format
+ end
- it "receives formatter as keyword argument" do
- formatter = Class.new do
- def call(_severity, _time, _progname, _msg); end
- end.new
+ it "receives formatter as keyword argument" do
+ formatter = Class.new do
+ def call(_severity, _time, _progname, _msg); end
+ end.new
- logger = Logger.new(STDERR, formatter: formatter)
- logger.formatter.should == formatter
- end
+ logger = Logger.new(STDERR, formatter: formatter)
+ logger.formatter.should == formatter
+ end
- it "receives shift_period_suffix " do
- shift_period_suffix = "%Y-%m-%d"
- path = tmp("shift_period_suffix_test.log")
- now = Time.now
- tomorrow = Time.at(now.to_i + 60 * 60 * 24)
- logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix)
+ it "receives shift_period_suffix " do
+ shift_period_suffix = "%Y-%m-%d"
+ path = tmp("shift_period_suffix_test.log")
+ now = Time.now
+ tomorrow = Time.at(now.to_i + 60 * 60 * 24)
+ logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix)
- logger.add Logger::INFO, 'message'
+ logger.add Logger::INFO, 'message'
- Time.stub!(:now).and_return(tomorrow)
- logger.add Logger::INFO, 'second message'
+ Time.stub!(:now).and_return(tomorrow)
+ logger.add Logger::INFO, 'second message'
- shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}"
+ shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}"
- File.exist?(shifted_path).should == true
+ File.exist?(shifted_path).should == true
- logger.close
+ logger.close
- rm_r path, shifted_path
- end
+ rm_r path, shifted_path
end
end
diff --git a/spec/ruby/library/net/ftp/initialize_spec.rb b/spec/ruby/library/net/ftp/initialize_spec.rb
index cd6252ac31..507320e494 100644
--- a/spec/ruby/library/net/ftp/initialize_spec.rb
+++ b/spec/ruby/library/net/ftp/initialize_spec.rb
@@ -89,318 +89,316 @@ describe "Net::FTP#initialize" do
end
end
- ruby_version_is '2.4' do
- before :each do
- @ftp.stub!(:login)
- end
+ before :each do
+ @ftp.stub!(:login)
+ end
- describe 'when the host' do
- describe 'is set' do
- describe 'and port option' do
- describe 'is set' do
- it 'tries to connect to the host on the specified port' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ port: 8080 })
- @ftp.should_receive(:connect).with('localhost', 8080)
+ describe 'when the host' do
+ describe 'is set' do
+ describe 'and port option' do
+ describe 'is set' do
+ it 'tries to connect to the host on the specified port' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ port: 8080 })
+ @ftp.should_receive(:connect).with('localhost', 8080)
- @ftp.send(:initialize, 'localhost', options)
- end
+ @ftp.send(:initialize, 'localhost', options)
end
+ end
- describe 'is not set' do
- it 'tries to connect to the host without a port' do
- @ftp.should_receive(:connect).with("localhost", *@port_args)
+ describe 'is not set' do
+ it 'tries to connect to the host without a port' do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
- @ftp.send(:initialize, 'localhost')
- end
+ @ftp.send(:initialize, 'localhost')
end
end
+ end
- describe 'when the username option' do
- describe 'is set' do
- describe 'and the password option' do
- describe 'is set' do
- describe 'and the account option' do
- describe 'is set' do
- it 'tries to log in with the supplied parameters' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' })
- @ftp.should_receive(:login).with('a', 'topsecret', 'b')
-
- @ftp.send(:initialize, 'localhost', options)
- end
+ describe 'when the username option' do
+ describe 'is set' do
+ describe 'and the password option' do
+ describe 'is set' do
+ describe 'and the account option' do
+ describe 'is set' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' })
+ @ftp.should_receive(:login).with('a', 'topsecret', 'b')
+
+ @ftp.send(:initialize, 'localhost', options)
end
+ end
- describe 'is unset' do
- it 'tries to log in with the supplied parameters' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' })
- @ftp.should_receive(:login).with('a', 'topsecret', nil)
+ describe 'is unset' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' })
+ @ftp.should_receive(:login).with('a', 'topsecret', nil)
- @ftp.send(:initialize, 'localhost', options)
- end
+ @ftp.send(:initialize, 'localhost', options)
end
end
end
+ end
- describe 'is unset' do
- describe 'and the account option' do
- describe 'is set' do
- it 'tries to log in with the supplied parameters' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' })
- @ftp.should_receive(:login).with('a', nil, 'b')
+ describe 'is unset' do
+ describe 'and the account option' do
+ describe 'is set' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' })
+ @ftp.should_receive(:login).with('a', nil, 'b')
- @ftp.send(:initialize, 'localhost', options)
- end
+ @ftp.send(:initialize, 'localhost', options)
end
+ end
- describe 'is unset' do
- it 'tries to log in with the supplied parameters' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ username: 'a'})
- @ftp.should_receive(:login).with('a', nil, nil)
+ describe 'is unset' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a'})
+ @ftp.should_receive(:login).with('a', nil, nil)
- @ftp.send(:initialize, 'localhost', options)
- end
+ @ftp.send(:initialize, 'localhost', options)
end
end
end
end
end
+ end
- describe 'is not set' do
- it 'does not try to log in' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({})
- @ftp.should_not_receive(:login)
+ describe 'is not set' do
+ it 'does not try to log in' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
+ @ftp.should_not_receive(:login)
- @ftp.send(:initialize, 'localhost', options)
- end
+ @ftp.send(:initialize, 'localhost', options)
end
end
end
+ end
- describe 'is unset' do
- it 'does not try to connect' do
- @ftp.should_not_receive(:connect)
+ describe 'is unset' do
+ it 'does not try to connect' do
+ @ftp.should_not_receive(:connect)
- @ftp.send(:initialize)
- end
+ @ftp.send(:initialize)
+ end
- it 'does not try to log in' do
- @ftp.should_not_receive(:login)
+ it 'does not try to log in' do
+ @ftp.should_not_receive(:login)
- @ftp.send(:initialize)
- end
+ @ftp.send(:initialize)
end
end
+ end
- describe 'when the passive option' do
- describe 'is set' do
- describe 'to true' do
- it 'sets passive to true' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ passive: true })
-
- @ftp.send(:initialize, nil, options)
- @ftp.passive.should == true
- end
- end
-
- describe 'to false' do
- it 'sets passive to false' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ passive: false })
+ describe 'when the passive option' do
+ describe 'is set' do
+ describe 'to true' do
+ it 'sets passive to true' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ passive: true })
- @ftp.send(:initialize, nil, options)
- @ftp.passive.should == false
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.passive.should == true
end
end
- describe 'is unset' do
+ describe 'to false' do
it 'sets passive to false' do
- @ftp.send(:initialize)
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ passive: false })
+
+ @ftp.send(:initialize, nil, options)
@ftp.passive.should == false
end
end
end
- describe 'when the debug_mode option' do
- describe 'is set' do
- describe 'to true' do
- it 'sets debug_mode to true' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ debug_mode: true })
-
- @ftp.send(:initialize, nil, options)
- @ftp.debug_mode.should == true
- end
- end
+ describe 'is unset' do
+ it 'sets passive to false' do
+ @ftp.send(:initialize)
+ @ftp.passive.should == false
+ end
+ end
+ end
- describe 'to false' do
- it 'sets debug_mode to false' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ debug_mode: false })
+ describe 'when the debug_mode option' do
+ describe 'is set' do
+ describe 'to true' do
+ it 'sets debug_mode to true' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ debug_mode: true })
- @ftp.send(:initialize, nil, options)
- @ftp.debug_mode.should == false
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.debug_mode.should == true
end
end
- describe 'is unset' do
+ describe 'to false' do
it 'sets debug_mode to false' do
- @ftp.send(:initialize)
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ debug_mode: false })
+
+ @ftp.send(:initialize, nil, options)
@ftp.debug_mode.should == false
end
end
end
- describe 'when the open_timeout option' do
- describe 'is set' do
- it 'sets open_timeout to the specified value' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ open_timeout: 42 })
+ describe 'is unset' do
+ it 'sets debug_mode to false' do
+ @ftp.send(:initialize)
+ @ftp.debug_mode.should == false
+ end
+ end
+ end
- @ftp.send(:initialize, nil, options)
- @ftp.open_timeout.should == 42
- end
+ describe 'when the open_timeout option' do
+ describe 'is set' do
+ it 'sets open_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ open_timeout: 42 })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.open_timeout.should == 42
end
+ end
- describe 'is not set' do
- it 'sets open_timeout to nil' do
- @ftp.send(:initialize)
- @ftp.open_timeout.should == nil
- end
+ describe 'is not set' do
+ it 'sets open_timeout to nil' do
+ @ftp.send(:initialize)
+ @ftp.open_timeout.should == nil
end
end
+ end
- describe 'when the read_timeout option' do
- describe 'is set' do
- it 'sets read_timeout to the specified value' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ read_timeout: 100 })
+ describe 'when the read_timeout option' do
+ describe 'is set' do
+ it 'sets read_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ read_timeout: 100 })
- @ftp.send(:initialize, nil, options)
- @ftp.read_timeout.should == 100
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.read_timeout.should == 100
end
+ end
- describe 'is not set' do
- it 'sets read_timeout to the default value' do
- @ftp.send(:initialize)
- @ftp.read_timeout.should == 60
- end
+ describe 'is not set' do
+ it 'sets read_timeout to the default value' do
+ @ftp.send(:initialize)
+ @ftp.read_timeout.should == 60
end
end
+ end
- describe 'when the ssl_handshake_timeout option' do
- describe 'is set' do
- it 'sets ssl_handshake_timeout to the specified value' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 })
+ describe 'when the ssl_handshake_timeout option' do
+ describe 'is set' do
+ it 'sets ssl_handshake_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 })
- @ftp.send(:initialize, nil, options)
- @ftp.ssl_handshake_timeout.should == 23
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.ssl_handshake_timeout.should == 23
end
+ end
- describe 'is not set' do
- it 'sets ssl_handshake_timeout to nil' do
- @ftp.send(:initialize)
- @ftp.ssl_handshake_timeout.should == nil
- end
+ describe 'is not set' do
+ it 'sets ssl_handshake_timeout to nil' do
+ @ftp.send(:initialize)
+ @ftp.ssl_handshake_timeout.should == nil
end
end
+ end
- describe 'when the ssl option' do
- describe 'is set' do
- describe "and the ssl option's value is true" do
- it 'initializes ssl_context to a blank SSLContext object' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ ssl: true })
+ describe 'when the ssl option' do
+ describe 'is set' do
+ describe "and the ssl option's value is true" do
+ it 'initializes ssl_context to a blank SSLContext object' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true })
- ssl_context = OpenSSL::SSL::SSLContext.allocate
- ssl_context.stub!(:set_params)
+ ssl_context = OpenSSL::SSL::SSLContext.allocate
+ ssl_context.stub!(:set_params)
- OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
- ssl_context.should_receive(:set_params).with({})
+ OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
+ ssl_context.should_receive(:set_params).with({})
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@ssl_context).should == ssl_context
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == ssl_context
end
+ end
- describe "and the ssl option's value is a hash" do
- it 'initializes ssl_context to a configured SSLContext object' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} })
+ describe "and the ssl option's value is a hash" do
+ it 'initializes ssl_context to a configured SSLContext object' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} })
- ssl_context = OpenSSL::SSL::SSLContext.allocate
- ssl_context.stub!(:set_params)
+ ssl_context = OpenSSL::SSL::SSLContext.allocate
+ ssl_context.stub!(:set_params)
- OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
- ssl_context.should_receive(:set_params).with({key: 'value'})
+ OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
+ ssl_context.should_receive(:set_params).with({key: 'value'})
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@ssl_context).should == ssl_context
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == ssl_context
end
+ end
- describe 'and private_data_connection' do
- describe 'is set' do
- it 'sets private_data_connection to that value' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' })
+ describe 'and private_data_connection' do
+ describe 'is set' do
+ it 'sets private_data_connection to that value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' })
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@private_data_connection).should == 'true'
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == 'true'
end
+ end
- describe 'is not set' do
- it 'sets private_data_connection to nil' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ ssl: true })
+ describe 'is not set' do
+ it 'sets private_data_connection to nil' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true })
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@private_data_connection).should == true
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == true
end
end
end
+ end
- describe 'is not set' do
- it 'sets ssl_context to nil' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({})
+ describe 'is not set' do
+ it 'sets ssl_context to nil' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@ssl_context).should == nil
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == nil
+ end
- describe 'private_data_connection' do
- describe 'is set' do
- it 'raises an ArgumentError' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({ private_data_connection: true })
+ describe 'private_data_connection' do
+ describe 'is set' do
+ it 'raises an ArgumentError' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ private_data_connection: true })
- -> {
- @ftp.send(:initialize, nil, options)
- }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/)
- end
+ -> {
+ @ftp.send(:initialize, nil, options)
+ }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/)
end
+ end
- describe 'is not set' do
- it 'sets private_data_connection to false' do
- options = mock('ftp initialize options')
- options.should_receive(:to_hash).and_return({})
+ describe 'is not set' do
+ it 'sets private_data_connection to false' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
- @ftp.send(:initialize, nil, options)
- @ftp.instance_variable_get(:@private_data_connection).should == false
- end
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == false
end
end
end
diff --git a/spec/ruby/library/net/ftp/status_spec.rb b/spec/ruby/library/net/ftp/status_spec.rb
index 22d0d47254..c3874ea41e 100644
--- a/spec/ruby/library/net/ftp/status_spec.rb
+++ b/spec/ruby/library/net/ftp/status_spec.rb
@@ -22,10 +22,8 @@ describe "Net::FTP#status" do
@ftp.last_response.should == "211 System status, or system help reply. (STAT)\n"
end
- ruby_version_is "2.4" do
- it "sends the STAT command with an optional parameter to the server" do
- @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n"
- end
+ it "sends the STAT command with an optional parameter to the server" do
+ @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n"
end
it "returns the received information" do
diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net/http/http/post_spec.rb
index c8d41b9617..9f20a03c85 100644
--- a/spec/ruby/library/net/http/http/post_spec.rb
+++ b/spec/ruby/library/net/http/http/post_spec.rb
@@ -3,40 +3,38 @@ require 'net/http'
require 'uri'
require_relative 'fixtures/http_server'
-ruby_version_is '2.4' do
- describe "Net::HTTP.post" do
- before :each do
- NetHTTPSpecs.start_server
- end
+describe "Net::HTTP.post" do
+ before :each do
+ NetHTTPSpecs.start_server
+ end
- after :each do
- NetHTTPSpecs.stop_server
- end
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
- it "sends post request to the specified URI and returns response" do
- response = Net::HTTP.post(
- URI("http://localhost:#{NetHTTPSpecs.port}/request"),
- '{ "q": "ruby", "max": "50" }',
- "Content-Type" => "application/json")
- response.body.should == "Request type: POST"
- end
+ it "sends post request to the specified URI and returns response" do
+ response = Net::HTTP.post(
+ URI("http://localhost:#{NetHTTPSpecs.port}/request"),
+ '{ "q": "ruby", "max": "50" }',
+ "Content-Type" => "application/json")
+ response.body.should == "Request type: POST"
+ end
- it "returns a Net::HTTPResponse" do
- response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test")
- response.should be_kind_of(Net::HTTPResponse)
- end
+ it "returns a Net::HTTPResponse" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test")
+ response.should be_kind_of(Net::HTTPResponse)
+ end
- it "sends Content-Type: application/x-www-form-urlencoded by default" do
- response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
- response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]')
- end
+ it "sends Content-Type: application/x-www-form-urlencoded by default" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
+ response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]')
+ end
- it "does not support HTTP Basic Auth" do
- response = Net::HTTP.post(
- URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"),
- "test=test")
- response.body.should == "username: \npassword: "
- end
+ it "does not support HTTP Basic Auth" do
+ response = Net::HTTP.post(
+ URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"),
+ "test=test")
+ response.body.should == "username: \npassword: "
end
end
diff --git a/spec/ruby/library/optionparser/order_spec.rb b/spec/ruby/library/optionparser/order_spec.rb
index 9d8f48d320..e49bd25554 100644
--- a/spec/ruby/library/optionparser/order_spec.rb
+++ b/spec/ruby/library/optionparser/order_spec.rb
@@ -2,31 +2,27 @@ require_relative '../../spec_helper'
require 'optparse'
describe "OptionParser#order" do
- ruby_version_is '2.4' do
- it "accepts `into` keyword argument and stores result in it" do
- options = {}
- parser = OptionParser.new do |opts|
- opts.on("-v", "--[no-]verbose", "Run verbosely")
- opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
- end
- parser.order %w[--verbose --require optparse], into: options
-
- options.should == { verbose: true, require: "optparse" }
+ it "accepts `into` keyword argument and stores result in it" do
+ options = {}
+ parser = OptionParser.new do |opts|
+ opts.on("-v", "--[no-]verbose", "Run verbosely")
+ opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
end
+ parser.order %w[--verbose --require optparse], into: options
+
+ options.should == { verbose: true, require: "optparse" }
end
end
describe "OptionParser#order!" do
- ruby_version_is '2.4' do
- it "accepts `into` keyword argument and stores result in it" do
- options = {}
- parser = OptionParser.new do |opts|
- opts.on("-v", "--[no-]verbose", "Run verbosely")
- opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
- end
- parser.order! %w[--verbose --require optparse], into: options
-
- options.should == { verbose: true, require: "optparse" }
+ it "accepts `into` keyword argument and stores result in it" do
+ options = {}
+ parser = OptionParser.new do |opts|
+ opts.on("-v", "--[no-]verbose", "Run verbosely")
+ opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
end
+ parser.order! %w[--verbose --require optparse], into: options
+
+ options.should == { verbose: true, require: "optparse" }
end
end
diff --git a/spec/ruby/library/optionparser/parse_spec.rb b/spec/ruby/library/optionparser/parse_spec.rb
index 5b105a7d0e..9511acb1db 100644
--- a/spec/ruby/library/optionparser/parse_spec.rb
+++ b/spec/ruby/library/optionparser/parse_spec.rb
@@ -2,31 +2,27 @@ require_relative '../../spec_helper'
require 'optparse'
describe "OptionParser#parse" do
- ruby_version_is '2.4' do
- it "accepts `into` keyword argument and stores result in it" do
- options = {}
- parser = OptionParser.new do |opts|
- opts.on("-v", "--[no-]verbose", "Run verbosely")
- opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
- end
- parser.parse %w[--verbose --require optparse], into: options
-
- options.should == { verbose: true, require: "optparse" }
+ it "accepts `into` keyword argument and stores result in it" do
+ options = {}
+ parser = OptionParser.new do |opts|
+ opts.on("-v", "--[no-]verbose", "Run verbosely")
+ opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
end
+ parser.parse %w[--verbose --require optparse], into: options
+
+ options.should == { verbose: true, require: "optparse" }
end
end
describe "OptionParser#parse!" do
- ruby_version_is '2.4' do
- it "accepts `into` keyword argument and stores result in it" do
- options = {}
- parser = OptionParser.new do |opts|
- opts.on("-v", "--[no-]verbose", "Run verbosely")
- opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
- end
- parser.parse! %w[--verbose --require optparse], into: options
-
- options.should == { verbose: true, require: "optparse" }
+ it "accepts `into` keyword argument and stores result in it" do
+ options = {}
+ parser = OptionParser.new do |opts|
+ opts.on("-v", "--[no-]verbose", "Run verbosely")
+ opts.on("-r", "--require LIBRARY", "Require the LIBRARY before executing your script")
end
+ parser.parse! %w[--verbose --require optparse], into: options
+
+ options.should == { verbose: true, require: "optparse" }
end
end
diff --git a/spec/ruby/library/pathname/empty_spec.rb b/spec/ruby/library/pathname/empty_spec.rb
index 6f46486a69..4deade5b64 100644
--- a/spec/ruby/library/pathname/empty_spec.rb
+++ b/spec/ruby/library/pathname/empty_spec.rb
@@ -1,34 +1,32 @@
require_relative '../../spec_helper'
require 'pathname'
-ruby_version_is '2.4' do
- describe 'Pathname#empty?' do
- before :all do
- @file = tmp 'new_file_path_name.txt'
- touch @file
- @dir = tmp 'new_directory_path_name'
- Dir.mkdir @dir
- end
+describe 'Pathname#empty?' do
+ before :all do
+ @file = tmp 'new_file_path_name.txt'
+ touch @file
+ @dir = tmp 'new_directory_path_name'
+ Dir.mkdir @dir
+ end
- after :all do
- rm_r @file
- rm_r @dir
- end
+ after :all do
+ rm_r @file
+ rm_r @dir
+ end
- it 'returns true when file is not empty' do
- Pathname.new(__FILE__).empty?.should be_false
- end
+ it 'returns true when file is not empty' do
+ Pathname.new(__FILE__).empty?.should be_false
+ end
- it 'returns false when the directory is not empty' do
- Pathname.new(__dir__).empty?.should be_false
- end
+ it 'returns false when the directory is not empty' do
+ Pathname.new(__dir__).empty?.should be_false
+ end
- it 'return true when file is empty' do
- Pathname.new(@file).empty?.should be_true
- end
+ it 'return true when file is empty' do
+ Pathname.new(@file).empty?.should be_true
+ end
- it 'returns true when directory is empty' do
- Pathname.new(@dir).empty?.should be_true
- end
+ it 'returns true when directory is empty' do
+ Pathname.new(@dir).empty?.should be_true
end
end
diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb
index 71e3d376d1..6725de8289 100644
--- a/spec/ruby/library/rbconfig/rbconfig_spec.rb
+++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb
@@ -24,3 +24,13 @@ describe 'RbConfig::CONFIG' do
end
end
end
+
+describe "RbConfig::TOPDIR" do
+ it "either returns nil (if not installed) or the prefix" do
+ if RbConfig::TOPDIR
+ RbConfig::TOPDIR.should == RbConfig::CONFIG["prefix"]
+ else
+ RbConfig::TOPDIR.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/library/rexml/element/element_reference_spec.rb b/spec/ruby/library/rexml/element/element_reference_spec.rb
index db94303b1e..9660ff7507 100644
--- a/spec/ruby/library/rexml/element/element_reference_spec.rb
+++ b/spec/ruby/library/rexml/element/element_reference_spec.rb
@@ -9,14 +9,12 @@ describe "REXML::Element#[]" do
@doc.root.add_element @child
end
- ruby_version_is "2.4" do
- it "return attribute value if argument is string or symbol" do
- @doc.root[:foo].should == 'bar'
- @doc.root['foo'].should == 'bar'
- end
+ it "return attribute value if argument is string or symbol" do
+ @doc.root[:foo].should == 'bar'
+ @doc.root['foo'].should == 'bar'
+ end
- it "return nth element if argument is int" do
- @doc.root[0].should == @child
- end
+ it "return nth element if argument is int" do
+ @doc.root[0].should == @child
end
end
diff --git a/spec/ruby/library/set/compare_by_identity_spec.rb b/spec/ruby/library/set/compare_by_identity_spec.rb
index 363a108935..01b66ec92b 100644
--- a/spec/ruby/library/set/compare_by_identity_spec.rb
+++ b/spec/ruby/library/set/compare_by_identity_spec.rb
@@ -1,147 +1,143 @@
require_relative '../../spec_helper'
require 'set'
-ruby_version_is '2.4' do
- describe "Set#compare_by_identity" do
- it "compares its members by identity" do
- a = "a"
- b1 = "b"
- b2 = "b"
-
- set = Set.new
- set.compare_by_identity
- set.merge([a, a, b1, b2])
- set.to_a.sort.should == [a, b1, b2].sort
- end
-
- it "causes future comparisons on the receiver to be made by identity" do
- elt = [1]
- set = Set.new
- set << elt
- set.member?(elt.dup).should be_true
- set.compare_by_identity
- set.member?(elt.dup).should be_false
- end
-
- it "rehashes internally so that old members can be looked up" do
- set = Set.new
- (1..10).each { |k| set << k }
- o = Object.new
- def o.hash; 123; end
- set << o
+describe "Set#compare_by_identity" do
+ it "compares its members by identity" do
+ a = "a"
+ b1 = "b"
+ b2 = "b"
+
+ set = Set.new
+ set.compare_by_identity
+ set.merge([a, a, b1, b2])
+ set.to_a.sort.should == [a, b1, b2].sort
+ end
+
+ it "causes future comparisons on the receiver to be made by identity" do
+ elt = [1]
+ set = Set.new
+ set << elt
+ set.member?(elt.dup).should be_true
+ set.compare_by_identity
+ set.member?(elt.dup).should be_false
+ end
+
+ it "rehashes internally so that old members can be looked up" do
+ set = Set.new
+ (1..10).each { |k| set << k }
+ o = Object.new
+ def o.hash; 123; end
+ set << o
+ set.compare_by_identity
+ set.member?(o).should be_true
+ end
+
+ it "returns self" do
+ set = Set.new
+ result = set.compare_by_identity
+ result.should equal(set)
+ end
+
+ it "is idempotent and has no effect on an already compare_by_identity set" do
+ set = Set.new.compare_by_identity
+ set << :foo
+ set.compare_by_identity.should equal(set)
+ set.compare_by_identity?.should == true
+ set.to_a.should == [:foo]
+ end
+
+ it "uses the semantics of BasicObject#equal? to determine members identity" do
+ :a.equal?(:a).should == true
+ Set.new.compare_by_identity.merge([:a, :a]).to_a.should == [:a]
+
+ ary1 = [1]
+ ary2 = [1]
+ ary1.equal?(ary2).should == false
+ Set.new.compare_by_identity.merge([ary1, ary2]).to_a.sort.should == [ary1, ary2].sort
+ end
+
+ it "uses #equal? semantics, but doesn't actually call #equal? to determine identity" do
+ set = Set.new.compare_by_identity
+ obj = mock("equal")
+ obj.should_not_receive(:equal?)
+ set << :foo
+ set << obj
+ set.to_a.should == [:foo, obj]
+ end
+
+ it "does not call #hash on members" do
+ elt = mock("element")
+ elt.should_not_receive(:hash)
+ set = Set.new.compare_by_identity
+ set << elt
+ set.member?(elt).should be_true
+ end
+
+ it "regards #dup'd objects as having different identities" do
+ a1 = "a"
+ a2 = a1.dup
+
+ set = Set.new.compare_by_identity
+ set.merge([a1, a2])
+ set.to_a.sort.should == [a1, a2].sort
+ end
+
+ it "regards #clone'd objects as having different identities" do
+ a1 = "a"
+ a2 = a1.clone
+
+ set = Set.new.compare_by_identity
+ set.merge([a1, a2])
+ set.to_a.sort.should == [a1, a2].sort
+ end
+
+ it "raises a #{frozen_error_class} on frozen sets" do
+ set = Set.new.freeze
+ lambda {
set.compare_by_identity
- set.member?(o).should be_true
- end
-
- it "returns self" do
- set = Set.new
- result = set.compare_by_identity
- result.should equal(set)
- end
-
- it "is idempotent and has no effect on an already compare_by_identity set" do
- set = Set.new.compare_by_identity
- set << :foo
- set.compare_by_identity.should equal(set)
- set.compare_by_identity?.should == true
- set.to_a.should == [:foo]
- end
-
- it "uses the semantics of BasicObject#equal? to determine members identity" do
- :a.equal?(:a).should == true
- Set.new.compare_by_identity.merge([:a, :a]).to_a.should == [:a]
-
- ary1 = [1]
- ary2 = [1]
- ary1.equal?(ary2).should == false
- Set.new.compare_by_identity.merge([ary1, ary2]).to_a.sort.should == [ary1, ary2].sort
- end
-
- it "uses #equal? semantics, but doesn't actually call #equal? to determine identity" do
- set = Set.new.compare_by_identity
- obj = mock("equal")
- obj.should_not_receive(:equal?)
- set << :foo
- set << obj
- set.to_a.should == [:foo, obj]
- end
-
- it "does not call #hash on members" do
- elt = mock("element")
- elt.should_not_receive(:hash)
- set = Set.new.compare_by_identity
- set << elt
- set.member?(elt).should be_true
- end
-
- it "regards #dup'd objects as having different identities" do
- a1 = "a"
- a2 = a1.dup
-
- set = Set.new.compare_by_identity
- set.merge([a1, a2])
- set.to_a.sort.should == [a1, a2].sort
- end
-
- it "regards #clone'd objects as having different identities" do
- a1 = "a"
- a2 = a1.clone
-
- set = Set.new.compare_by_identity
- set.merge([a1, a2])
- set.to_a.sort.should == [a1, a2].sort
- end
-
- it "raises a #{frozen_error_class} on frozen sets" do
- set = Set.new.freeze
- lambda {
- set.compare_by_identity
- }.should raise_error(frozen_error_class, /frozen Hash/)
- end
-
- it "persists over #dups" do
- set = Set.new.compare_by_identity
- set << :a
- set_dup = set.dup
- set_dup.should == set
- set_dup << :a
- set_dup.to_a.should == [:a]
- end
-
- it "persists over #clones" do
- set = Set.new.compare_by_identity
- set << :a
- set_clone = set.clone
- set_clone.should == set
- set_clone << :a
- set_clone.to_a.should == [:a]
- end
-
- it "is not equal to set what does not compare by identity" do
- Set.new([1, 2]).should == Set.new([1, 2])
- Set.new([1, 2]).should_not == Set.new([1, 2]).compare_by_identity
- end
+ }.should raise_error(frozen_error_class, /frozen Hash/)
+ end
+
+ it "persists over #dups" do
+ set = Set.new.compare_by_identity
+ set << :a
+ set_dup = set.dup
+ set_dup.should == set
+ set_dup << :a
+ set_dup.to_a.should == [:a]
+ end
+
+ it "persists over #clones" do
+ set = Set.new.compare_by_identity
+ set << :a
+ set_clone = set.clone
+ set_clone.should == set
+ set_clone << :a
+ set_clone.to_a.should == [:a]
+ end
+
+ it "is not equal to set what does not compare by identity" do
+ Set.new([1, 2]).should == Set.new([1, 2])
+ Set.new([1, 2]).should_not == Set.new([1, 2]).compare_by_identity
end
end
-ruby_version_is '2.4' do
- describe "Set#compare_by_identity?" do
- it "returns false by default" do
- Set.new.compare_by_identity?.should == false
- end
+describe "Set#compare_by_identity?" do
+ it "returns false by default" do
+ Set.new.compare_by_identity?.should == false
+ end
- it "returns true once #compare_by_identity has been invoked on self" do
- set = Set.new
- set.compare_by_identity
- set.compare_by_identity?.should == true
- end
+ it "returns true once #compare_by_identity has been invoked on self" do
+ set = Set.new
+ set.compare_by_identity
+ set.compare_by_identity?.should == true
+ end
- it "returns true when called multiple times on the same set" do
- set = Set.new
- set.compare_by_identity
- set.compare_by_identity?.should == true
- set.compare_by_identity?.should == true
- set.compare_by_identity?.should == true
- end
+ it "returns true when called multiple times on the same set" do
+ set = Set.new
+ set.compare_by_identity
+ set.compare_by_identity?.should == true
+ set.compare_by_identity?.should == true
+ set.compare_by_identity?.should == true
end
end
diff --git a/spec/ruby/library/shellwords/shellwords_spec.rb b/spec/ruby/library/shellwords/shellwords_spec.rb
index b245fe862d..bb6bcb3d30 100644
--- a/spec/ruby/library/shellwords/shellwords_spec.rb
+++ b/spec/ruby/library/shellwords/shellwords_spec.rb
@@ -27,10 +27,8 @@ describe "Shellwords#shellwords" do
lambda { shellwords("a 'b c d e") }.should raise_error(ArgumentError)
end
- ruby_version_is '2.4' do
- # https://bugs.ruby-lang.org/issues/10055
- it "matches POSIX sh behavior for backslashes within double quoted strings" do
- shellsplit('printf "%s\n"').should == ['printf', '%s\n']
- end
+ # https://bugs.ruby-lang.org/issues/10055
+ it "matches POSIX sh behavior for backslashes within double quoted strings" do
+ shellsplit('printf "%s\n"').should == ['printf', '%s\n']
end
end
diff --git a/spec/ruby/library/socket/fixtures/classes.rb b/spec/ruby/library/socket/fixtures/classes.rb
index b73fd0fa4c..4cfa084333 100644
--- a/spec/ruby/library/socket/fixtures/classes.rb
+++ b/spec/ruby/library/socket/fixtures/classes.rb
@@ -71,12 +71,12 @@ module SocketSpecs
end
end
- def self.loop_with_timeout(timeout = 5)
+ def self.loop_with_timeout(timeout = TIME_TOLERANCE)
require 'timeout'
- time = Time.now
+ time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
loop do
- if Time.now - time >= timeout
+ if Process.clock_gettime(Process::CLOCK_MONOTONIC) - time >= timeout
raise TimeoutError, "Did not succeed within #{timeout} seconds"
end
@@ -85,7 +85,7 @@ module SocketSpecs
end
end
- def self.wait_until_success(timeout = 5)
+ def self.wait_until_success(timeout = TIME_TOLERANCE)
loop_with_timeout(timeout) do
begin
return yield
diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb
index f6eae02690..1389408399 100644
--- a/spec/ruby/library/stringio/each_line_spec.rb
+++ b/spec/ruby/library/stringio/each_line_spec.rb
@@ -14,8 +14,6 @@ describe "StringIO#each_line when self is not readable" do
it_behaves_like :stringio_each_not_readable, :each_line
end
-ruby_version_is "2.4" do
- describe "StringIO#each_line when passed chomp" do
- it_behaves_like :stringio_each_chomp, :each_line
- end
+describe "StringIO#each_line when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :each_line
end
diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb
index 4ecaba3dad..a76460049b 100644
--- a/spec/ruby/library/stringio/each_spec.rb
+++ b/spec/ruby/library/stringio/each_spec.rb
@@ -14,8 +14,6 @@ describe "StringIO#each when self is not readable" do
it_behaves_like :stringio_each_not_readable, :each
end
-ruby_version_is "2.4" do
- describe "StringIO#each when passed chomp" do
- it_behaves_like :stringio_each_chomp, :each
- end
+describe "StringIO#each when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :each
end
diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb
index 7fe00d8d19..d682b2784f 100644
--- a/spec/ruby/library/stringio/gets_spec.rb
+++ b/spec/ruby/library/stringio/gets_spec.rb
@@ -237,11 +237,9 @@ describe "StringIO#gets when in write-only mode" do
end
end
-ruby_version_is "2.4" do
- describe "StringIO#gets when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.gets(chomp: true).should == "this>is>an>example"
- end
+describe "StringIO#gets when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is>an>example\n")
+ io.gets(chomp: true).should == "this>is>an>example"
end
end
diff --git a/spec/ruby/library/stringio/lines_spec.rb b/spec/ruby/library/stringio/lines_spec.rb
index dd5773f5a3..d9dd26c2e2 100644
--- a/spec/ruby/library/stringio/lines_spec.rb
+++ b/spec/ruby/library/stringio/lines_spec.rb
@@ -14,8 +14,6 @@ describe "StringIO#lines when self is not readable" do
it_behaves_like :stringio_each_not_readable, :lines
end
-ruby_version_is "2.4" do
- describe "StringIO#lines when passed chomp" do
- it_behaves_like :stringio_each_chomp, :lines
- end
+describe "StringIO#lines when passed chomp" do
+ it_behaves_like :stringio_each_chomp, :lines
end
diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb
index fc1e75b67e..dc396f61a9 100644
--- a/spec/ruby/library/stringio/readline_spec.rb
+++ b/spec/ruby/library/stringio/readline_spec.rb
@@ -121,11 +121,9 @@ describe "StringIO#readline when in write-only mode" do
end
end
-ruby_version_is "2.4" do
- describe "StringIO#readline when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.readline(chomp: true).should == "this>is>an>example"
- end
+describe "StringIO#readline when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is>an>example\n")
+ io.readline(chomp: true).should == "this>is>an>example"
end
end
diff --git a/spec/ruby/library/stringio/readlines_spec.rb b/spec/ruby/library/stringio/readlines_spec.rb
index c15f81b846..840470c09c 100644
--- a/spec/ruby/library/stringio/readlines_spec.rb
+++ b/spec/ruby/library/stringio/readlines_spec.rb
@@ -91,11 +91,9 @@ describe "StringIO#readlines when in write-only mode" do
end
end
-ruby_version_is "2.4" do
- describe "StringIO#readlines when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is\nan>example\r\n")
- io.readlines(chomp: true).should == ["this>is", "an>example"]
- end
+describe "StringIO#readlines when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is\nan>example\r\n")
+ io.readlines(chomp: true).should == ["this>is", "an>example"]
end
end
diff --git a/spec/ruby/library/stringscanner/scan_spec.rb b/spec/ruby/library/stringscanner/scan_spec.rb
index 23de7f07cb..8e26b80591 100644
--- a/spec/ruby/library/stringscanner/scan_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_spec.rb
@@ -19,6 +19,22 @@ describe "StringScanner#scan" do
@s.scan(/^\s/).should == " "
end
+ it "treats ^ as matching from the beginning of the current position when it's not the first character in the regexp" do
+ @s.scan(/\w+/).should == "This"
+ @s.scan(/( is not|^ is a)/).should == " is a"
+ end
+
+ it "treats \\A as matching from the beginning of the current position" do
+ @s.scan(/\w+/).should == "This"
+ @s.scan(/\A\d/).should be_nil
+ @s.scan(/\A\s/).should == " "
+ end
+
+ it "treats \\A as matching from the beginning of the current position when it's not the first character in the regexp" do
+ @s.scan(/\w+/).should == "This"
+ @s.scan(/( is not|\A is a)/).should == " is a"
+ end
+
it "returns nil if there's no match" do
@s.scan(/\d/).should == nil
end
diff --git a/spec/ruby/library/time/to_time_spec.rb b/spec/ruby/library/time/to_time_spec.rb
index 5602915551..7e6c75a003 100644
--- a/spec/ruby/library/time/to_time_spec.rb
+++ b/spec/ruby/library/time/to_time_spec.rb
@@ -1,17 +1,15 @@
require_relative '../../spec_helper'
require 'time'
-ruby_version_is "2.4" do
- describe "Time#to_time" do
- it "returns itself in the same timezone" do
- time = Time.new(2012, 2, 21, 10, 11, 12)
+describe "Time#to_time" do
+ it "returns itself in the same timezone" do
+ time = Time.new(2012, 2, 21, 10, 11, 12)
- with_timezone("America/Regina") do
- time.to_time.should equal time
- end
-
- time2 = Time.utc(2012, 2, 21, 10, 11, 12)
- time2.to_time.should equal time2
+ with_timezone("America/Regina") do
+ time.to_time.should equal time
end
+
+ time2 = Time.utc(2012, 2, 21, 10, 11, 12)
+ time2.to_time.should equal time2
end
end
diff --git a/spec/ruby/library/timeout/timeout_spec.rb b/spec/ruby/library/timeout/timeout_spec.rb
index ac0580ec13..fc957dc36f 100644
--- a/spec/ruby/library/timeout/timeout_spec.rb
+++ b/spec/ruby/library/timeout/timeout_spec.rb
@@ -5,7 +5,7 @@ describe "Timeout.timeout" do
it "raises Timeout::Error when it times out with no specified error type" do
lambda {
Timeout.timeout(1) do
- sleep 3
+ sleep
end
}.should raise_error(Timeout::Error)
end
@@ -13,22 +13,11 @@ describe "Timeout.timeout" do
it "raises specified error type when it times out" do
lambda do
Timeout.timeout(1, StandardError) do
- sleep 3
+ sleep
end
end.should raise_error(StandardError)
end
- it "does not wait too long" do
- before_time = Time.now
- lambda do
- Timeout.timeout(1, StandardError) do
- sleep 3
- end
- end.should raise_error(StandardError)
-
- (Time.now - before_time).should be_close(1.0, 0.8)
- end
-
it "returns back the last value in the block" do
Timeout.timeout(1) do
42
diff --git a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
index f29927e20b..6fb6915f15 100644
--- a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
@@ -21,11 +21,9 @@ describe 'GzipReader#ungetbyte' do
@gz.read.should == '!12345abcde'
end
- ruby_bug "#13616", ""..."2.6" do
- it 'decrements pos' do
- @gz.ungetbyte 0x21
- @gz.pos.should == -1
- end
+ it 'decrements pos' do
+ @gz.ungetbyte 0x21
+ @gz.pos.should == -1
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
index d749d58cca..d19ec61610 100644
--- a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
@@ -21,11 +21,9 @@ describe 'GzipReader#ungetc' do
@gz.read.should == 'x12345abcde'
end
- ruby_bug "#13616", ""..."2.6" do
- it 'decrements pos' do
- @gz.ungetc 'x'
- @gz.pos.should == -1
- end
+ it 'decrements pos' do
+ @gz.ungetc 'x'
+ @gz.pos.should == -1
end
end
@@ -35,11 +33,9 @@ describe 'GzipReader#ungetc' do
@gz.read.should == 'ŷ12345abcde'
end
- ruby_bug "#13616", ""..."2.6" do
- it 'decrements pos' do
- @gz.ungetc 'ŷ'
- @gz.pos.should == -2
- end
+ it 'decrements pos' do
+ @gz.ungetc 'ŷ'
+ @gz.pos.should == -2
end
end
@@ -49,11 +45,9 @@ describe 'GzipReader#ungetc' do
@gz.read.should == 'xŷž12345abcde'
end
- ruby_bug "#13616", ""..."2.6" do
- it 'decrements pos' do
- @gz.ungetc 'xŷž'
- @gz.pos.should == -5
- end
+ it 'decrements pos' do
+ @gz.ungetc 'xŷž'
+ @gz.pos.should == -5
end
end
@@ -63,11 +57,9 @@ describe 'GzipReader#ungetc' do
@gz.read.should == '!12345abcde'
end
- ruby_bug "#13616", ""..."2.6" do
- it 'decrements pos' do
- @gz.ungetc 0x21
- @gz.pos.should == -1
- end
+ it 'decrements pos' do
+ @gz.ungetc 0x21
+ @gz.pos.should == -1
end
end
diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb
index a4dac6707a..57636f3819 100644
--- a/spec/ruby/optional/capi/class_spec.rb
+++ b/spec/ruby/optional/capi/class_spec.rb
@@ -237,12 +237,10 @@ describe "C-API Class function" do
}.should raise_error(TypeError)
end
- ruby_version_is "2.4" do
- it "raises a ArgumentError when given NULL as superclass" do
- lambda {
- @s.rb_define_class("ClassSpecDefineClass4", nil)
- }.should raise_error(ArgumentError)
- end
+ it "raises a ArgumentError when given NULL as superclass" do
+ lambda {
+ @s.rb_define_class("ClassSpecDefineClass4", nil)
+ }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/optional/capi/constants_spec.rb b/spec/ruby/optional/capi/constants_spec.rb
index a99fdac7e5..11a328a91f 100644
--- a/spec/ruby/optional/capi/constants_spec.rb
+++ b/spec/ruby/optional/capi/constants_spec.rb
@@ -11,12 +11,6 @@ describe "C-API constant" do
@s.rb_cArray.should == Array
end
- ruby_version_is ""..."2.4" do
- specify "rb_cBignum references the Bignum class" do
- @s.rb_cBignum.should == Bignum
- end
- end
-
specify "rb_cClass references the Class class" do
@s.rb_cClass.should == Class
end
@@ -43,12 +37,6 @@ describe "C-API constant" do
@s.rb_cFile.should == File
end
- ruby_version_is ""..."2.4" do
- specify "rb_cFixnum references the Fixnum class" do
- @s.rb_cFixnum.should == Fixnum
- end
- end
-
specify "rb_cFloat references the Float class" do
@s.rb_cFloat.should == Float
end
diff --git a/spec/ruby/optional/capi/data_spec.rb b/spec/ruby/optional/capi/data_spec.rb
index b7d1b8fd65..dd99581824 100644
--- a/spec/ruby/optional/capi/data_spec.rb
+++ b/spec/ruby/optional/capi/data_spec.rb
@@ -30,6 +30,10 @@ describe "CApiWrappedStruct" do
@s.change_struct(a, 100)
@s.get_struct(a).should == 100
end
+
+ it "raises a TypeError if the object does not wrap a struct" do
+ lambda { @s.get_struct(Object.new) }.should raise_error(TypeError)
+ end
end
describe "DATA_PTR" do
diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c
index e3fbb872cf..a8f5a29145 100644
--- a/spec/ruby/optional/capi/ext/io_spec.c
+++ b/spec/ruby/optional/capi/ext/io_spec.c
@@ -167,6 +167,16 @@ VALUE io_spec_rb_thread_wait_fd(VALUE self, VALUE io) {
return Qnil;
}
+VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE secs, VALUE usecs) {
+ int fd = io_spec_get_fd(io);
+ struct timeval tv;
+ if (!NIL_P(secs)) {
+ tv.tv_sec = FIX2INT(secs);
+ tv.tv_usec = FIX2INT(usecs);
+ }
+ return INT2FIX(rb_wait_for_single_fd(fd, FIX2INT(events), NIL_P(secs) ? NULL : &tv));
+}
+
VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) {
rb_thread_fd_writable(io_spec_get_fd(io));
return Qnil;
@@ -220,6 +230,7 @@ void Init_io_spec(void) {
rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1);
rb_define_method(cls, "rb_thread_wait_fd", io_spec_rb_thread_wait_fd, 1);
rb_define_method(cls, "rb_thread_fd_writable", io_spec_rb_thread_fd_writable, 1);
+ rb_define_method(cls, "rb_wait_for_single_fd", io_spec_rb_wait_for_single_fd, 4);
rb_define_method(cls, "rb_io_binmode", io_spec_rb_io_binmode, 1);
rb_define_method(cls, "rb_fd_fix_cloexec", io_spec_rb_fd_fix_cloexec, 1);
rb_define_method(cls, "rb_cloexec_open", io_spec_rb_cloexec_open, 3);
diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c
index 5ec45f542c..48e2b1ca95 100644
--- a/spec/ruby/optional/capi/ext/kernel_spec.c
+++ b/spec/ruby/optional/capi/ext/kernel_spec.c
@@ -168,6 +168,7 @@ static VALUE kernel_spec_rb_protect_yield(VALUE self, VALUE obj, VALUE ary) {
int status = 0;
VALUE res = rb_protect(rb_yield, obj, &status);
rb_ary_store(ary, 0, INT2NUM(23));
+ rb_ary_store(ary, 1, res);
if (status) {
rb_jump_tag(status);
}
diff --git a/spec/ruby/optional/capi/ext/object_spec.c b/spec/ruby/optional/capi/ext/object_spec.c
index c70c2ecf3a..cd32050f14 100644
--- a/spec/ruby/optional/capi/ext/object_spec.c
+++ b/spec/ruby/optional/capi/ext/object_spec.c
@@ -327,6 +327,16 @@ static VALUE object_spec_rb_ivar_defined(VALUE self, VALUE obj, VALUE sym_name)
return rb_ivar_defined(obj, SYM2ID(sym_name));
}
+static VALUE object_spec_rb_copy_generic_ivar(VALUE self, VALUE clone, VALUE obj) {
+ rb_copy_generic_ivar(clone, obj);
+ return self;
+}
+
+static VALUE object_spec_rb_free_generic_ivar(VALUE self, VALUE obj) {
+ rb_free_generic_ivar(obj);
+ return self;
+}
+
static VALUE object_spec_rb_equal(VALUE self, VALUE a, VALUE b) {
return rb_equal(a, b);
}
@@ -400,6 +410,8 @@ void Init_object_spec(void) {
rb_define_method(cls, "rb_ivar_get", object_spec_rb_ivar_get, 2);
rb_define_method(cls, "rb_ivar_set", object_spec_rb_ivar_set, 3);
rb_define_method(cls, "rb_ivar_defined", object_spec_rb_ivar_defined, 2);
+ rb_define_method(cls, "rb_copy_generic_ivar", object_spec_rb_copy_generic_ivar, 2);
+ rb_define_method(cls, "rb_free_generic_ivar", object_spec_rb_free_generic_ivar, 1);
}
#ifdef __cplusplus
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c
index dfb1ee51cb..6ad0b46ae4 100644
--- a/spec/ruby/optional/capi/ext/string_spec.c
+++ b/spec/ruby/optional/capi/ext/string_spec.c
@@ -176,6 +176,10 @@ VALUE string_spec_rb_str_encode(VALUE self, VALUE str, VALUE enc, VALUE flags, V
return rb_str_encode(str, enc, FIX2INT(flags), opts);
}
+VALUE string_spec_rb_str_export_to_enc(VALUE self, VALUE str, VALUE enc) {
+ return rb_str_export_to_enc(str, rb_to_encoding(enc));
+}
+
VALUE string_spec_rb_str_new_cstr(VALUE self, VALUE str) {
if(NIL_P(str)) {
return rb_str_new_cstr("");
@@ -435,6 +439,7 @@ void Init_string_spec(void) {
rb_define_method(cls, "rb_str_new_offset", string_spec_rb_str_new_offset, 3);
rb_define_method(cls, "rb_str_new2", string_spec_rb_str_new2, 1);
rb_define_method(cls, "rb_str_encode", string_spec_rb_str_encode, 4);
+ rb_define_method(cls, "rb_str_export_to_enc", string_spec_rb_str_export_to_enc, 2);
rb_define_method(cls, "rb_str_new_cstr", string_spec_rb_str_new_cstr, 1);
rb_define_method(cls, "rb_external_str_new", string_spec_rb_external_str_new, 1);
rb_define_method(cls, "rb_external_str_new_cstr", string_spec_rb_external_str_new_cstr, 1);
diff --git a/spec/ruby/optional/capi/io_spec.rb b/spec/ruby/optional/capi/io_spec.rb
index a832c6a93b..82dc1fc0df 100644
--- a/spec/ruby/optional/capi/io_spec.rb
+++ b/spec/ruby/optional/capi/io_spec.rb
@@ -299,6 +299,26 @@ describe "C-API IO function" do
end
end
+ describe "rb_wait_for_single_fd" do
+ it "waits til an fd is ready for reading" do
+ start = false
+ thr = Thread.new do
+ start = true
+ sleep 0.05
+ @w_io.write "rb_io_wait_readable"
+ end
+
+ Thread.pass until start
+
+ @o.rb_wait_for_single_fd(@r_io, 1, nil, nil).should == 1
+
+ thr.join
+ end
+
+ it "polls whether an fd is ready for reading if timeout is 0" do
+ @o.rb_wait_for_single_fd(@r_io, 1, 0, 0).should == 0
+ end
+ end
end
describe "rb_fd_fix_cloexec" do
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb
index f68a46ed50..ab6c2bceef 100644
--- a/spec/ruby/optional/capi/kernel_spec.rb
+++ b/spec/ruby/optional/capi/kernel_spec.rb
@@ -281,6 +281,15 @@ describe "C-API Kernel function" do
end.should raise_error(NameError)
proof[0].should == 23
end
+
+ it "will return nil if an error was raised" do
+ proof = [] # Hold proof of work performed after the yield.
+ lambda do
+ @s.rb_protect_yield(7, proof) { |x| raise NameError}
+ end.should raise_error(NameError)
+ proof[0].should == 23
+ proof[1].should == nil
+ end
end
describe "rb_rescue" do
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index 541b58b48c..34aae636c7 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -853,5 +853,28 @@ describe "CApiObject" do
@o.rb_ivar_defined(@test, :bar).should == false
end
end
+
+ # The `generic_iv_tbl` table and `*_generic_ivar` functions are for mutable
+ # objects which do not store ivars directly in MRI such as RString, because
+ # there is no member iv_index_tbl (ivar table) such as in RObject and RClass.
+
+ describe "rb_copy_generic_ivar for objects which do not store ivars directly" do
+ it "copies the instance variables from one object to another" do
+ original = "abc"
+ original.instance_variable_set(:@foo, :bar)
+ clone = "def"
+ @o.rb_copy_generic_ivar(clone, original)
+ clone.instance_variable_get(:@foo).should == :bar
+ end
+ end
+
+ describe "rb_free_generic_ivar for objects which do not store ivars directly" do
+ it "removes the instance variables from an object" do
+ o = "abc"
+ o.instance_variable_set(:@baz, :flibble)
+ @o.rb_free_generic_ivar(o)
+ o.instance_variables.should == []
+ end
+ end
end
end
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index ac23198662..79cdb524ad 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -167,6 +167,10 @@ describe "C-API String function" do
@s.rb_str_new("hello", 3).should == "hel"
end
+ it "returns a non-tainted string" do
+ @s.rb_str_new("hello", 5).tainted?.should == false
+ end
+
it "returns an empty string if len is 0" do
@s.rb_str_new("hello", 0).should == ""
end
@@ -877,6 +881,27 @@ describe "C-API String function" do
end
end
+ describe "rb_str_export_to_enc" do
+ it "returns a copy of an ascii string converted to the new encoding" do
+ source = "A simple string".encode(Encoding::US_ASCII)
+ result = @s.rb_str_export_to_enc(source, Encoding::UTF_8)
+ result.should == source.encode(Encoding::UTF_8)
+ result.encoding.should == Encoding::UTF_8
+ end
+
+ it "returns the source string if it can not be converted" do
+ source = ["00ff"].pack("H*");
+ result = @s.rb_str_export_to_enc(source, Encoding::UTF_8)
+ result.should equal(source)
+ end
+
+ it "does not alter the source string if it can not be converted" do
+ source = ["00ff"].pack("H*");
+ result = @s.rb_str_export_to_enc(source, Encoding::UTF_8)
+ source.bytes.should == [0, 255]
+ end
+end
+
describe "rb_sprintf" do
it "replaces the parts like sprintf" do
@s.rb_sprintf1("Awesome %s is replaced", "string").should == "Awesome string is replaced"
diff --git a/spec/ruby/optional/capi/struct_spec.rb b/spec/ruby/optional/capi/struct_spec.rb
index b3acd02b61..3b0972926c 100644
--- a/spec/ruby/optional/capi/struct_spec.rb
+++ b/spec/ruby/optional/capi/struct_spec.rb
@@ -203,11 +203,9 @@ describe "C-API Struct function" do
end
end
- ruby_version_is "2.4" do
- describe "rb_struct_size" do
- it "returns the number of struct members" do
- @s.rb_struct_size(@struct).should == 3
- end
+ describe "rb_struct_size" do
+ it "returns the number of struct members" do
+ @s.rb_struct_size(@struct).should == 3
end
end
end
diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb
index 52070198fd..a46290203a 100644
--- a/spec/ruby/optional/capi/thread_spec.rb
+++ b/spec/ruby/optional/capi/thread_spec.rb
@@ -24,7 +24,7 @@ describe "C-API Thread function" do
it "sleeps the current thread for the give amount of time" do
start = Time.now
@t.rb_thread_wait_for(0, 100_000)
- (Time.now - start).should be_close(0.1, 0.2)
+ (Time.now - start).should be_close(0.1, TIME_TOLERANCE)
end
end
diff --git a/spec/ruby/optional/capi/time_spec.rb b/spec/ruby/optional/capi/time_spec.rb
index 1191ceabd2..427507a3bb 100644
--- a/spec/ruby/optional/capi/time_spec.rb
+++ b/spec/ruby/optional/capi/time_spec.rb
@@ -294,7 +294,7 @@ describe "CApiTimeSpecs" do
now = Time.now
time = @s.rb_time_from_timespec(now.utc_offset)
time.should be_an_instance_of(Time)
- (time - now).should be_close(0, 10)
+ (time - now).should be_close(0, TIME_TOLERANCE)
end
end
end
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb
index b3e43d29ce..33dc30df85 100644
--- a/spec/ruby/optional/capi/util_spec.rb
+++ b/spec/ruby/optional/capi/util_spec.rb
@@ -119,6 +119,11 @@ describe "C-API Util function" do
ScratchPad.recorded.should == [1, nil]
end
+ it "assigns required and optional arguments with no hash argument given" do
+ @o.rb_scan_args([1, 7, 4], "21:", 3, @acc).should == 3
+ ScratchPad.recorded.should == [1, 7, 4]
+ end
+
it "assigns required, optional, splat, post-splat, Hash and block arguments" do
h = {a: 1, b: 2}
@o.rb_scan_args([1, 2, 3, 4, 5, h], "11*1:&", 6, @acc, &@prc).should == 5
diff --git a/spec/ruby/security/cve_2011_4815_spec.rb b/spec/ruby/security/cve_2011_4815_spec.rb
index 02ef10d562..554e014a1f 100644
--- a/spec/ruby/security/cve_2011_4815_spec.rb
+++ b/spec/ruby/security/cve_2011_4815_spec.rb
@@ -35,9 +35,7 @@ describe "String#hash" do
end
describe "Symbol#hash" do
- ruby_bug "#13376", "2.3.0"..."2.3.4" do
- it_behaves_like :resists_cve_2011_4815, ':a'
- end
+ it_behaves_like :resists_cve_2011_4815, ':a'
end
describe "Array#hash" do
diff --git a/spec/ruby/security/cve_2018_8780_spec.rb b/spec/ruby/security/cve_2018_8780_spec.rb
index febb1de51d..d9c02fbbd1 100644
--- a/spec/ruby/security/cve_2018_8780_spec.rb
+++ b/spec/ruby/security/cve_2018_8780_spec.rb
@@ -23,12 +23,10 @@ describe "CVE-2018-8780 is resisted by" do
}.should raise_error(ArgumentError, /(path name|string) contains null byte/)
end
- ruby_version_is "2.4" do
- it "Dir.empty? by raising an exception when there is a NUL byte" do
- lambda {
- Dir.empty?(@root+"\0")
- }.should raise_error(ArgumentError, /(path name|string) contains null byte/)
- end
+ it "Dir.empty? by raising an exception when there is a NUL byte" do
+ lambda {
+ Dir.empty?(@root+"\0")
+ }.should raise_error(ArgumentError, /(path name|string) contains null byte/)
end
ruby_version_is "2.5" do
diff --git a/spec/ruby/shared/rational/Rational.rb b/spec/ruby/shared/rational/Rational.rb
index 30425775d6..3952f663c6 100644
--- a/spec/ruby/shared/rational/Rational.rb
+++ b/spec/ruby/shared/rational/Rational.rb
@@ -132,12 +132,10 @@ describe :kernel_Rational, shared: true do
end
end
- ruby_bug "#15525", "2.6"..."2.6.1" do
- describe "and nil arguments" do
- it "swallows an error" do
- Rational(nil, exception: false).should == nil
- Rational(nil, nil, exception: false).should == nil
- end
+ describe "and nil arguments" do
+ it "swallows an error" do
+ Rational(nil, exception: false).should == nil
+ Rational(nil, nil, exception: false).should == nil
end
end
end
diff --git a/spec/ruby/shared/rational/round.rb b/spec/ruby/shared/rational/round.rb
index 36ed476350..e99f884cea 100644
--- a/spec/ruby/shared/rational/round.rb
+++ b/spec/ruby/shared/rational/round.rb
@@ -72,28 +72,35 @@ describe :rational_round, shared: true do
end
end
- ruby_version_is "2.4" do
- describe "with half option" do
- it "returns an Integer when precision is not passed" do
- Rational(10, 4).round(half: :up).should == 3
- Rational(10, 4).round(half: :down).should == 2
- Rational(10, 4).round(half: :even).should == 2
- Rational(-10, 4).round(half: :up).should == -3
- Rational(-10, 4).round(half: :down).should == -2
- Rational(-10, 4).round(half: :even).should == -2
- end
+ describe "with half option" do
+ it "returns an Integer when precision is not passed" do
+ Rational(10, 4).round(half: nil).should == 3
+ Rational(10, 4).round(half: :up).should == 3
+ Rational(10, 4).round(half: :down).should == 2
+ Rational(10, 4).round(half: :even).should == 2
+ Rational(-10, 4).round(half: nil).should == -3
+ Rational(-10, 4).round(half: :up).should == -3
+ Rational(-10, 4).round(half: :down).should == -2
+ Rational(-10, 4).round(half: :even).should == -2
+ end
- it "returns a Rational when the precision is greater than 0" do
- Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
- Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
- Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
- Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
- Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
- Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
- Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
- Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
- Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
- end
+ it "returns a Rational when the precision is greater than 0" do
+ Rational(25, 100).round(1, half: nil).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
+ Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
+ Rational(35, 100).round(1, half: nil).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
+ Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
+ Rational(-25, 100).round(1, half: nil).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
+ Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
+ end
+
+ it "raise for a non-existent round mode" do
+ lambda { Rational(10, 4).round(half: :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode: nonsense")
end
end
end