summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2022-04-25 14:53:54 +0200
committerBenoit Daloze <eregontp@gmail.com>2022-04-25 14:53:54 +0200
commit45cf4f218728a15eb36d14a6c9912086525f5e3f (patch)
tree2aa93fadcb904c226f722dde47827098b87a9846
parent6ae81d49b52563a6720d666a6118ffa6e484f398 (diff)
Update to ruby/spec@3affe1e
-rw-r--r--spec/ruby/.rubocop.yml45
-rw-r--r--spec/ruby/CONTRIBUTING.md2
-rw-r--r--spec/ruby/README.md5
-rw-r--r--spec/ruby/command_line/dash_upper_w_spec.rb33
-rw-r--r--spec/ruby/command_line/dash_w_spec.rb6
-rw-r--r--spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb2
-rw-r--r--spec/ruby/command_line/rubyopt_spec.rb30
-rw-r--r--spec/ruby/core/array/clear_spec.rb20
-rw-r--r--spec/ruby/core/array/compact_spec.rb30
-rw-r--r--spec/ruby/core/array/concat_spec.rb58
-rw-r--r--spec/ruby/core/array/deconstruct_spec.rb10
-rw-r--r--spec/ruby/core/array/delete_at_spec.rb22
-rw-r--r--spec/ruby/core/array/delete_if_spec.rb16
-rw-r--r--spec/ruby/core/array/delete_spec.rb22
-rw-r--r--spec/ruby/core/array/element_set_spec.rb76
-rw-r--r--spec/ruby/core/array/fill_spec.rb8
-rw-r--r--spec/ruby/core/array/flatten_spec.rb10
-rw-r--r--spec/ruby/core/array/intersection_spec.rb16
-rw-r--r--spec/ruby/core/array/multiply_spec.rb40
-rw-r--r--spec/ruby/core/array/pack/p_spec.rb24
-rw-r--r--spec/ruby/core/array/pack/shared/basic.rb12
-rw-r--r--spec/ruby/core/array/pack/shared/taint.rb33
-rw-r--r--spec/ruby/core/array/plus_spec.rb16
-rw-r--r--spec/ruby/core/array/pop_spec.rb52
-rw-r--r--spec/ruby/core/array/shared/clone.rb24
-rw-r--r--spec/ruby/core/array/shared/collect.rb31
-rw-r--r--spec/ruby/core/array/shared/inspect.rb26
-rw-r--r--spec/ruby/core/array/shared/join.rb86
-rw-r--r--spec/ruby/core/array/shared/slice.rb76
-rw-r--r--spec/ruby/core/array/shift_spec.rb16
-rw-r--r--spec/ruby/core/array/slice_spec.rb18
-rw-r--r--spec/ruby/core/array/uniq_spec.rb76
-rw-r--r--spec/ruby/core/array/values_at_spec.rb8
-rw-r--r--spec/ruby/core/builtin_constants/builtin_constants_spec.rb12
-rw-r--r--spec/ruby/core/comparable/clamp_spec.rb78
-rw-r--r--spec/ruby/core/complex/comparison_spec.rb36
-rw-r--r--spec/ruby/core/dir/children_spec.rb8
-rw-r--r--spec/ruby/core/dir/each_child_spec.rb7
-rw-r--r--spec/ruby/core/dir/entries_spec.rb7
-rw-r--r--spec/ruby/core/dir/foreach_spec.rb7
-rw-r--r--spec/ruby/core/dir/shared/glob.rb15
-rw-r--r--spec/ruby/core/encoding/list_spec.rb6
-rw-r--r--spec/ruby/core/enumerable/filter_map_spec.rb34
-rw-r--r--spec/ruby/core/enumerable/group_by_spec.rb10
-rw-r--r--spec/ruby/core/enumerable/shared/entries.rb10
-rw-r--r--spec/ruby/core/enumerable/shared/inject.rb3
-rw-r--r--spec/ruby/core/enumerable/tally_spec.rb48
-rw-r--r--spec/ruby/core/enumerable/uniq_spec.rb76
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/eager_spec.rb38
-rw-r--r--spec/ruby/core/enumerator/lazy/filter_map_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/with_index_spec.rb50
-rw-r--r--spec/ruby/core/enumerator/new_spec.rb12
-rw-r--r--spec/ruby/core/enumerator/produce_spec.rb48
-rw-r--r--spec/ruby/core/enumerator/yielder/to_proc_spec.rb20
-rw-r--r--spec/ruby/core/env/merge_spec.rb6
-rw-r--r--spec/ruby/core/env/shared/update.rb30
-rw-r--r--spec/ruby/core/exception/frozen_error_spec.rb28
-rw-r--r--spec/ruby/core/false/to_s_spec.rb12
-rw-r--r--spec/ruby/core/fiber/raise_spec.rb148
-rw-r--r--spec/ruby/core/file/absolute_path_spec.rb74
-rw-r--r--spec/ruby/core/file/extname_spec.rb4
-rw-r--r--spec/ruby/core/hash/constructor_spec.rb27
-rw-r--r--spec/ruby/core/hash/deconstruct_keys_spec.rb32
-rw-r--r--spec/ruby/core/hash/reject_spec.rb7
-rw-r--r--spec/ruby/core/hash/ruby2_keywords_hash_spec.rb110
-rw-r--r--spec/ruby/core/hash/shared/eql.rb84
-rw-r--r--spec/ruby/core/hash/shared/to_s.rb12
-rw-r--r--spec/ruby/core/hash/to_a_spec.rb12
-rw-r--r--spec/ruby/core/integer/chr_spec.rb20
-rw-r--r--spec/ruby/core/integer/element_reference_spec.rb122
-rw-r--r--spec/ruby/core/integer/fdiv_spec.rb46
-rw-r--r--spec/ruby/core/io/gets_spec.rb32
-rw-r--r--spec/ruby/core/io/set_encoding_by_bom_spec.rb86
-rw-r--r--spec/ruby/core/io/ungetbyte_spec.rb18
-rw-r--r--spec/ruby/core/kernel/caller_locations_spec.rb10
-rw-r--r--spec/ruby/core/kernel/caller_spec.rb10
-rw-r--r--spec/ruby/core/kernel/clone_spec.rb7
-rw-r--r--spec/ruby/core/kernel/inspect_spec.rb10
-rw-r--r--spec/ruby/core/kernel/method_spec.rb24
-rw-r--r--spec/ruby/core/kernel/proc_spec.rb10
-rw-r--r--spec/ruby/core/kernel/shared/dup_clone.rb24
-rw-r--r--spec/ruby/core/kernel/shared/require.rb6
-rw-r--r--spec/ruby/core/kernel/taint_spec.rb45
-rw-r--r--spec/ruby/core/kernel/tainted_spec.rb12
-rw-r--r--spec/ruby/core/kernel/to_s_spec.rb10
-rw-r--r--spec/ruby/core/kernel/trust_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untaint_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untrust_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untrusted_spec.rb28
-rw-r--r--spec/ruby/core/main/ruby2_keywords_spec.rb10
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb26
-rw-r--r--spec/ruby/core/marshal/shared/load.rb83
-rw-r--r--spec/ruby/core/matchdata/allocate_spec.rb8
-rw-r--r--spec/ruby/core/matchdata/element_reference_spec.rb6
-rw-r--r--spec/ruby/core/matchdata/post_match_spec.rb18
-rw-r--r--spec/ruby/core/matchdata/pre_match_spec.rb18
-rw-r--r--spec/ruby/core/method/shared/to_s.rb32
-rw-r--r--spec/ruby/core/module/append_features_spec.rb14
-rw-r--r--spec/ruby/core/module/autoload_spec.rb20
-rw-r--r--spec/ruby/core/module/const_source_location_spec.rb333
-rw-r--r--spec/ruby/core/module/deprecate_constant_spec.rb20
-rw-r--r--spec/ruby/core/module/extend_object_spec.rb14
-rw-r--r--spec/ruby/core/module/name_spec.rb26
-rw-r--r--spec/ruby/core/module/prepend_features_spec.rb14
-rw-r--r--spec/ruby/core/module/refine_spec.rb126
-rw-r--r--spec/ruby/core/module/ruby2_keywords_spec.rb360
-rw-r--r--spec/ruby/core/nil/to_s_spec.rb12
-rw-r--r--spec/ruby/core/objectspace/weakmap/element_set_spec.rb53
-rw-r--r--spec/ruby/core/objectspace/weakmap/shared/include.rb16
-rw-r--r--spec/ruby/core/proc/block_pass_spec.rb22
-rw-r--r--spec/ruby/core/proc/new_spec.rb39
-rw-r--r--spec/ruby/core/proc/ruby2_keywords_spec.rb114
-rw-r--r--spec/ruby/core/proc/shared/compose.rb51
-rw-r--r--spec/ruby/core/proc/shared/to_s.rb10
-rw-r--r--spec/ruby/core/process/wait2_spec.rb9
-rw-r--r--spec/ruby/core/range/bsearch_spec.rb196
-rw-r--r--spec/ruby/core/range/case_compare_spec.rb6
-rw-r--r--spec/ruby/core/range/count_spec.rb16
-rw-r--r--spec/ruby/core/range/each_spec.rb6
-rw-r--r--spec/ruby/core/range/equal_value_spec.rb6
-rw-r--r--spec/ruby/core/range/first_spec.rb6
-rw-r--r--spec/ruby/core/range/frozen_spec.rb2
-rw-r--r--spec/ruby/core/range/inspect_spec.rb28
-rw-r--r--spec/ruby/core/range/max_spec.rb12
-rw-r--r--spec/ruby/core/range/min_spec.rb6
-rw-r--r--spec/ruby/core/range/minmax_spec.rb124
-rw-r--r--spec/ruby/core/range/new_spec.rb22
-rw-r--r--spec/ruby/core/range/shared/cover.rb56
-rw-r--r--spec/ruby/core/range/shared/cover_and_include.rb8
-rw-r--r--spec/ruby/core/range/size_spec.rb12
-rw-r--r--spec/ruby/core/range/step_spec.rb16
-rw-r--r--spec/ruby/core/range/to_a_spec.rb6
-rw-r--r--spec/ruby/core/range/to_s_spec.rb22
-rw-r--r--spec/ruby/core/string/b_spec.rb9
-rw-r--r--spec/ruby/core/string/capitalize_spec.rb7
-rw-r--r--spec/ruby/core/string/center_spec.rb18
-rw-r--r--spec/ruby/core/string/chomp_spec.rb62
-rw-r--r--spec/ruby/core/string/chop_spec.rb12
-rw-r--r--spec/ruby/core/string/crypt_spec.rb30
-rw-r--r--spec/ruby/core/string/delete_prefix_spec.rb7
-rw-r--r--spec/ruby/core/string/delete_spec.rb9
-rw-r--r--spec/ruby/core/string/delete_suffix_spec.rb7
-rw-r--r--spec/ruby/core/string/downcase_spec.rb8
-rw-r--r--spec/ruby/core/string/dump_spec.rb12
-rw-r--r--spec/ruby/core/string/element_set_spec.rb24
-rw-r--r--spec/ruby/core/string/gsub_spec.rb138
-rw-r--r--spec/ruby/core/string/insert_spec.rb12
-rw-r--r--spec/ruby/core/string/inspect_spec.rb12
-rw-r--r--spec/ruby/core/string/ljust_spec.rb18
-rw-r--r--spec/ruby/core/string/lstrip_spec.rb8
-rw-r--r--spec/ruby/core/string/modulo_spec.rb50
-rw-r--r--spec/ruby/core/string/plus_spec.rb13
-rw-r--r--spec/ruby/core/string/prepend_spec.rb10
-rw-r--r--spec/ruby/core/string/reverse_spec.rb7
-rw-r--r--spec/ruby/core/string/rjust_spec.rb18
-rw-r--r--spec/ruby/core/string/rstrip_spec.rb8
-rw-r--r--spec/ruby/core/string/scan_spec.rb40
-rw-r--r--spec/ruby/core/string/shared/chars.rb14
-rw-r--r--spec/ruby/core/string/shared/concat.rb12
-rw-r--r--spec/ruby/core/string/shared/each_line.rb8
-rw-r--r--spec/ruby/core/string/shared/replace.rb30
-rw-r--r--spec/ruby/core/string/shared/slice.rb128
-rw-r--r--spec/ruby/core/string/shared/succ.rb8
-rw-r--r--spec/ruby/core/string/shared/to_s.rb7
-rw-r--r--spec/ruby/core/string/slice_spec.rb85
-rw-r--r--spec/ruby/core/string/split_spec.rb71
-rw-r--r--spec/ruby/core/string/squeeze_spec.rb10
-rw-r--r--spec/ruby/core/string/strip_spec.rb8
-rw-r--r--spec/ruby/core/string/sub_spec.rb104
-rw-r--r--spec/ruby/core/string/swapcase_spec.rb7
-rw-r--r--spec/ruby/core/string/tr_s_spec.rb13
-rw-r--r--spec/ruby/core/string/tr_spec.rb13
-rw-r--r--spec/ruby/core/string/undump_spec.rb10
-rw-r--r--spec/ruby/core/string/unpack/p_spec.rb12
-rw-r--r--spec/ruby/core/string/unpack/shared/taint.rb81
-rw-r--r--spec/ruby/core/string/upcase_spec.rb8
-rw-r--r--spec/ruby/core/struct/deconstruct_keys_spec.rb146
-rw-r--r--spec/ruby/core/struct/deconstruct_spec.rb12
-rw-r--r--spec/ruby/core/symbol/end_with_spec.rb6
-rw-r--r--spec/ruby/core/symbol/shared/slice.rb20
-rw-r--r--spec/ruby/core/symbol/start_with_spec.rb6
-rw-r--r--spec/ruby/core/thread/backtrace_locations_spec.rb10
-rw-r--r--spec/ruby/core/thread/report_on_exception_spec.rb30
-rw-r--r--spec/ruby/core/thread/shared/to_s.rb4
-rw-r--r--spec/ruby/core/time/ceil_spec.rb64
-rw-r--r--spec/ruby/core/time/floor_spec.rb52
-rw-r--r--spec/ruby/core/time/inspect_spec.rb44
-rw-r--r--spec/ruby/core/true/to_s_spec.rb12
-rw-r--r--spec/ruby/core/unboundmethod/bind_call_spec.rb74
-rw-r--r--spec/ruby/core/warning/element_reference_spec.rb28
-rw-r--r--spec/ruby/core/warning/element_set_spec.rb48
-rw-r--r--spec/ruby/language/alias_spec.rb13
-rw-r--r--spec/ruby/language/block_spec.rb52
-rw-r--r--spec/ruby/language/comment_spec.rb16
-rw-r--r--spec/ruby/language/def_spec.rb33
-rw-r--r--spec/ruby/language/defined_spec.rb14
-rw-r--r--spec/ruby/language/delegation_spec.rb61
-rw-r--r--spec/ruby/language/fixtures/defined.rb3
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb2
-rw-r--r--spec/ruby/language/hash_spec.rb15
-rw-r--r--spec/ruby/language/heredoc_spec.rb18
-rw-r--r--spec/ruby/language/keyword_arguments_spec.rb57
-rw-r--r--spec/ruby/language/lambda_spec.rb64
-rw-r--r--spec/ruby/language/method_spec.rb274
-rw-r--r--spec/ruby/language/numbered_parameters_spec.rb184
-rw-r--r--spec/ruby/language/pattern_matching_spec.rb2246
-rw-r--r--spec/ruby/language/predefined_spec.rb54
-rw-r--r--spec/ruby/language/proc_spec.rb8
-rw-r--r--spec/ruby/language/range_spec.rb8
-rw-r--r--spec/ruby/language/rescue_spec.rb10
-rw-r--r--spec/ruby/language/return_spec.rb46
-rw-r--r--spec/ruby/language/safe_spec.rb94
-rw-r--r--spec/ruby/language/send_spec.rb18
-rw-r--r--spec/ruby/language/string_spec.rb22
-rw-r--r--spec/ruby/language/yield_spec.rb2
-rw-r--r--spec/ruby/library/cmath/math/acos_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/acosh_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/asin_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/asinh_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/atan2_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/atan_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/atanh_spec.rb19
-rw-r--r--spec/ruby/library/cmath/math/cos_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/cosh_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/exp_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/log10_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/log_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/sin_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/sinh_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/sqrt_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/tan_spec.rb17
-rw-r--r--spec/ruby/library/cmath/math/tanh_spec.rb17
-rw-r--r--spec/ruby/library/date/shared/valid_jd.rb20
-rw-r--r--spec/ruby/library/delegate/delegator/taint_spec.rb17
-rw-r--r--spec/ruby/library/delegate/delegator/trust_spec.rb16
-rw-r--r--spec/ruby/library/delegate/delegator/untaint_spec.rb18
-rw-r--r--spec/ruby/library/delegate/delegator/untrust_spec.rb17
-rw-r--r--spec/ruby/library/openstruct/method_missing_spec.rb8
-rw-r--r--spec/ruby/library/pathname/glob_spec.rb16
-rw-r--r--spec/ruby/library/pathname/new_spec.rb7
-rw-r--r--spec/ruby/library/pathname/pathname_spec.rb19
-rw-r--r--spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb20
-rw-r--r--spec/ruby/library/rbconfig/unicode_version_spec.rb20
-rw-r--r--spec/ruby/library/readline/history/delete_at_spec.rb9
-rw-r--r--spec/ruby/library/readline/history/each_spec.rb8
-rw-r--r--spec/ruby/library/readline/history/element_reference_spec.rb7
-rw-r--r--spec/ruby/library/readline/history/pop_spec.rb9
-rw-r--r--spec/ruby/library/readline/history/shift_spec.rb9
-rw-r--r--spec/ruby/library/readline/readline_spec.rb7
-rw-r--r--spec/ruby/library/scanf/io/block_scanf_spec.rb9
-rw-r--r--spec/ruby/library/scanf/io/scanf_spec.rb37
-rw-r--r--spec/ruby/library/scanf/string/block_scanf_spec.rb9
-rw-r--r--spec/ruby/library/scanf/string/scanf_spec.rb55
-rw-r--r--spec/ruby/library/stringio/append_spec.rb7
-rw-r--r--spec/ruby/library/stringio/reopen_spec.rb17
-rw-r--r--spec/ruby/library/stringio/shared/write.rb7
-rw-r--r--spec/ruby/library/stringscanner/check_spec.rb14
-rw-r--r--spec/ruby/library/stringscanner/scan_spec.rb44
-rw-r--r--spec/ruby/library/stringscanner/shared/extract_range.rb13
-rw-r--r--spec/ruby/library/stringscanner/shared/extract_range_matched.rb11
-rw-r--r--spec/ruby/library/stringscanner/shared/peek.rb10
-rw-r--r--spec/ruby/library/yaml/to_yaml_spec.rb12
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb10
-rw-r--r--spec/ruby/optional/capi/object_spec.rb77
-rw-r--r--spec/ruby/optional/capi/proc_spec.rb28
-rw-r--r--spec/ruby/optional/capi/shared/rbasic.rb34
-rw-r--r--spec/ruby/optional/capi/string_spec.rb53
-rw-r--r--spec/ruby/optional/capi/util_spec.rb19
-rw-r--r--spec/ruby/security/cve_2018_16396_spec.rb14
-rw-r--r--spec/ruby/security/cve_2019_8321_spec.rb30
-rw-r--r--spec/ruby/security/cve_2019_8322_spec.rb32
-rw-r--r--spec/ruby/security/cve_2019_8323_spec.rb54
-rw-r--r--spec/ruby/security/cve_2019_8325_spec.rb52
-rw-r--r--spec/ruby/security/cve_2020_10663_spec.rb25
-rw-r--r--spec/ruby/shared/rational/to_f.rb6
-rw-r--r--spec/ruby/shared/string/times.rb12
277 files changed, 3575 insertions, 7355 deletions
diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml
index eab4c3c4a6..e807b59321 100644
--- a/spec/ruby/.rubocop.yml
+++ b/spec/ruby/.rubocop.yml
@@ -1,11 +1,12 @@
inherit_from: .rubocop_todo.yml
AllCops:
- TargetRubyVersion: 2.6
+ TargetRubyVersion: 2.7
DisplayCopNames: true
Exclude:
- command_line/fixtures/bad_syntax.rb
DisabledByDefault: true
+ NewCops: disable
Layout/TrailingWhitespace:
Enabled: true
@@ -56,12 +57,52 @@ Lint/UnusedMethodArgument:
Lint/UselessAssignment:
Enabled: false
-Lint/UselessComparison:
+Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false
+Lint/EmptyConditionalBody:
+ Enabled: false # buggy
+
Lint/Void:
Enabled: false
+Lint/ConstantDefinitionInBlock:
+ Enabled: false
+
+Lint/RaiseException:
+ Enabled: false
+
+Lint/FloatComparison:
+ Enabled: false
+
+Lint/DeprecatedClassMethods:
+ Enabled: false
+
+Lint/UnreachableLoop:
+ Enabled: false
+
+Lint/MissingSuper:
+ Enabled: false
+
+Lint/UselessMethodDefinition:
+ Enabled: false
+
+Lint/UselessTimes:
+ Enabled: false
+
+Lint/MixedRegexpCaptureTypes:
+ Enabled: false
+
+Lint/DuplicateElsifCondition:
+ Enabled: false
+
+Lint/OutOfRangeRegexpRef:
+ Enabled: false
+
+Lint/ElseLayout:
+ Exclude:
+ - 'language/if_spec.rb'
+
Lint/EmptyExpression:
Exclude:
- 'language/**/*.rb'
diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md
index de6fccbd7e..20258e5c36 100644
--- a/spec/ruby/CONTRIBUTING.md
+++ b/spec/ruby/CONTRIBUTING.md
@@ -180,7 +180,7 @@ First, file a bug at https://bugs.ruby-lang.org/.
It is better to use a `ruby_version_is` guard if there was a release with the fix.
```ruby
-ruby_bug '#13669', ''...'2.7' do
+ruby_bug '#13669', ''...'3.2' do
it "works like this" do
# Specify the expected behavior here, not the bug
end
diff --git a/spec/ruby/README.md b/spec/ruby/README.md
index 6f6b75f6a7..55b248a6c3 100644
--- a/spec/ruby/README.md
+++ b/spec/ruby/README.md
@@ -31,8 +31,8 @@ ruby/spec is known to be tested in these implementations for every commit:
* [Opal](https://github.com/opal/opal/tree/master/spec)
* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
-ruby/spec describes the behavior of Ruby 2.6 and more recent Ruby versions.
-More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (2.6.x, 2.7.x, 3.0.x, etc), and those are tested in CI.
+ruby/spec describes the behavior of Ruby 2.7 and more recent Ruby versions.
+More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (2.7.x, 3.0.x, 3.1.x, etc), and those are tested in CI.
### Synchronization with Ruby Implementations
@@ -61,6 +61,7 @@ For older specs try these commits:
* Ruby 2.3.8 - [Suite](https://github.com/ruby/spec/commit/dc733114d8ae66a3368ba3a98422c50147a76ba5) using [MSpec](https://github.com/ruby/mspec/commit/4599bc195fb109f2a482a01c32a7d659518369ea)
* Ruby 2.4.10 - [Suite](https://github.com/ruby/spec/commit/bce4f2b81d6c31db67cf4d023a0625ceadde59bd) using [MSpec](https://github.com/ruby/mspec/commit/e7eb8aa4c26495b7b461e687d950b96eb08b3ff2)
* Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041)
+* Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661)
### Running the specs
diff --git a/spec/ruby/command_line/dash_upper_w_spec.rb b/spec/ruby/command_line/dash_upper_w_spec.rb
index cbb040a8dd..4019510d42 100644
--- a/spec/ruby/command_line/dash_upper_w_spec.rb
+++ b/spec/ruby/command_line/dash_upper_w_spec.rb
@@ -19,29 +19,26 @@ describe "The -W command line option with 2" do
it_behaves_like :command_line_verbose, "-W2"
end
-# Regarding the defaults, see core/warning/element_reference_spec.rb
-ruby_version_is "2.7" do
- describe "The -W command line option with :deprecated" do
- it "enables deprecation warnings" do
- ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n"
- end
+describe "The -W command line option with :deprecated" do
+ it "enables deprecation warnings" do
+ ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n"
end
+end
- describe "The -W command line option with :no-deprecated" do
- it "suppresses deprecation warnings" do
- ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n"
- end
+describe "The -W command line option with :no-deprecated" do
+ it "suppresses deprecation warnings" do
+ ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n"
end
+end
- describe "The -W command line option with :experimental" do
- it "enables experimental warnings" do
- ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n"
- end
+describe "The -W command line option with :experimental" do
+ it "enables experimental warnings" do
+ ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n"
end
+end
- describe "The -W command line option with :no-experimental" do
- it "suppresses experimental warnings" do
- ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n"
- end
+describe "The -W command line option with :no-experimental" do
+ it "suppresses experimental warnings" do
+ ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n"
end
end
diff --git a/spec/ruby/command_line/dash_w_spec.rb b/spec/ruby/command_line/dash_w_spec.rb
index c262df12cc..f310dca3ed 100644
--- a/spec/ruby/command_line/dash_w_spec.rb
+++ b/spec/ruby/command_line/dash_w_spec.rb
@@ -4,9 +4,7 @@ require_relative 'shared/verbose'
describe "The -w command line option" do
it_behaves_like :command_line_verbose, "-w"
- ruby_version_is "2.7" do
- it "enables both deprecated and experimental warnings" do
- ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n"
- end
+ it "enables both deprecated and experimental warnings" do
+ ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n"
end
end
diff --git a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
index 074092c9d9..f5547a5bae 100644
--- a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
+++ b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
@@ -1 +1 @@
-p "abc".object_id == "abc".object_id
+p "abc".equal?("abc")
diff --git a/spec/ruby/command_line/rubyopt_spec.rb b/spec/ruby/command_line/rubyopt_spec.rb
index a2b817bad8..bbea4d557d 100644
--- a/spec/ruby/command_line/rubyopt_spec.rb
+++ b/spec/ruby/command_line/rubyopt_spec.rb
@@ -59,24 +59,22 @@ describe "Processing RUBYOPT" do
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
end
- ruby_version_is "2.7" do
- it "suppresses deprecation warnings for '-W:no-deprecated'" do
- ENV["RUBYOPT"] = '-W:no-deprecated'
- result = ruby_exe('$; = ""', args: '2>&1')
- result.should == ""
- end
+ it "suppresses deprecation warnings for '-W:no-deprecated'" do
+ ENV["RUBYOPT"] = '-W:no-deprecated'
+ result = ruby_exe('$; = ""', args: '2>&1')
+ result.should == ""
+ end
- it "suppresses experimental warnings for '-W:no-experimental'" do
- ENV["RUBYOPT"] = '-W:no-experimental'
- result = ruby_exe('case 0; in a; end', args: '2>&1')
- result.should == ""
- end
+ it "suppresses experimental warnings for '-W:no-experimental'" do
+ ENV["RUBYOPT"] = '-W:no-experimental'
+ result = ruby_exe('case 0; in a; end', args: '2>&1')
+ result.should == ""
+ end
- it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do
- ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental'
- result = ruby_exe('case ($; = ""); in a; end', args: '2>&1')
- result.should == ""
- end
+ it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do
+ ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental'
+ result = ruby_exe('case ($; = ""); in a; end', args: '2>&1')
+ result.should == ""
end
it "requires the file for '-r'" do
diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb
index bddc672d3b..81ba56e01e 100644
--- a/spec/ruby/core/array/clear_spec.rb
+++ b/spec/ruby/core/array/clear_spec.rb
@@ -20,30 +20,10 @@ describe "Array#clear" do
a.size.should == 0
end
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- a = [1]
- a.taint
- a.tainted?.should be_true
- a.clear
- a.tainted?.should be_true
- end
- end
-
it "does not accept any arguments" do
-> { [1].clear(true) }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "keeps untrusted status" do
- a = [1]
- a.untrust
- a.untrusted?.should be_true
- a.clear
- a.untrusted?.should be_true
- end
- end
-
it "raises a FrozenError on a frozen array" do
a = [1]
a.freeze
diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb
index aa3c1c0446..83b3fa2a89 100644
--- a/spec/ruby/core/array/compact_spec.rb
+++ b/spec/ruby/core/array/compact_spec.rb
@@ -21,20 +21,6 @@ describe "Array#compact" do
it "does not return subclass instance for Array subclasses" do
ArraySpecs::MyArray[1, 2, 3, nil].compact.should be_an_instance_of(Array)
end
-
- ruby_version_is ''...'2.7' do
- it "does not keep tainted status even if all elements are removed" do
- a = [nil, nil]
- a.taint
- a.compact.tainted?.should be_false
- end
-
- it "does not keep untrusted status even if all elements are removed" do
- a = [nil, nil]
- a.untrust
- a.compact.untrusted?.should be_false
- end
- end
end
describe "Array#compact!" do
@@ -59,22 +45,6 @@ describe "Array#compact!" do
[1, 2, false, 3].compact!.should == nil
end
- ruby_version_is ''...'2.7' do
- it "keeps tainted status even if all elements are removed" do
- a = [nil, nil]
- a.taint
- a.compact!
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status even if all elements are removed" do
- a = [nil, nil]
- a.untrust
- a.compact!
- a.untrusted?.should be_true
- end
- end
-
it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.compact! }.should raise_error(FrozenError)
end
diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb
index da6763bfd6..f3cab9c17c 100644
--- a/spec/ruby/core/array/concat_spec.rb
+++ b/spec/ruby/core/array/concat_spec.rb
@@ -41,64 +41,6 @@ describe "Array#concat" do
-> { ArraySpecs.frozen_array.concat([]) }.should raise_error(FrozenError)
end
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- ary = [1, 2]
- ary.taint
- ary.concat([3])
- ary.tainted?.should be_true
- ary.concat([])
- ary.tainted?.should be_true
- end
-
- it "is not infected by the other" do
- ary = [1,2]
- other = [3]; other.taint
- ary.tainted?.should be_false
- ary.concat(other)
- ary.tainted?.should be_false
- end
-
- it "keeps the tainted status of elements" do
- ary = [ Object.new, Object.new, Object.new ]
- ary.each {|x| x.taint }
-
- ary.concat([ Object.new ])
- ary[0].tainted?.should be_true
- ary[1].tainted?.should be_true
- ary[2].tainted?.should be_true
- ary[3].tainted?.should be_false
- end
-
- it "keeps untrusted status" do
- ary = [1, 2]
- ary.untrust
- ary.concat([3])
- ary.untrusted?.should be_true
- ary.concat([])
- ary.untrusted?.should be_true
- end
-
- it "is not infected untrustedness by the other" do
- ary = [1,2]
- other = [3]; other.untrust
- ary.untrusted?.should be_false
- ary.concat(other)
- ary.untrusted?.should be_false
- end
-
- it "keeps the untrusted status of elements" do
- ary = [ Object.new, Object.new, Object.new ]
- ary.each {|x| x.untrust }
-
- ary.concat([ Object.new ])
- ary[0].untrusted?.should be_true
- ary[1].untrusted?.should be_true
- ary[2].untrusted?.should be_true
- ary[3].untrusted?.should be_false
- end
- end
-
it "appends elements to an Array with enough capacity that has been shifted" do
ary = [1, 2, 3, 4, 5]
2.times { ary.shift }
diff --git a/spec/ruby/core/array/deconstruct_spec.rb b/spec/ruby/core/array/deconstruct_spec.rb
index 2b07152dfc..ad67abe47b 100644
--- a/spec/ruby/core/array/deconstruct_spec.rb
+++ b/spec/ruby/core/array/deconstruct_spec.rb
@@ -1,11 +1,9 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Array#deconstruct" do
- it "returns self" do
- array = [1]
+describe "Array#deconstruct" do
+ it "returns self" do
+ array = [1]
- array.deconstruct.should equal array
- end
+ array.deconstruct.should equal array
end
end
diff --git a/spec/ruby/core/array/delete_at_spec.rb b/spec/ruby/core/array/delete_at_spec.rb
index fc225a03f1..80ec643702 100644
--- a/spec/ruby/core/array/delete_at_spec.rb
+++ b/spec/ruby/core/array/delete_at_spec.rb
@@ -38,26 +38,4 @@ describe "Array#delete_at" do
it "raises a FrozenError on a frozen array" do
-> { [1,2,3].freeze.delete_at(0) }.should raise_error(FrozenError)
end
-
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- ary = [1, 2]
- ary.taint
- ary.tainted?.should be_true
- ary.delete_at(0)
- ary.tainted?.should be_true
- ary.delete_at(0) # now empty
- ary.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- ary = [1, 2]
- ary.untrust
- ary.untrusted?.should be_true
- ary.delete_at(0)
- ary.untrusted?.should be_true
- ary.delete_at(0) # now empty
- ary.untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/array/delete_if_spec.rb b/spec/ruby/core/array/delete_if_spec.rb
index e1931220f5..1459cc8d04 100644
--- a/spec/ruby/core/array/delete_if_spec.rb
+++ b/spec/ruby/core/array/delete_if_spec.rb
@@ -47,22 +47,6 @@ describe "Array#delete_if" do
-> { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(FrozenError)
end
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- @a.taint
- @a.tainted?.should be_true
- @a.delete_if{ true }
- @a.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- @a.untrust
- @a.untrusted?.should be_true
- @a.delete_if{ true }
- @a.untrusted?.should be_true
- end
- end
-
it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3]
it_behaves_like :delete_if, :delete_if
end
diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb
index 5d53c74e47..dddbbe6bd3 100644
--- a/spec/ruby/core/array/delete_spec.rb
+++ b/spec/ruby/core/array/delete_spec.rb
@@ -43,26 +43,4 @@ describe "Array#delete" do
it "raises a FrozenError on a frozen array" do
-> { [1, 2, 3].freeze.delete(1) }.should raise_error(FrozenError)
end
-
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- a = [1, 2]
- a.taint
- a.tainted?.should be_true
- a.delete(2)
- a.tainted?.should be_true
- a.delete(1) # now empty
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- a = [1, 2]
- a.untrust
- a.untrusted?.should be_true
- a.delete(2)
- a.untrusted?.should be_true
- a.delete(1) # now empty
- a.untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb
index 1e192c100f..df5ca9582e 100644
--- a/spec/ruby/core/array/element_set_spec.rb
+++ b/spec/ruby/core/array/element_set_spec.rb
@@ -481,50 +481,48 @@ describe "Array#[]= with [m..]" do
end
end
-ruby_version_is "2.7" do
- describe "Array#[]= with [..n] and [...n]" do
- it "just sets the section defined by range to nil even if the rhs is nil" do
- a = [1, 2, 3, 4, 5]
- a[eval("(..2)")] = nil
- a.should == [nil, 4, 5]
- a[eval("(...2)")] = nil
- a.should == [nil, 5]
- end
+describe "Array#[]= with [..n] and [...n]" do
+ it "just sets the section defined by range to nil even if the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[(..2)] = nil
+ a.should == [nil, 4, 5]
+ a[(...2)] = nil
+ a.should == [nil, 5]
+ end
- it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do
- a = [1, 2, 3, 4, 5]
- a[eval("(..-3)")] = nil
- a.should == [nil, 4, 5]
- a[eval("(...-1)")] = [nil, 5]
- end
+ it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[(..-3)] = nil
+ a.should == [nil, 4, 5]
+ a[(...-1)] = [nil, 5]
+ end
- it "replaces the section defined by range" do
- a = [6, 5, 4, 3, 2, 1]
- a[eval("(...3)")] = 9
- a.should == [9, 3, 2, 1]
- a[eval("(..2)")] = [7, 7, 7, 7, 7]
- a.should == [7, 7, 7, 7, 7, 1]
- end
+ it "replaces the section defined by range" do
+ a = [6, 5, 4, 3, 2, 1]
+ a[(...3)] = 9
+ a.should == [9, 3, 2, 1]
+ a[(..2)] = [7, 7, 7, 7, 7]
+ a.should == [7, 7, 7, 7, 7, 1]
+ end
- it "replaces the section if n < 0" do
- a = [1, 2, 3, 4, 5]
- a[eval("(..-2)")] = [7, 8, 9]
- a.should == [7, 8, 9, 5]
- end
+ it "replaces the section if n < 0" do
+ a = [1, 2, 3, 4, 5]
+ a[(..-2)] = [7, 8, 9]
+ a.should == [7, 8, 9, 5]
+ end
- it "replaces everything if n > the array size" do
- a = [1, 2, 3]
- a[eval("(...7)")] = [4]
- a.should == [4]
- end
+ it "replaces everything if n > the array size" do
+ a = [1, 2, 3]
+ a[(...7)] = [4]
+ a.should == [4]
+ end
- it "inserts at the beginning if n < negative the array size" do
- a = [1, 2, 3]
- a[eval("(..-7)")] = [4]
- a.should == [4, 1, 2, 3]
- a[eval("(...-10)")] = [6]
- a.should == [6, 4, 1, 2, 3]
- end
+ it "inserts at the beginning if n < negative the array size" do
+ a = [1, 2, 3]
+ a[(..-7)] = [4]
+ a.should == [4, 1, 2, 3]
+ a[(...-10)] = [6]
+ a.should == [6, 4, 1, 2, 3]
end
end
diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb
index bfa8db551b..6369f23544 100644
--- a/spec/ruby/core/array/fill_spec.rb
+++ b/spec/ruby/core/array/fill_spec.rb
@@ -323,10 +323,8 @@ describe "Array#fill with (filler, range)" do
[1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
end
- ruby_version_is "2.7" do
- it "works with beginless ranges" do
- [1, 2, 3, 4].fill('x', eval("(..2)")).should == ["x", "x", "x", 4]
- [1, 2, 3, 4].fill(eval("(...2)")) { |x| x + 2 }.should == [2, 3, 3, 4]
- end
+ it "works with beginless ranges" do
+ [1, 2, 3, 4].fill('x', (..2)).should == ["x", "x", "x", 4]
+ [1, 2, 3, 4].fill((...2)) { |x| x + 2 }.should == [2, 3, 3, 4]
end
end
diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb
index 2f9fb8a3ec..1770b5389a 100644
--- a/spec/ruby/core/array/flatten_spec.rb
+++ b/spec/ruby/core/array/flatten_spec.rb
@@ -147,16 +147,6 @@ describe "Array#flatten" do
end
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted array if self is tainted" do
- [].taint.flatten.tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- [].untrust.flatten.untrusted?.should be_true
- end
- end
-
it "performs respond_to? and method_missing-aware checks when coercing elements to array" do
bo = BasicObject.new
[bo].flatten.should == [bo]
diff --git a/spec/ruby/core/array/intersection_spec.rb b/spec/ruby/core/array/intersection_spec.rb
index 27d90f1e44..e01a68d389 100644
--- a/spec/ruby/core/array/intersection_spec.rb
+++ b/spec/ruby/core/array/intersection_spec.rb
@@ -6,16 +6,14 @@ describe "Array#&" do
it_behaves_like :array_intersection, :&
end
-ruby_version_is "2.7" do
- describe "Array#intersection" do
- it_behaves_like :array_intersection, :intersection
+describe "Array#intersection" do
+ it_behaves_like :array_intersection, :intersection
- it "accepts multiple arguments" do
- [1, 2, 3, 4].intersection([1, 2, 3], [2, 3, 4]).should == [2, 3]
- end
+ it "accepts multiple arguments" do
+ [1, 2, 3, 4].intersection([1, 2, 3], [2, 3, 4]).should == [2, 3]
+ end
- it "preserves elements order from original array" do
- [1, 2, 3, 4].intersection([3, 2, 1]).should == [1, 2, 3]
- end
+ it "preserves elements order from original array" do
+ [1, 2, 3, 4].intersection([3, 2, 1]).should == [1, 2, 3]
end
end
diff --git a/spec/ruby/core/array/multiply_spec.rb b/spec/ruby/core/array/multiply_spec.rb
index 16e407348b..23d5c99f3a 100644
--- a/spec/ruby/core/array/multiply_spec.rb
+++ b/spec/ruby/core/array/multiply_spec.rb
@@ -97,46 +97,6 @@ describe "Array#* with an integer" do
ScratchPad.recorded.should be_nil
end
end
-
- ruby_version_is ''...'2.7' do
- it "copies the taint status of the original array even if the passed count is 0" do
- ary = [1, 2, 3]
- ary.taint
- (ary * 0).should.tainted?
- end
-
- it "copies the taint status of the original array even if the array is empty" do
- ary = []
- ary.taint
- (ary * 3).should.tainted?
- end
-
- it "copies the taint status of the original array if the passed count is not 0" do
- ary = [1, 2, 3]
- ary.taint
- (ary * 1).should.tainted?
- (ary * 2).should.tainted?
- end
-
- it "copies the untrusted status of the original array even if the passed count is 0" do
- ary = [1, 2, 3]
- ary.untrust
- (ary * 0).should.untrusted?
- end
-
- it "copies the untrusted status of the original array even if the array is empty" do
- ary = []
- ary.untrust
- (ary * 3).should.untrusted?
- end
-
- it "copies the untrusted status of the original array if the passed count is not 0" do
- ary = [1, 2, 3]
- ary.untrust
- (ary * 1).should.untrusted?
- (ary * 2).should.untrusted?
- end
- end
end
describe "Array#* with a string" do
diff --git a/spec/ruby/core/array/pack/p_spec.rb b/spec/ruby/core/array/pack/p_spec.rb
index d7dff8a4da..b023bf9110 100644
--- a/spec/ruby/core/array/pack/p_spec.rb
+++ b/spec/ruby/core/array/pack/p_spec.rb
@@ -15,18 +15,6 @@ describe "Array#pack with format 'P'" do
["hello"].pack("P").unpack("P5").should == ["hello"]
end
- ruby_version_is ''...'2.7' do
- it "taints the input string" do
- input_string = "hello"
- [input_string].pack("P")
- input_string.tainted?.should be_true
- end
-
- it "does not taint the output string in normal cases" do
- ["hello"].pack("P").tainted?.should be_false
- end
- end
-
it "with nil gives a null pointer" do
[nil].pack("P").unpack("J").should == [0]
end
@@ -44,18 +32,6 @@ describe "Array#pack with format 'p'" do
["hello"].pack("p").unpack("p").should == ["hello"]
end
- ruby_version_is ''...'2.7' do
- it "taints the input string" do
- input_string = "hello"
- [input_string].pack("p")
- input_string.tainted?.should be_true
- end
-
- it "does not taint the output string in normal cases" do
- ["hello"].pack("p").tainted?.should be_false
- end
- end
-
it "with nil gives a null pointer" do
[nil].pack("p").unpack("J").should == [0]
end
diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb
index 9061273ad6..23e239d3de 100644
--- a/spec/ruby/core/array/pack/shared/basic.rb
+++ b/spec/ruby/core/array/pack/shared/basic.rb
@@ -32,12 +32,6 @@ describe :array_pack_basic_non_float, shared: true do
d.should_receive(:to_str).and_return("x"+pack_format)
[@obj, @obj].pack(d).should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the output string if the format string is tainted" do
- [@obj, @obj].pack("x"+pack_format.taint).tainted?.should be_true
- end
- end
end
describe :array_pack_basic_float, shared: true do
@@ -50,12 +44,6 @@ describe :array_pack_basic_float, shared: true do
d.should_receive(:to_str).and_return("x"+pack_format)
[1.2, 4.7].pack(d).should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the output string if the format string is tainted" do
- [3.2, 2.8].pack("x"+pack_format.taint).tainted?.should be_true
- end
- end
end
describe :array_pack_no_platform, shared: true do
diff --git a/spec/ruby/core/array/pack/shared/taint.rb b/spec/ruby/core/array/pack/shared/taint.rb
index 565f04b8b9..2c2b011c34 100644
--- a/spec/ruby/core/array/pack/shared/taint.rb
+++ b/spec/ruby/core/array/pack/shared/taint.rb
@@ -1,35 +1,2 @@
describe :array_pack_taint, shared: true do
- ruby_version_is ''...'2.7' do
- it "returns a tainted string when a pack argument is tainted" do
- ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true
- end
-
- it "does not return a tainted string when the array is tainted" do
- ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false
- end
-
- it "returns a tainted string when the format is tainted" do
- ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true
- end
-
- it "returns a tainted string when an empty format is tainted" do
- ["abcd", 0x20].pack("".taint).tainted?.should be_true
- end
-
- it "returns a untrusted string when the format is untrusted" do
- ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when the empty format is untrusted" do
- ["abcd", 0x20].pack("".untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when a pack argument is untrusted" do
- ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true
- end
-
- it "returns a trusted string when the array is untrusted" do
- ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false
- end
- end
end
diff --git a/spec/ruby/core/array/plus_spec.rb b/spec/ruby/core/array/plus_spec.rb
index 45f8438208..3962b05c39 100644
--- a/spec/ruby/core/array/plus_spec.rb
+++ b/spec/ruby/core/array/plus_spec.rb
@@ -40,20 +40,4 @@ describe "Array#+" do
it "does not call to_ary on array subclasses" do
([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
end
-
- ruby_version_is ''...'2.7' do
- it "does not get infected even if an original array is tainted" do
- ([1, 2] + [3, 4]).tainted?.should be_false
- ([1, 2].taint + [3, 4]).tainted?.should be_false
- ([1, 2] + [3, 4].taint).tainted?.should be_false
- ([1, 2].taint + [3, 4].taint).tainted?.should be_false
- end
-
- it "does not infected even if an original array is untrusted" do
- ([1, 2] + [3, 4]).untrusted?.should be_false
- ([1, 2].untrust + [3, 4]).untrusted?.should be_false
- ([1, 2] + [3, 4].untrust).untrusted?.should be_false
- ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false
- end
- end
end
diff --git a/spec/ruby/core/array/pop_spec.rb b/spec/ruby/core/array/pop_spec.rb
index 96ef78da32..2a19408660 100644
--- a/spec/ruby/core/array/pop_spec.rb
+++ b/spec/ruby/core/array/pop_spec.rb
@@ -30,16 +30,6 @@ describe "Array#pop" do
array.pop.should == [1, 'two', 3.0, array, array, array, array]
end
- ruby_version_is ''...'2.7' do
- it "keeps taint status" do
- a = [1, 2].taint
- a.pop
- a.tainted?.should be_true
- a.pop
- a.tainted?.should be_true
- end
- end
-
it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.pop }.should raise_error(FrozenError)
end
@@ -48,16 +38,6 @@ describe "Array#pop" do
-> { ArraySpecs.empty_frozen_array.pop }.should raise_error(FrozenError)
end
- ruby_version_is ''...'2.7' do
- it "keeps untrusted status" do
- a = [1, 2].untrust
- a.pop
- a.untrusted?.should be_true
- a.pop
- a.untrusted?.should be_true
- end
- end
-
describe "passed a number n as an argument" do
it "removes and returns an array with the last n elements of the array" do
a = [1, 2, 3, 4, 5, 6]
@@ -136,41 +116,9 @@ describe "Array#pop" do
ArraySpecs::MyArray[1, 2, 3].pop(2).should be_an_instance_of(Array)
end
- ruby_version_is ''...'2.7' do
- it "returns an untainted array even if the array is tainted" do
- ary = [1, 2].taint
- ary.pop(2).tainted?.should be_false
- ary.pop(0).tainted?.should be_false
- end
-
- it "keeps taint status" do
- a = [1, 2].taint
- a.pop(2)
- a.tainted?.should be_true
- a.pop(2)
- a.tainted?.should be_true
- end
-
- it "returns a trusted array even if the array is untrusted" do
- ary = [1, 2].untrust
- ary.pop(2).untrusted?.should be_false
- ary.pop(0).untrusted?.should be_false
- end
- end
-
it "raises a FrozenError on a frozen array" do
-> { ArraySpecs.frozen_array.pop(2) }.should raise_error(FrozenError)
-> { ArraySpecs.frozen_array.pop(0) }.should raise_error(FrozenError)
end
-
- ruby_version_is ''...'2.7' do
- it "keeps untrusted status" do
- a = [1, 2].untrust
- a.pop(2)
- a.untrusted?.should be_true
- a.pop(2)
- a.untrusted?.should be_true
- end
- end
end
end
diff --git a/spec/ruby/core/array/shared/clone.rb b/spec/ruby/core/array/shared/clone.rb
index 3c17b1f10f..035b45ec99 100644
--- a/spec/ruby/core/array/shared/clone.rb
+++ b/spec/ruby/core/array/shared/clone.rb
@@ -17,28 +17,4 @@ describe :array_clone, shared: true do
b.should == a
b.__id__.should_not == a.__id__
end
-
- ruby_version_is ''...'2.7' do
- it "copies taint status from the original" do
- a = [1, 2, 3, 4]
- b = [1, 2, 3, 4]
- a.taint
- aa = a.send @method
- bb = b.send @method
-
- aa.should.tainted?
- bb.should_not.tainted?
- end
-
- it "copies untrusted status from the original" do
- a = [1, 2, 3, 4]
- b = [1, 2, 3, 4]
- a.untrust
- aa = a.send @method
- bb = b.send @method
-
- aa.should.untrusted?
- bb.should_not.untrusted?
- end
- end
end
diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb
index d84432734a..8d75f7db9a 100644
--- a/spec/ruby/core/array/shared/collect.rb
+++ b/spec/ruby/core/array/shared/collect.rb
@@ -42,20 +42,6 @@ describe :array_collect, shared: true do
}.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "does not copy tainted status" do
- a = [1, 2, 3]
- a.taint
- a.send(@method){|x| x}.tainted?.should be_false
- end
-
- it "does not copy untrusted status" do
- a = [1, 2, 3]
- a.untrust
- a.send(@method){|x| x}.untrusted?.should be_false
- end
- end
-
before :all do
@object = [1, 2, 3, 4]
end
@@ -96,23 +82,6 @@ describe :array_collect_b, shared: true do
a.should == ["1!", "2!", "3!"]
end
- ruby_version_is ''...'2.7' do
- it "keeps tainted status" do
- a = [1, 2, 3]
- a.taint
- a.tainted?.should be_true
- a.send(@method){|x| x}
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- a = [1, 2, 3]
- a.untrust
- a.send(@method){|x| x}
- a.untrusted?.should be_true
- end
- end
-
describe "when frozen" do
it "raises a FrozenError" do
-> { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(FrozenError)
diff --git a/spec/ruby/core/array/shared/inspect.rb b/spec/ruby/core/array/shared/inspect.rb
index 736f8d946b..a2b43d4959 100644
--- a/spec/ruby/core/array/shared/inspect.rb
+++ b/spec/ruby/core/array/shared/inspect.rb
@@ -64,32 +64,6 @@ describe :array_inspect, shared: true do
ArraySpecs.empty_recursive_array.send(@method).should == "[[...]]"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if the Array is non-empty and tainted" do
- [1, 2].taint.send(@method).tainted?.should be_true
- end
-
- it "does not taint the result if the Array is tainted but empty" do
- [].taint.send(@method).tainted?.should be_false
- end
-
- it "taints the result if an element is tainted" do
- ["str".taint].send(@method).tainted?.should be_true
- end
-
- it "untrusts the result if the Array is untrusted" do
- [1, 2].untrust.send(@method).untrusted?.should be_true
- end
-
- it "does not untrust the result if the Array is untrusted but empty" do
- [].untrust.send(@method).untrusted?.should be_false
- end
-
- it "untrusts the result if an element is untrusted" do
- ["str".untrust].send(@method).untrusted?.should be_true
- end
- end
-
describe "with encoding" do
before :each do
@default_external_encoding = Encoding.default_external
diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb
index dfdb4ae1e4..507b13e3c8 100644
--- a/spec/ruby/core/array/shared/join.rb
+++ b/spec/ruby/core/array/shared/join.rb
@@ -58,36 +58,6 @@ describe :array_join_with_default_separator, shared: true do
-> { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "taints the result if the Array is tainted and non-empty" do
- [1, 2].taint.send(@method).tainted?.should be_true
- end
-
- it "does not taint the result if the Array is tainted but empty" do
- [].taint.send(@method).tainted?.should be_false
- end
-
- it "taints the result if the result of coercing an element is tainted" do
- s = mock("taint")
- s.should_receive(:to_s).and_return("str".taint)
- [s].send(@method).tainted?.should be_true
- end
-
- it "untrusts the result if the Array is untrusted and non-empty" do
- [1, 2].untrust.send(@method).untrusted?.should be_true
- end
-
- it "does not untrust the result if the Array is untrusted but empty" do
- [].untrust.send(@method).untrusted?.should be_false
- end
-
- it "untrusts the result if the result of coercing an element is untrusted" do
- s = mock("untrust")
- s.should_receive(:to_s).and_return("str".untrust)
- [s].send(@method).untrusted?.should be_true
- end
- end
-
it "uses the first encoding when other strings are compatible" do
ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings
ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings
@@ -114,18 +84,16 @@ describe :array_join_with_default_separator, shared: true do
-> { ary_utf8_bad_binary.send(@method) }.should raise_error(EncodingError)
end
- ruby_version_is "2.7" do
- context "when $, is not nil" do
- before do
- suppress_warning do
- $, = '*'
- end
+ context "when $, is not nil" do
+ before do
+ suppress_warning do
+ $, = '*'
end
+ end
- it "warns" do
- -> { [].join }.should complain(/warning: \$, is set to non-nil value/)
- -> { [].join(nil) }.should complain(/warning: \$, is set to non-nil value/)
- end
+ it "warns" do
+ -> { [].join }.should complain(/warning: \$, is set to non-nil value/)
+ -> { [].join(nil) }.should complain(/warning: \$, is set to non-nil value/)
end
end
end
@@ -141,42 +109,4 @@ describe :array_join_with_string_separator, shared: true do
[1, [2, [3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
[1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
end
-
- ruby_version_is ''...'2.7' do
- describe "with a tainted separator" do
- before :each do
- @sep = ":".taint
- end
-
- it "does not taint the result if the array is empty" do
- [].send(@method, @sep).tainted?.should be_false
- end
-
- it "does not taint the result if the array has only one element" do
- [1].send(@method, @sep).tainted?.should be_false
- end
-
- it "taints the result if the array has two or more elements" do
- [1, 2].send(@method, @sep).tainted?.should be_true
- end
- end
-
- describe "with an untrusted separator" do
- before :each do
- @sep = ":".untrust
- end
-
- it "does not untrust the result if the array is empty" do
- [].send(@method, @sep).untrusted?.should be_false
- end
-
- it "does not untrust the result if the array has only one element" do
- [1].send(@method, @sep).untrusted?.should be_false
- end
-
- it "untrusts the result if the array has two or more elements" do
- [1, 2].send(@method, @sep).untrusted?.should be_true
- end
- end
- end
end
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
index 540a050130..3b09fdcbc6 100644
--- a/spec/ruby/core/array/shared/slice.rb
+++ b/spec/ruby/core/array/shared/slice.rb
@@ -556,34 +556,34 @@ describe :array_slice, shared: true do
it "has beginless range and positive steps" do
# end with zero index
- @array.send(@method, eval("(..0).step(1)")).should == [0]
- @array.send(@method, eval("(...0).step(1)")).should == []
+ @array.send(@method, (..0).step(1)).should == [0]
+ @array.send(@method, (...0).step(1)).should == []
- @array.send(@method, eval("(..0).step(2)")).should == [0]
- @array.send(@method, eval("(...0).step(2)")).should == []
+ @array.send(@method, (..0).step(2)).should == [0]
+ @array.send(@method, (...0).step(2)).should == []
- @array.send(@method, eval("(..0).step(10)")).should == [0]
- @array.send(@method, eval("(...0).step(10)")).should == []
+ @array.send(@method, (..0).step(10)).should == [0]
+ @array.send(@method, (...0).step(10)).should == []
# end with positive index
- @array.send(@method, eval("(..3).step(1)")).should == [0, 1, 2, 3]
- @array.send(@method, eval("(...3).step(1)")).should == [0, 1, 2]
+ @array.send(@method, (..3).step(1)).should == [0, 1, 2, 3]
+ @array.send(@method, (...3).step(1)).should == [0, 1, 2]
- @array.send(@method, eval("(..3).step(2)")).should == [0, 2]
- @array.send(@method, eval("(...3).step(2)")).should == [0, 2]
+ @array.send(@method, (..3).step(2)).should == [0, 2]
+ @array.send(@method, (...3).step(2)).should == [0, 2]
- @array.send(@method, eval("(..3).step(10)")).should == [0]
- @array.send(@method, eval("(...3).step(10)")).should == [0]
+ @array.send(@method, (..3).step(10)).should == [0]
+ @array.send(@method, (...3).step(10)).should == [0]
# end with negative index
- @array.send(@method, eval("(..-2).step(1)")).should == [0, 1, 2, 3, 4,]
- @array.send(@method, eval("(...-2).step(1)")).should == [0, 1, 2, 3]
+ @array.send(@method, (..-2).step(1)).should == [0, 1, 2, 3, 4,]
+ @array.send(@method, (...-2).step(1)).should == [0, 1, 2, 3]
- @array.send(@method, eval("(..-2).step(2)")).should == [0, 2, 4]
- @array.send(@method, eval("(...-2).step(2)")).should == [0, 2]
+ @array.send(@method, (..-2).step(2)).should == [0, 2, 4]
+ @array.send(@method, (...-2).step(2)).should == [0, 2]
- @array.send(@method, eval("(..-2).step(10)")).should == [0]
- @array.send(@method, eval("(...-2).step(10)")).should == [0]
+ @array.send(@method, (..-2).step(10)).should == [0]
+ @array.send(@method, (...-2).step(10)).should == [0]
end
it "has endless range and negative steps" do
@@ -770,26 +770,24 @@ describe :array_slice, shared: true do
end
end
- ruby_version_is "2.7" do
- it "can accept beginless ranges" do
- a = [0, 1, 2, 3, 4, 5]
- a.send(@method, eval("(..3)")).should == [0, 1, 2, 3]
- a.send(@method, eval("(...3)")).should == [0, 1, 2]
- a.send(@method, eval("(..-3)")).should == [0, 1, 2, 3]
- a.send(@method, eval("(...-3)")).should == [0, 1, 2]
- a.send(@method, eval("(..0)")).should == [0]
- a.send(@method, eval("(...0)")).should == []
- a.send(@method, eval("(..9)")).should == [0, 1, 2, 3, 4, 5]
- a.send(@method, eval("(...9)")).should == [0, 1, 2, 3, 4, 5]
- a.send(@method, eval("(..-9)")).should == []
- a.send(@method, eval("(...-9)")).should == []
- end
-
- it "can accept nil...nil ranges" do
- a = [0, 1, 2, 3, 4, 5]
- a.send(@method, eval("(nil...nil)")).should == a
- a.send(@method, eval("(...nil)")).should == a
- a.send(@method, eval("(nil..)")).should == a
- end
+ it "can accept beginless ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a.send(@method, (..3)).should == [0, 1, 2, 3]
+ a.send(@method, (...3)).should == [0, 1, 2]
+ a.send(@method, (..-3)).should == [0, 1, 2, 3]
+ a.send(@method, (...-3)).should == [0, 1, 2]
+ a.send(@method, (..0)).should == [0]
+ a.send(@method, (...0)).should == []
+ a.send(@method, (..9)).should == [0, 1, 2, 3, 4, 5]
+ a.send(@method, (...9)).should == [0, 1, 2, 3, 4, 5]
+ a.send(@method, (..-9)).should == []
+ a.send(@method, (...-9)).should == []
+ end
+
+ it "can accept nil...nil ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a.send(@method, eval("(nil...nil)")).should == a
+ a.send(@method, (...nil)).should == a
+ a.send(@method, eval("(nil..)")).should == a
end
end
diff --git a/spec/ruby/core/array/shift_spec.rb b/spec/ruby/core/array/shift_spec.rb
index b998e45d28..6b4ef39f77 100644
--- a/spec/ruby/core/array/shift_spec.rb
+++ b/spec/ruby/core/array/shift_spec.rb
@@ -116,21 +116,5 @@ describe "Array#shift" do
it "does not return subclass instances with Array subclass" do
ArraySpecs::MyArray[1, 2, 3].shift(2).should be_an_instance_of(Array)
end
-
- ruby_version_is ''...'2.7' do
- it "returns an untainted array even if the array is tainted" do
- ary = [1, 2].taint
- ary.shift(2).tainted?.should be_false
- ary.shift(0).tainted?.should be_false
- end
-
- it "keeps taint status" do
- a = [1, 2].taint
- a.shift(2)
- a.tainted?.should be_true
- a.shift(2)
- a.tainted?.should be_true
- end
- end
end
end
diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb
index 8c276f9084..8e1499855a 100644
--- a/spec/ruby/core/array/slice_spec.rb
+++ b/spec/ruby/core/array/slice_spec.rb
@@ -172,16 +172,14 @@ describe "Array#slice!" do
a.should == [1, 2]
end
- ruby_version_is "2.7" do
- it "works with beginless ranges" do
- a = [0,1,2,3,4]
- a.slice!(eval("(..3)")).should == [0, 1, 2, 3]
- a.should == [4]
-
- a = [0,1,2,3,4]
- a.slice!(eval("(...-2)")).should == [0, 1, 2]
- a.should == [3, 4]
- end
+ it "works with beginless ranges" do
+ a = [0,1,2,3,4]
+ a.slice!((..3)).should == [0, 1, 2, 3]
+ a.should == [4]
+
+ a = [0,1,2,3,4]
+ a.slice!((...-2)).should == [0, 1, 2]
+ a.should == [3, 4]
end
describe "with a subclass of Array" do
diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb
index 5911c23e6a..4461cae16b 100644
--- a/spec/ruby/core/array/uniq_spec.rb
+++ b/spec/ruby/core/array/uniq_spec.rb
@@ -39,76 +39,32 @@ describe "Array#uniq" do
[x, y].uniq.should == [x, y]
end
- ruby_version_is '2.7' do
- 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)
- false
- end
-
- obj
- end
-
- a.uniq.should == a
+ 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)
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- true
- end
-
- obj
+ def obj.eql?(o)
+ false
end
- a.uniq.size.should == 1
+ obj
end
- end
- ruby_version_is ''...'2.7' do
- 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
-
- obj
- end
-
- a.uniq.should == a
- a[0].should.tainted?
- a[1].should.tainted?
+ a.uniq.should == a
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
+ 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
- true
- end
-
- obj
+ def obj.eql?(o)
+ true
end
- a.uniq.size.should == 1
- a[0].should.tainted?
- a[1].should.tainted?
+ obj
end
+
+ a.uniq.size.should == 1
end
it "compares elements based on the value returned from the block" do
diff --git a/spec/ruby/core/array/values_at_spec.rb b/spec/ruby/core/array/values_at_spec.rb
index f1522e0bfe..2c6fd16947 100644
--- a/spec/ruby/core/array/values_at_spec.rb
+++ b/spec/ruby/core/array/values_at_spec.rb
@@ -66,10 +66,8 @@ describe "Array#values_at" do
[1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
end
- ruby_version_is "2.7" do
- it "works when given beginless ranges" do
- [1, 2, 3, 4].values_at(eval("(..2)")).should == [1, 2, 3]
- [1, 2, 3, 4].values_at(eval("(...2)")).should == [1, 2]
- end
+ it "works when given beginless ranges" do
+ [1, 2, 3, 4].values_at((..2)).should == [1, 2, 3]
+ [1, 2, 3, 4].values_at((...2)).should == [1, 2]
end
end
diff --git a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
index 7c87a970d7..b0b86030e2 100644
--- a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
+++ b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
@@ -49,15 +49,7 @@ describe "RUBY_RELEASE_DATE" do
end
describe "RUBY_REVISION" do
- ruby_version_is ""..."2.7" do
- it "is an Integer" do
- RUBY_REVISION.should be_kind_of(Integer)
- end
- end
-
- ruby_version_is "2.7" do
- it "is a String" do
- RUBY_REVISION.should be_kind_of(String)
- end
+ it "is a String" do
+ RUBY_REVISION.should be_kind_of(String)
end
end
diff --git a/spec/ruby/core/comparable/clamp_spec.rb b/spec/ruby/core/comparable/clamp_spec.rb
index 393496fc76..796d4a18c1 100644
--- a/spec/ruby/core/comparable/clamp_spec.rb
+++ b/spec/ruby/core/comparable/clamp_spec.rb
@@ -2,14 +2,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe 'Comparable#clamp' do
- ruby_version_is ""..."2.7" do
- it 'raises an Argument error unless given 2 parameters' do
- c = ComparableSpecs::Weird.new(0)
- -> { c.clamp(c) }.should raise_error(ArgumentError)
- -> { c.clamp(c, c, c) }.should raise_error(ArgumentError)
- end
- end
-
it 'raises an Argument error unless the 2 parameters are correctly ordered' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
@@ -48,41 +40,39 @@ describe 'Comparable#clamp' do
c.clamp(one, two).should equal(two)
end
- ruby_version_is "2.7" do
- it 'returns self if within the given range 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 minimum value of the range parameters 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 maximum value of the range parameters 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
-
- it 'raises an Argument error if the range parameter is exclusive' do
- one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(3)
-
- -> { c.clamp(one...two) }.should raise_error(ArgumentError)
- end
+ it 'returns self if within the given range 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 minimum value of the range parameters 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 maximum value of the range parameters 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
+
+ it 'raises an Argument error if the range parameter is exclusive' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ -> { c.clamp(one...two) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/complex/comparison_spec.rb b/spec/ruby/core/complex/comparison_spec.rb
index 2a437afb71..3a3142f234 100644
--- a/spec/ruby/core/complex/comparison_spec.rb
+++ b/spec/ruby/core/complex/comparison_spec.rb
@@ -1,27 +1,25 @@
require_relative '../../spec_helper'
describe "Complex#<=>" do
- ruby_version_is "2.7" do
- it "returns nil if either self or argument has imaginary part" do
- (Complex(5, 1) <=> Complex(2)).should be_nil
- (Complex(1) <=> Complex(2, 1)).should be_nil
- (5 <=> Complex(2, 1)).should be_nil
- end
+ it "returns nil if either self or argument has imaginary part" do
+ (Complex(5, 1) <=> Complex(2)).should be_nil
+ (Complex(1) <=> Complex(2, 1)).should be_nil
+ (5 <=> Complex(2, 1)).should be_nil
+ end
- it "returns nil if argument is not numeric" do
- (Complex(5, 1) <=> "cmp").should be_nil
- (Complex(1) <=> "cmp").should be_nil
- (Complex(1) <=> Object.new).should be_nil
- end
+ it "returns nil if argument is not numeric" do
+ (Complex(5, 1) <=> "cmp").should be_nil
+ (Complex(1) <=> "cmp").should be_nil
+ (Complex(1) <=> Object.new).should be_nil
+ end
- it "returns 0, 1, or -1 if self and argument do not have imaginary part" do
- (Complex(5) <=> Complex(2)).should == 1
- (Complex(2) <=> Complex(3)).should == -1
- (Complex(2) <=> Complex(2)).should == 0
+ it "returns 0, 1, or -1 if self and argument do not have imaginary part" do
+ (Complex(5) <=> Complex(2)).should == 1
+ (Complex(2) <=> Complex(3)).should == -1
+ (Complex(2) <=> Complex(2)).should == 0
- (Complex(5) <=> 2).should == 1
- (Complex(2) <=> 3).should == -1
- (Complex(2) <=> 2).should == 0
- end
+ (Complex(5) <=> 2).should == 1
+ (Complex(2) <=> 3).should == -1
+ (Complex(2) <=> 2).should == 0
end
end
diff --git a/spec/ruby/core/dir/children_spec.rb b/spec/ruby/core/dir/children_spec.rb
index 986c8f38c0..03698cc246 100644
--- a/spec/ruby/core/dir/children_spec.rb
+++ b/spec/ruby/core/dir/children_spec.rb
@@ -105,14 +105,6 @@ describe "Dir#children" do
dirs.each { |d| d.encoding.should == Encoding::UTF_8 }
end
- ruby_version_is ""..."2.7" do
- it "accepts nil options" do
- @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", nil)
- dirs = @dir.to_a.sort
- dirs.each { |d| d.encoding.should == Encoding.find("filesystem") }
- end
- end
-
it "returns children encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the
# children that are not ascii_only? will be BINARY encoded.
diff --git a/spec/ruby/core/dir/each_child_spec.rb b/spec/ruby/core/dir/each_child_spec.rb
index f7980991e5..520186e79e 100644
--- a/spec/ruby/core/dir/each_child_spec.rb
+++ b/spec/ruby/core/dir/each_child_spec.rb
@@ -15,13 +15,6 @@ describe "Dir.each_child" do
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
end
- ruby_version_is ""..."2.7" do
- it "accepts nil options" do
- dirs = Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
- dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
- end
- end
-
it "yields all names in an existing directory to the provided block" do
a, b = [], []
diff --git a/spec/ruby/core/dir/entries_spec.rb b/spec/ruby/core/dir/entries_spec.rb
index 9aa58657db..91c30fccae 100644
--- a/spec/ruby/core/dir/entries_spec.rb
+++ b/spec/ruby/core/dir/entries_spec.rb
@@ -40,13 +40,6 @@ describe "Dir.entries" do
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
end
- ruby_version_is ""..."2.7" do
- it "accepts nil options" do
- dirs = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
- dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
- end
- end
-
it "returns entries encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the
# entries that are not ascii_only? will be BINARY encoded.
diff --git a/spec/ruby/core/dir/foreach_spec.rb b/spec/ruby/core/dir/foreach_spec.rb
index 85e8c61fd6..b0e18afeb5 100644
--- a/spec/ruby/core/dir/foreach_spec.rb
+++ b/spec/ruby/core/dir/foreach_spec.rb
@@ -51,13 +51,6 @@ describe "Dir.foreach" do
end
end
- ruby_version_is ""..."2.7" do
- it "accepts nil options" do
- dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
- dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
- end
- end
-
describe "when no block is given" do
it "returns an Enumerator" do
Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator)
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb
index a38ff8aa68..60d4a8c97a 100644
--- a/spec/ruby/core/dir/shared/glob.rb
+++ b/spec/ruby/core/dir/shared/glob.rb
@@ -23,19 +23,8 @@ describe :dir_glob, shared: true do
Dir.send(@method, obj).should == %w[file_one.ext]
end
- ruby_version_is ""..."2.7" do
- it "splits the string on \\0 if there is only one string given and warns" do
- -> {
- Dir.send(@method, "file_o*\0file_t*").should ==
- %w!file_one.ext file_two.ext!
- }.should complain(/warning: use glob patterns list instead of nul-separated patterns/)
- end
- end
-
- ruby_version_is "2.7" do
- it "raises an ArgumentError if the string contains \\0" do
- -> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
- end
+ it "raises an ArgumentError if the string contains \\0" do
+ -> {Dir.send(@method, "file_o*\0file_t*")}.should raise_error ArgumentError, /nul-separated/
end
ruby_version_is "3.0" do
diff --git a/spec/ruby/core/encoding/list_spec.rb b/spec/ruby/core/encoding/list_spec.rb
index 8efd94ab9c..bd3d5b7bc0 100644
--- a/spec/ruby/core/encoding/list_spec.rb
+++ b/spec/ruby/core/encoding/list_spec.rb
@@ -40,10 +40,8 @@ describe "Encoding.list" do
Encoding.list.should.include?(Encoding::UTF_8)
end
- ruby_version_is "2.7" do
- it 'includes CESU-8 encoding' do
- Encoding.list.should.include?(Encoding::CESU_8)
- end
+ it 'includes CESU-8 encoding' do
+ Encoding.list.should.include?(Encoding::CESU_8)
end
# TODO: Find example that illustrates this
diff --git a/spec/ruby/core/enumerable/filter_map_spec.rb b/spec/ruby/core/enumerable/filter_map_spec.rb
index 31acc277b4..aa4894230b 100644
--- a/spec/ruby/core/enumerable/filter_map_spec.rb
+++ b/spec/ruby/core/enumerable/filter_map_spec.rb
@@ -1,26 +1,24 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is '2.7' do
- describe 'Enumerable#filter_map' do
- before :each do
- @numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
- end
+describe 'Enumerable#filter_map' do
+ before :each do
+ @numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
+ end
- it 'returns an empty array if there are no elements' do
- EnumerableSpecs::Empty.new.filter_map { true }.should == []
- end
+ it 'returns an empty array if there are no elements' do
+ EnumerableSpecs::Empty.new.filter_map { true }.should == []
+ end
- it 'returns an array with truthy results of passing each element to block' do
- @numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
- @numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
- @numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
- @numerous.filter_map { false }.should == []
- @numerous.filter_map { nil }.should == []
- end
+ it 'returns an array with truthy results of passing each element to block' do
+ @numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
+ @numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
+ @numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
+ @numerous.filter_map { false }.should == []
+ @numerous.filter_map { nil }.should == []
+ end
- it 'returns an enumerator when no block given' do
- @numerous.filter_map.should be_an_instance_of(Enumerator)
- end
+ it 'returns an enumerator when no block given' do
+ @numerous.filter_map.should be_an_instance_of(Enumerator)
end
end
diff --git a/spec/ruby/core/enumerable/group_by_spec.rb b/spec/ruby/core/enumerable/group_by_spec.rb
index 52b5a68d64..4fd1603819 100644
--- a/spec/ruby/core/enumerable/group_by_spec.rb
+++ b/spec/ruby/core/enumerable/group_by_spec.rb
@@ -33,15 +33,5 @@ describe "Enumerable#group_by" do
[3, 4, 5] => [[3, 4, 5]] }
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted hash if self is tainted" do
- EnumerableSpecs::Empty.new.taint.group_by {}.tainted?.should be_true
- end
-
- it "returns an untrusted hash if self is untrusted" do
- EnumerableSpecs::Empty.new.untrust.group_by {}.untrusted?.should be_true
- end
- end
-
it_behaves_like :enumerable_enumeratorized_with_origin_size, :group_by
end
diff --git a/spec/ruby/core/enumerable/shared/entries.rb b/spec/ruby/core/enumerable/shared/entries.rb
index 590ce73bcf..e32eb23d2a 100644
--- a/spec/ruby/core/enumerable/shared/entries.rb
+++ b/spec/ruby/core/enumerable/shared/entries.rb
@@ -13,14 +13,4 @@ describe :enumerable_entries, shared: true do
count.send(@method, :hello, "world").should == [1, 2, 3]
count.arguments_passed.should == [:hello, "world"]
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted array if self is tainted" do
- EnumerableSpecs::Empty.new.taint.send(@method).tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- EnumerableSpecs::Empty.new.untrust.send(@method).untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/enumerable/shared/inject.rb b/spec/ruby/core/enumerable/shared/inject.rb
index e59b82b02e..c5907f92d8 100644
--- a/spec/ruby/core/enumerable/shared/inject.rb
+++ b/spec/ruby/core/enumerable/shared/inject.rb
@@ -17,7 +17,8 @@ describe :enumerable_inject, shared: true do
end
it "ignores the block if two arguments" do
- EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-){ raise "we never get here"}.should == 4
+ EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-) { raise "we never get here"}.should == 4
+ [].send(@method, 3, :+) { raise "we never get here"}.should == 3
end
it "can take a symbol argument" do
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb
index 92aac507ff..f09a8f533a 100644
--- a/spec/ruby/core/enumerable/tally_spec.rb
+++ b/spec/ruby/core/enumerable/tally_spec.rb
@@ -1,36 +1,34 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "Enumerable#tally" do
- before :each do
- ScratchPad.record []
- end
+describe "Enumerable#tally" do
+ before :each do
+ ScratchPad.record []
+ end
- it "returns a hash with counts according to the value" do
- enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
- enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
- end
+ it "returns a hash with counts according to the value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
- it "returns a hash without default" do
- hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
- hash.default_proc.should be_nil
- hash.default.should be_nil
- end
+ it "returns a hash without default" do
+ hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
+ hash.default_proc.should be_nil
+ hash.default.should be_nil
+ end
- it "returns an empty hash for empty enumerables" do
- EnumerableSpecs::Empty.new.tally.should == {}
- end
+ it "returns an empty hash for empty enumerables" do
+ EnumerableSpecs::Empty.new.tally.should == {}
+ end
- it "counts values as gathered array when yielded with multiple arguments" do
- EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
- end
+ it "counts values as gathered array when yielded with multiple arguments" do
+ EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
+ end
- it "does not call given block" do
- enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
- enum.tally { |v| ScratchPad << v }
- ScratchPad.recorded.should == []
- end
+ it "does not call given block" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally { |v| ScratchPad << v }
+ ScratchPad.recorded.should == []
end
end
diff --git a/spec/ruby/core/enumerable/uniq_spec.rb b/spec/ruby/core/enumerable/uniq_spec.rb
index e58dd36366..a1ed44796f 100644
--- a/spec/ruby/core/enumerable/uniq_spec.rb
+++ b/spec/ruby/core/enumerable/uniq_spec.rb
@@ -31,76 +31,32 @@ describe 'Enumerable#uniq' do
[x, y].to_enum.uniq.should == [x, y]
end
- ruby_version_is '2.7' do
- 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)
- false
- end
-
- obj
- end
-
- a.uniq.should == a
+ 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)
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- true
- end
-
- obj
+ def obj.eql?(o)
+ false
end
- a.to_enum.uniq.size.should == 1
+ obj
end
- end
- ruby_version_is ''...'2.7' do
- 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
-
- obj
- end
-
- a.uniq.should == a
- a[0].should.tainted?
- a[1].should.tainted?
+ a.uniq.should == a
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
+ 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
- true
- end
-
- obj
+ def obj.eql?(o)
+ true
end
- a.to_enum.uniq.size.should == 1
- a[0].should.tainted?
- a[1].should.tainted?
+ obj
end
+
+ a.to_enum.uniq.size.should == 1
end
context 'when yielded with multiple arguments' do
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb
index 1837a4f246..bd243fa0b5 100644
--- a/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb
@@ -7,12 +7,10 @@ describe "Enumerator::ArithmeticSequence#begin" do
(1...10).step.begin.should == 1
end
- ruby_version_is "2.7" do
- context "with beginless" do
- it "returns nil as begin of the sequence" do
- eval("(..10).step(1)").begin.should == nil
- eval("(...10).step(1)").begin.should == nil
- end
+ context "with beginless" do
+ it "returns nil as begin of the sequence" do
+ (..10).step(1).begin.should == nil
+ (...10).step(1).begin.should == nil
end
end
end
diff --git a/spec/ruby/core/enumerator/lazy/eager_spec.rb b/spec/ruby/core/enumerator/lazy/eager_spec.rb
index 30ba2dfe0e..592da4fd8c 100644
--- a/spec/ruby/core/enumerator/lazy/eager_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/eager_spec.rb
@@ -1,29 +1,27 @@
require_relative '../../../spec_helper'
-ruby_version_is "2.7" do
- describe "Enumerator::Lazy#eager" do
- it "returns a non-lazy Enumerator converted from the lazy enumerator" do
- enum = [1, 2, 3].lazy
+describe "Enumerator::Lazy#eager" do
+ it "returns a non-lazy Enumerator converted from the lazy enumerator" do
+ enum = [1, 2, 3].lazy
- enum.class.should == Enumerator::Lazy
- enum.eager.class.should == Enumerator
- end
+ enum.class.should == Enumerator::Lazy
+ enum.eager.class.should == Enumerator
+ end
- it "does not enumerate an enumerator" do
- ScratchPad.record []
+ it "does not enumerate an enumerator" do
+ ScratchPad.record []
- sequence = [1, 2, 3]
- enum_lazy = Enumerator::Lazy.new(sequence) do |yielder, value|
- yielder << value
- ScratchPad << value
- end
+ sequence = [1, 2, 3]
+ enum_lazy = Enumerator::Lazy.new(sequence) do |yielder, value|
+ yielder << value
+ ScratchPad << value
+ end
- ScratchPad.recorded.should == []
- enum = enum_lazy.eager
- ScratchPad.recorded.should == []
+ ScratchPad.recorded.should == []
+ enum = enum_lazy.eager
+ ScratchPad.recorded.should == []
- enum.map { |i| i }.should == [1, 2, 3]
- ScratchPad.recorded.should == [1, 2, 3]
- end
+ enum.map { |i| i }.should == [1, 2, 3]
+ ScratchPad.recorded.should == [1, 2, 3]
end
end
diff --git a/spec/ruby/core/enumerator/lazy/filter_map_spec.rb b/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
index 3480af0865..99dd59cebe 100644
--- a/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
@@ -3,14 +3,12 @@
require_relative '../../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "Enumerator::Lazy#filter_map" do
- it "maps only truthy results" do
- (1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7]
- end
+describe "Enumerator::Lazy#filter_map" do
+ it "maps only truthy results" do
+ (1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7]
+ end
- it "does not map false results" do
- (1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7]
- end
+ it "does not map false results" do
+ (1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7]
end
end
diff --git a/spec/ruby/core/enumerator/lazy/with_index_spec.rb b/spec/ruby/core/enumerator/lazy/with_index_spec.rb
index b6dbe554d9..a6b5c38777 100644
--- a/spec/ruby/core/enumerator/lazy/with_index_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/with_index_spec.rb
@@ -3,36 +3,34 @@
require_relative '../../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "Enumerator::Lazy#with_index" do
- it "enumerates with an index" do
- (0..Float::INFINITY).lazy.with_index.map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
- end
+describe "Enumerator::Lazy#with_index" do
+ it "enumerates with an index" do
+ (0..Float::INFINITY).lazy.with_index.map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
+ end
- it "enumerates with an index starting at a given offset" do
- (0..Float::INFINITY).lazy.with_index(3).map { |i, idx| [i, idx] }.first(3).should == [[0, 3], [1, 4], [2, 5]]
- end
+ it "enumerates with an index starting at a given offset" do
+ (0..Float::INFINITY).lazy.with_index(3).map { |i, idx| [i, idx] }.first(3).should == [[0, 3], [1, 4], [2, 5]]
+ end
- it "enumerates with an index starting at 0 when offset is nil" do
- (0..Float::INFINITY).lazy.with_index(nil).map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
- end
+ it "enumerates with an index starting at 0 when offset is nil" do
+ (0..Float::INFINITY).lazy.with_index(nil).map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
+ end
- it "raises TypeError when offset does not convert to Integer" do
- -> { (0..Float::INFINITY).lazy.with_index(false).map { |i, idx| i }.first(3) }.should raise_error(TypeError)
- end
+ it "raises TypeError when offset does not convert to Integer" do
+ -> { (0..Float::INFINITY).lazy.with_index(false).map { |i, idx| i }.first(3) }.should raise_error(TypeError)
+ end
- it "enumerates with a given block" do
- result = []
- (0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3)
- result.should == [[0,0],[2,1],[4,2]]
- end
+ it "enumerates with a given block" do
+ result = []
+ (0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3)
+ result.should == [[0,0],[2,1],[4,2]]
+ end
- it "resets after a new call to each" do
- enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] }
- result = []
- enum.each { |i, idx| result << [i, idx] }
- enum.each { |i, idx| result << [i, idx] }
- result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]]
- end
+ it "resets after a new call to each" do
+ enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] }
+ result = []
+ enum.each { |i, idx| result << [i, idx] }
+ enum.each { |i, idx| result << [i, idx] }
+ result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]]
end
end
diff --git a/spec/ruby/core/enumerator/new_spec.rb b/spec/ruby/core/enumerator/new_spec.rb
index 5cc0b3ff2e..c439469525 100644
--- a/spec/ruby/core/enumerator/new_spec.rb
+++ b/spec/ruby/core/enumerator/new_spec.rb
@@ -77,14 +77,12 @@ describe "Enumerator.new" do
enum.take(3).should == [1, 2, 3]
end
- ruby_version_is "2.7" do
- it "defines iteration with block, yielder argument and treating it as a proc" do
- enum = Enumerator.new do |yielder|
- "a\nb\nc".each_line(&yielder)
- end
-
- enum.to_a.should == ["a\n", "b\n", "c"]
+ it "defines iteration with block, yielder argument and treating it as a proc" do
+ enum = Enumerator.new do |yielder|
+ "a\nb\nc".each_line(&yielder)
end
+
+ enum.to_a.should == ["a\n", "b\n", "c"]
end
describe 'yielded values' do
diff --git a/spec/ruby/core/enumerator/produce_spec.rb b/spec/ruby/core/enumerator/produce_spec.rb
index f6f1dcd429..c69fb49303 100644
--- a/spec/ruby/core/enumerator/produce_spec.rb
+++ b/spec/ruby/core/enumerator/produce_spec.rb
@@ -1,36 +1,34 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Enumerator.produce" do
- it "creates an infinite enumerator" do
- enum = Enumerator.produce(0) { |prev| prev + 1 }
- enum.take(5).should == [0, 1, 2, 3, 4]
- end
-
- it "terminates iteration when block raises StopIteration exception" do
- enum = Enumerator.produce(0) do | prev|
- raise StopIteration if prev >= 2
- prev + 1
- end
+describe "Enumerator.produce" do
+ it "creates an infinite enumerator" do
+ enum = Enumerator.produce(0) { |prev| prev + 1 }
+ enum.take(5).should == [0, 1, 2, 3, 4]
+ end
- enum.to_a.should == [0, 1, 2]
+ it "terminates iteration when block raises StopIteration exception" do
+ enum = Enumerator.produce(0) do | prev|
+ raise StopIteration if prev >= 2
+ prev + 1
end
- context "when initial value skipped" do
- it "uses nil instead" do
- ScratchPad.record []
- enum = Enumerator.produce { |prev| ScratchPad << prev; (prev || 0) + 1 }
+ enum.to_a.should == [0, 1, 2]
+ end
+
+ context "when initial value skipped" do
+ it "uses nil instead" do
+ ScratchPad.record []
+ enum = Enumerator.produce { |prev| ScratchPad << prev; (prev || 0) + 1 }
- enum.take(3).should == [1, 2, 3]
- ScratchPad.recorded.should == [nil, 1, 2]
- end
+ enum.take(3).should == [1, 2, 3]
+ ScratchPad.recorded.should == [nil, 1, 2]
+ end
- it "starts enumerable from result of first block call" do
- array = "a\nb\nc\nd".lines
- lines = Enumerator.produce { array.shift }.take_while { |s| s }
+ it "starts enumerable from result of first block call" do
+ array = "a\nb\nc\nd".lines
+ lines = Enumerator.produce { array.shift }.take_while { |s| s }
- lines.should == ["a\n", "b\n", "c\n", "d"]
- end
+ lines.should == ["a\n", "b\n", "c\n", "d"]
end
end
end
diff --git a/spec/ruby/core/enumerator/yielder/to_proc_spec.rb b/spec/ruby/core/enumerator/yielder/to_proc_spec.rb
index 0ed1645853..1d3681ab50 100644
--- a/spec/ruby/core/enumerator/yielder/to_proc_spec.rb
+++ b/spec/ruby/core/enumerator/yielder/to_proc_spec.rb
@@ -1,18 +1,16 @@
require_relative '../../../spec_helper'
-ruby_version_is "2.7" do
- describe "Enumerator::Yielder#to_proc" do
- it "returns a Proc object that takes an argument and yields it to the block" do
- ScratchPad.record []
- y = Enumerator::Yielder.new { |*args| ScratchPad << args; "foobar" }
+describe "Enumerator::Yielder#to_proc" do
+ it "returns a Proc object that takes an argument and yields it to the block" do
+ ScratchPad.record []
+ y = Enumerator::Yielder.new { |*args| ScratchPad << args; "foobar" }
- callable = y.to_proc
- callable.class.should == Proc
+ callable = y.to_proc
+ callable.class.should == Proc
- result = callable.call(1, 2)
- ScratchPad.recorded.should == [[1, 2]]
+ result = callable.call(1, 2)
+ ScratchPad.recorded.should == [[1, 2]]
- result.should == "foobar"
- end
+ result.should == "foobar"
end
end
diff --git a/spec/ruby/core/env/merge_spec.rb b/spec/ruby/core/env/merge_spec.rb
index b418cd11f4..f10662cf79 100644
--- a/spec/ruby/core/env/merge_spec.rb
+++ b/spec/ruby/core/env/merge_spec.rb
@@ -1,8 +1,6 @@
require_relative '../../spec_helper'
require_relative 'shared/update'
-ruby_version_is "2.7" do
- describe "ENV.merge!" do
- it_behaves_like :env_update, :merge!
- end
+describe "ENV.merge!" do
+ it_behaves_like :env_update, :merge!
end
diff --git a/spec/ruby/core/env/shared/update.rb b/spec/ruby/core/env/shared/update.rb
index 129a56544c..2746e86545 100644
--- a/spec/ruby/core/env/shared/update.rb
+++ b/spec/ruby/core/env/shared/update.rb
@@ -39,23 +39,21 @@ describe :env_update, shared: true do
ENV["bar"].should == "5"
end
- ruby_version_is "2.7" do
- # BUG: https://bugs.ruby-lang.org/issues/16192
- it "does not evaluate the block when the name is new" do
- ENV.delete("bar")
- ENV.send @method, {"foo" => "0"}
- ENV.send(@method, "bar" => "1") { |key, old, new| fail "Should not get here" }
- ENV["bar"].should == "1"
- end
+ # BUG: https://bugs.ruby-lang.org/issues/16192
+ it "does not evaluate the block when the name is new" do
+ ENV.delete("bar")
+ ENV.send @method, {"foo" => "0"}
+ ENV.send(@method, "bar" => "1") { |key, old, new| fail "Should not get here" }
+ ENV["bar"].should == "1"
+ end
- # BUG: https://bugs.ruby-lang.org/issues/16192
- it "does not use the block's return value as the value when the name is new" do
- ENV.delete("bar")
- ENV.send @method, {"foo" => "0"}
- ENV.send(@method, "bar" => "1") { |key, old, new| "Should not use this value" }
- ENV["foo"].should == "0"
- ENV["bar"].should == "1"
- end
+ # BUG: https://bugs.ruby-lang.org/issues/16192
+ it "does not use the block's return value as the value when the name is new" do
+ ENV.delete("bar")
+ ENV.send @method, {"foo" => "0"}
+ ENV.send(@method, "bar" => "1") { |key, old, new| "Should not use this value" }
+ ENV["foo"].should == "0"
+ ENV["bar"].should == "1"
end
it "returns ENV when block given" do
diff --git a/spec/ruby/core/exception/frozen_error_spec.rb b/spec/ruby/core/exception/frozen_error_spec.rb
index f27b33295c..2efdc239d8 100644
--- a/spec/ruby/core/exception/frozen_error_spec.rb
+++ b/spec/ruby/core/exception/frozen_error_spec.rb
@@ -1,26 +1,22 @@
require_relative '../../spec_helper'
describe "FrozenError.new" do
- ruby_version_is "2.7" do
- it "should take optional receiver argument" do
- o = Object.new
- FrozenError.new("msg", receiver: o).receiver.should equal(o)
- end
+ it "should take optional receiver argument" do
+ o = Object.new
+ FrozenError.new("msg", receiver: o).receiver.should equal(o)
end
end
describe "FrozenError#receiver" do
- ruby_version_is "2.7" do
- it "should return frozen object that modification was attempted on" do
- o = Object.new.freeze
- begin
- def o.x; end
- rescue => e
- e.should be_kind_of(FrozenError)
- e.receiver.should equal(o)
- else
- raise
- end
+ it "should return frozen object that modification was attempted on" do
+ o = Object.new.freeze
+ begin
+ def o.x; end
+ rescue => e
+ e.should be_kind_of(FrozenError)
+ e.receiver.should equal(o)
+ else
+ raise
end
end
end
diff --git a/spec/ruby/core/false/to_s_spec.rb b/spec/ruby/core/false/to_s_spec.rb
index 4cae278891..62f67f6f55 100644
--- a/spec/ruby/core/false/to_s_spec.rb
+++ b/spec/ruby/core/false/to_s_spec.rb
@@ -5,13 +5,11 @@ describe "FalseClass#to_s" do
false.to_s.should == "false"
end
- ruby_version_is "2.7" do
- it "returns a frozen string" do
- false.to_s.should.frozen?
- end
+ it "returns a frozen string" do
+ false.to_s.should.frozen?
+ end
- it "always returns the same string" do
- false.to_s.should equal(false.to_s)
- end
+ it "always returns the same string" do
+ false.to_s.should equal(false.to_s)
end
end
diff --git a/spec/ruby/core/fiber/raise_spec.rb b/spec/ruby/core/fiber/raise_spec.rb
index 2a465c8bfa..09c4c1b524 100644
--- a/spec/ruby/core/fiber/raise_spec.rb
+++ b/spec/ruby/core/fiber/raise_spec.rb
@@ -2,101 +2,99 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative '../../shared/kernel/raise'
-ruby_version_is "2.7" do
- describe "Fiber#raise" do
- it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
+describe "Fiber#raise" do
+ it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
+end
+
+describe "Fiber#raise" do
+ it 'raises RuntimeError by default' do
+ -> { FiberSpecs::NewFiberToRaise.raise }.should raise_error(RuntimeError)
end
- describe "Fiber#raise" do
- it 'raises RuntimeError by default' do
- -> { FiberSpecs::NewFiberToRaise.raise }.should raise_error(RuntimeError)
- end
+ it "raises FiberError if Fiber is not born" do
+ fiber = Fiber.new { true }
+ -> { fiber.raise }.should raise_error(FiberError, "cannot raise exception on unborn fiber")
+ end
- it "raises FiberError if Fiber is not born" do
- fiber = Fiber.new { true }
- -> { fiber.raise }.should raise_error(FiberError, "cannot raise exception on unborn fiber")
- end
+ it "raises FiberError if Fiber is dead" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ -> { fiber.raise }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
+ end
- it "raises FiberError if Fiber is dead" do
- fiber = Fiber.new { true }
- fiber.resume
- -> { fiber.raise }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
- end
+ it 'accepts error class' do
+ -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError }.should raise_error(FiberSpecs::CustomError)
+ end
- it 'accepts error class' do
- -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError }.should raise_error(FiberSpecs::CustomError)
- end
+ it 'accepts error message' do
+ -> { FiberSpecs::NewFiberToRaise.raise "error message" }.should raise_error(RuntimeError, "error message")
+ end
- it 'accepts error message' do
- -> { FiberSpecs::NewFiberToRaise.raise "error message" }.should raise_error(RuntimeError, "error message")
- end
+ it 'does not accept array of backtrace information only' do
+ -> { FiberSpecs::NewFiberToRaise.raise ['foo'] }.should raise_error(TypeError)
+ end
- it 'does not accept array of backtrace information only' do
- -> { FiberSpecs::NewFiberToRaise.raise ['foo'] }.should raise_error(TypeError)
- end
+ it 'does not accept integer' do
+ -> { FiberSpecs::NewFiberToRaise.raise 100 }.should raise_error(TypeError)
+ end
- it 'does not accept integer' do
- -> { FiberSpecs::NewFiberToRaise.raise 100 }.should raise_error(TypeError)
- end
+ it 'accepts error class with error message' do
+ -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error' }.should raise_error(FiberSpecs::CustomError, 'test error')
+ end
- it 'accepts error class with error message' do
- -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error' }.should raise_error(FiberSpecs::CustomError, 'test error')
- end
+ it 'accepts error class with with error message and backtrace information' do
+ -> {
+ FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error', ['foo', 'boo']
+ }.should raise_error(FiberSpecs::CustomError) { |e|
+ e.message.should == 'test error'
+ e.backtrace.should == ['foo', 'boo']
+ }
+ end
- it 'accepts error class with with error message and backtrace information' do
- -> {
- FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error', ['foo', 'boo']
- }.should raise_error(FiberSpecs::CustomError) { |e|
- e.message.should == 'test error'
- e.backtrace.should == ['foo', 'boo']
- }
- end
+ it 'does not accept only error message and backtrace information' do
+ -> { FiberSpecs::NewFiberToRaise.raise 'test error', ['foo', 'boo'] }.should raise_error(TypeError)
+ end
- it 'does not accept only error message and backtrace information' do
- -> { FiberSpecs::NewFiberToRaise.raise 'test error', ['foo', 'boo'] }.should raise_error(TypeError)
- end
+ it "raises a FiberError if invoked from a different Thread" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+ Thread.new do
+ -> {
+ fiber.raise
+ }.should raise_error(FiberError, "fiber called across threads")
+ end.join
+ end
- it "raises a FiberError if invoked from a different Thread" do
- fiber = Fiber.new { Fiber.yield }
- fiber.resume
- Thread.new do
- -> {
- fiber.raise
- }.should raise_error(FiberError, "fiber called across threads")
- end.join
- end
+ it "kills Fiber" do
+ fiber = Fiber.new { Fiber.yield :first; :second }
+ fiber.resume
+ -> { fiber.raise }.should raise_error
+ -> { fiber.resume }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
+ end
- it "kills Fiber" do
- fiber = Fiber.new { Fiber.yield :first; :second }
- fiber.resume
- -> { fiber.raise }.should raise_error
- -> { fiber.resume }.should raise_error(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
+ it "returns to calling fiber after raise" do
+ fiber_one = Fiber.new do
+ Fiber.yield :yield_one
+ :unreachable
end
- it "returns to calling fiber after raise" do
- fiber_one = Fiber.new do
- Fiber.yield :yield_one
- :unreachable
- end
-
- fiber_two = Fiber.new do
- results = []
- results << fiber_one.resume
- begin
- fiber_one.raise
- rescue
- results << :rescued
- end
- results
+ fiber_two = Fiber.new do
+ results = []
+ results << fiber_one.resume
+ begin
+ fiber_one.raise
+ rescue
+ results << :rescued
end
-
- fiber_two.resume.should == [:yield_one, :rescued]
+ results
end
- end
+ fiber_two.resume.should == [:yield_one, :rescued]
+ end
end
-ruby_version_is "2.7"..."3.0" do
+
+ruby_version_is ""..."3.0" do
describe "Fiber#raise" do
it "raises a FiberError if invoked on a transferring Fiber" do
require "fiber"
diff --git a/spec/ruby/core/file/absolute_path_spec.rb b/spec/ruby/core/file/absolute_path_spec.rb
index 9f39923472..e35c80ec3c 100644
--- a/spec/ruby/core/file/absolute_path_spec.rb
+++ b/spec/ruby/core/file/absolute_path_spec.rb
@@ -1,54 +1,52 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "File.absolute_path?" do
- before :each do
- @abs = File.expand_path(__FILE__)
- end
+describe "File.absolute_path?" do
+ before :each do
+ @abs = File.expand_path(__FILE__)
+ end
- it "returns true if it's an absolute pathname" do
- File.absolute_path?(@abs).should be_true
- end
+ it "returns true if it's an absolute pathname" do
+ File.absolute_path?(@abs).should be_true
+ end
- it "returns false if it's a relative path" do
- File.absolute_path?(File.basename(__FILE__)).should be_false
- end
+ it "returns false if it's a relative path" do
+ File.absolute_path?(File.basename(__FILE__)).should be_false
+ end
- it "returns false if it's a tricky relative path" do
- File.absolute_path?("C:foo\\bar").should be_false
- end
+ it "returns false if it's a tricky relative path" do
+ File.absolute_path?("C:foo\\bar").should be_false
+ end
- it "does not expand '~' to a home directory." do
- File.absolute_path?('~').should be_false
- end
+ it "does not expand '~' to a home directory." do
+ File.absolute_path?('~').should be_false
+ end
- it "does not expand '~user' to a home directory." do
- path = File.dirname(@abs)
- Dir.chdir(path) do
- File.absolute_path?('~user').should be_false
- end
+ it "does not expand '~user' to a home directory." do
+ path = File.dirname(@abs)
+ Dir.chdir(path) do
+ File.absolute_path?('~user').should be_false
end
+ end
- it "calls #to_path on its argument" do
- mock = mock_to_path(File.expand_path(__FILE__))
+ it "calls #to_path on its argument" do
+ mock = mock_to_path(File.expand_path(__FILE__))
- File.absolute_path?(mock).should be_true
- end
+ File.absolute_path?(mock).should be_true
+ end
- platform_is_not :windows do
- it "takes into consideration the platform's root" do
- File.absolute_path?("C:\\foo\\bar").should be_false
- File.absolute_path?("C:/foo/bar").should be_false
- File.absolute_path?("/foo/bar\\baz").should be_true
- end
+ platform_is_not :windows do
+ it "takes into consideration the platform's root" do
+ File.absolute_path?("C:\\foo\\bar").should be_false
+ File.absolute_path?("C:/foo/bar").should be_false
+ File.absolute_path?("/foo/bar\\baz").should be_true
end
+ end
- platform_is :windows do
- it "takes into consideration the platform path separator(s)" do
- File.absolute_path?("C:\\foo\\bar").should be_true
- File.absolute_path?("C:/foo/bar").should be_true
- File.absolute_path?("/foo/bar\\baz").should be_false
- end
+ platform_is :windows do
+ it "takes into consideration the platform path separator(s)" do
+ File.absolute_path?("C:\\foo\\bar").should be_true
+ File.absolute_path?("C:/foo/bar").should be_true
+ File.absolute_path?("/foo/bar\\baz").should be_false
end
end
end
diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb
index e182ed44f2..d20cf813d9 100644
--- a/spec/ruby/core/file/extname_spec.rb
+++ b/spec/ruby/core/file/extname_spec.rb
@@ -33,14 +33,14 @@ describe "File.extname" do
end
describe "for a filename ending with a dot" do
- guard -> { platform_is :windows or ruby_version_is ""..."2.7" } do
+ platform_is :windows do
it "returns ''" do
File.extname(".foo.").should == ""
File.extname("foo.").should == ""
end
end
- guard -> { platform_is_not :windows and ruby_version_is "2.7" } do
+ platform_is_not :windows do
it "returns '.'" do
File.extname(".foo.").should == "."
File.extname("foo.").should == "."
diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb
index ad67274802..8fba47958f 100644
--- a/spec/ruby/core/hash/constructor_spec.rb
+++ b/spec/ruby/core/hash/constructor_spec.rb
@@ -42,26 +42,13 @@ describe "Hash.[]" do
Hash[ary].should == { a: :b }
end
- ruby_version_is "" ... "2.7" do
- it "ignores elements that are not arrays" do
- -> {
- Hash[[:a]].should == {}
- }.should complain(/ignoring wrong elements/)
- -> {
- Hash[[:nil]].should == {}
- }.should complain(/ignoring wrong elements/)
- end
- end
-
- ruby_version_is "2.7" do
- it "raises for elements that are not arrays" do
- -> {
- Hash[[:a]].should == {}
- }.should raise_error(ArgumentError)
- -> {
- Hash[[:nil]].should == {}
- }.should raise_error(ArgumentError)
- end
+ it "raises for elements that are not arrays" do
+ -> {
+ Hash[[:a]].should == {}
+ }.should raise_error(ArgumentError)
+ -> {
+ Hash[[:nil]].should == {}
+ }.should raise_error(ArgumentError)
end
it "raises an ArgumentError for arrays of more than 2 elements" do
diff --git a/spec/ruby/core/hash/deconstruct_keys_spec.rb b/spec/ruby/core/hash/deconstruct_keys_spec.rb
index b265732616..bbcd8932e5 100644
--- a/spec/ruby/core/hash/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/hash/deconstruct_keys_spec.rb
@@ -1,25 +1,23 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Hash#deconstruct_keys" do
- it "returns self" do
- hash = {a: 1, b: 2}
+describe "Hash#deconstruct_keys" do
+ it "returns self" do
+ hash = {a: 1, b: 2}
- hash.deconstruct_keys([:a, :b]).should equal hash
- end
+ hash.deconstruct_keys([:a, :b]).should equal hash
+ end
- it "requires one argument" do
- -> {
- {a: 1}.deconstruct_keys
- }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
- end
+ it "requires one argument" do
+ -> {
+ {a: 1}.deconstruct_keys
+ }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
- it "ignores argument" do
- hash = {a: 1, b: 2}
+ it "ignores argument" do
+ hash = {a: 1, b: 2}
- hash.deconstruct_keys([:a]).should == {a: 1, b: 2}
- hash.deconstruct_keys(0 ).should == {a: 1, b: 2}
- hash.deconstruct_keys('' ).should == {a: 1, b: 2}
- end
+ hash.deconstruct_keys([:a]).should == {a: 1, b: 2}
+ hash.deconstruct_keys(0 ).should == {a: 1, b: 2}
+ hash.deconstruct_keys('' ).should == {a: 1, b: 2}
end
end
diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb
index 397000ab67..dd8e817237 100644
--- a/spec/ruby/core/hash/reject_spec.rb
+++ b/spec/ruby/core/hash/reject_spec.rb
@@ -31,13 +31,6 @@ describe "Hash#reject" do
HashSpecs::MyHash[1 => 2, 3 => 4].reject { false }.should be_kind_of(Hash)
HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should be_kind_of(Hash)
end
-
- ruby_version_is ''...'2.7' do
- it "does not taint the resulting hash" do
- h = { a: 1 }.taint
- h.reject {false}.should_not.tainted?
- end
- end
end
it "processes entries with the same order as reject!" do
diff --git a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb
index 13e8ffe4af..e9337b9d1c 100644
--- a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb
+++ b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb
@@ -1,61 +1,59 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "Hash.ruby2_keywords_hash?" do
- it "returns false if the Hash is not a keywords Hash" do
- Hash.ruby2_keywords_hash?({}).should == false
- end
-
- it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do
- obj = Class.new {
- ruby2_keywords def m(*args)
- args.last
- end
- }.new
- Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true
- end
-
- it "raises TypeError for non-Hash" do
- -> { Hash.ruby2_keywords_hash?(nil) }.should raise_error(TypeError)
- end
- end
-
- describe "Hash.ruby2_keywords_hash" do
- it "returns a copy of a Hash and marks the copy as a keywords Hash" do
- h = {a: 1}.freeze
- kw = Hash.ruby2_keywords_hash(h)
- Hash.ruby2_keywords_hash?(h).should == false
- Hash.ruby2_keywords_hash?(kw).should == true
- kw.should == h
- end
-
- it "returns an instance of the subclass if called on an instance of a subclass of Hash" do
- h = HashSpecs::MyHash.new
- h[:a] = 1
- kw = Hash.ruby2_keywords_hash(h)
- kw.class.should == HashSpecs::MyHash
- Hash.ruby2_keywords_hash?(h).should == false
- Hash.ruby2_keywords_hash?(kw).should == true
- kw.should == h
- end
-
- it "copies instance variables" do
- h = {a: 1}
- h.instance_variable_set(:@foo, 42)
- kw = Hash.ruby2_keywords_hash(h)
- kw.instance_variable_get(:@foo).should == 42
- end
-
- it "copies the hash internals" do
- h = {a: 1}
- kw = Hash.ruby2_keywords_hash(h)
- h[:a] = 2
- kw[:a].should == 1
- end
-
- it "raises TypeError for non-Hash" do
- -> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError)
- end
+describe "Hash.ruby2_keywords_hash?" do
+ it "returns false if the Hash is not a keywords Hash" do
+ Hash.ruby2_keywords_hash?({}).should == false
+ end
+
+ it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do
+ obj = Class.new {
+ ruby2_keywords def m(*args)
+ args.last
+ end
+ }.new
+ Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true
+ end
+
+ it "raises TypeError for non-Hash" do
+ -> { Hash.ruby2_keywords_hash?(nil) }.should raise_error(TypeError)
+ end
+end
+
+describe "Hash.ruby2_keywords_hash" do
+ it "returns a copy of a Hash and marks the copy as a keywords Hash" do
+ h = {a: 1}.freeze
+ kw = Hash.ruby2_keywords_hash(h)
+ Hash.ruby2_keywords_hash?(h).should == false
+ Hash.ruby2_keywords_hash?(kw).should == true
+ kw.should == h
+ end
+
+ it "returns an instance of the subclass if called on an instance of a subclass of Hash" do
+ h = HashSpecs::MyHash.new
+ h[:a] = 1
+ kw = Hash.ruby2_keywords_hash(h)
+ kw.class.should == HashSpecs::MyHash
+ Hash.ruby2_keywords_hash?(h).should == false
+ Hash.ruby2_keywords_hash?(kw).should == true
+ kw.should == h
+ end
+
+ it "copies instance variables" do
+ h = {a: 1}
+ h.instance_variable_set(:@foo, 42)
+ kw = Hash.ruby2_keywords_hash(h)
+ kw.instance_variable_get(:@foo).should == 42
+ end
+
+ it "copies the hash internals" do
+ h = {a: 1}
+ kw = Hash.ruby2_keywords_hash(h)
+ h[:a] = 2
+ kw[:a].should == 1
+ end
+
+ it "raises TypeError for non-Hash" do
+ -> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/core/hash/shared/eql.rb b/spec/ruby/core/hash/shared/eql.rb
index e294edd764..68db49f76d 100644
--- a/spec/ruby/core/hash/shared/eql.rb
+++ b/spec/ruby/core/hash/shared/eql.rb
@@ -149,80 +149,34 @@ describe :hash_eql_additional, shared: true do
h.send(@method, HashSpecs::MyHash[h]).should be_true
end
- ruby_version_is '2.7' do
- # Why isn't this true of eql? too ?
- it "compares keys with matching hash codes via eql?" do
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- return true if self.equal?(o)
- false
- end
-
- obj
+ # Why isn't this true of eql? too ?
+ it "compares keys with matching hash codes via eql?" do
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
+
+ def obj.eql?(o)
+ return true if self.equal?(o)
+ false
end
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false
-
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- true
- end
-
- obj
- end
-
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
+ obj
end
- end
- ruby_version_is ''...'2.7' do
- # Why isn't this true of eql? too ?
- it "compares keys with matching hash codes via eql?" do
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
+ { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- def obj.eql?(o)
- return true if self.equal?(o)
- taint
- o.taint
- false
- end
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
- obj
+ def obj.eql?(o)
+ true
end
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false
- a[0].tainted?.should be_true
- a[1].tainted?.should be_true
-
- 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].send(@method, a[1]) or
- # a[1].send(@method, a[0]) so we taint both.
- taint
- o.taint
- true
- end
-
- obj
- end
-
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
- a[0].tainted?.should be_true
- a[1].tainted?.should be_true
+ obj
end
+
+ { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
end
it "compares the values in self to values in other hash" do
diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb
index c74537aed4..2db3a96583 100644
--- a/spec/ruby/core/hash/shared/to_s.rb
+++ b/spec/ruby/core/hash/shared/to_s.rb
@@ -76,18 +76,6 @@ describe :hash_to_s, shared: true do
y.send(@method).should == "{1=>{0=>{...}}}"
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if self is tainted and not empty" do
- {}.taint.send(@method).tainted?.should be_false
- { nil => nil }.taint.send(@method).tainted?.should be_true
- end
-
- it "returns an untrusted string if self is untrusted and not empty" do
- {}.untrust.send(@method).untrusted?.should be_false
- { nil => nil }.untrust.send(@method).untrusted?.should be_true
- end
- end
-
it "does not raise if inspected result is not default external encoding" do
utf_16be = mock("utf_16be")
utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
diff --git a/spec/ruby/core/hash/to_a_spec.rb b/spec/ruby/core/hash/to_a_spec.rb
index 6f6f74f73b..8b7894a2ba 100644
--- a/spec/ruby/core/hash/to_a_spec.rb
+++ b/spec/ruby/core/hash/to_a_spec.rb
@@ -27,17 +27,7 @@ describe "Hash#to_a" do
ent.should == pairs
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted array if self is tainted" do
- {}.taint.to_a.tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- {}.untrust.to_a.untrusted?.should be_true
- end
- end
-
- ruby_version_is '2.7'...'3.0' do
+ ruby_version_is ''...'3.0' do
it "returns a not tainted array if self is tainted" do
{}.taint.to_a.tainted?.should be_false
end
diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb
index a919d29f12..3e13f45480 100644
--- a/spec/ruby/core/integer/chr_spec.rb
+++ b/spec/ruby/core/integer/chr_spec.rb
@@ -245,16 +245,14 @@ describe "Integer#chr with an encoding argument" do
end
end
- ruby_version_is "2.7" do
- it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
- # see more details here https://en.wikipedia.org/wiki/CESU-8
- # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8
- 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
-
- # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair,
- # which decodes to a 4-byte UTF-8 string
- 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes
- 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80]
- end
+ it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
+ # see more details here https://en.wikipedia.org/wiki/CESU-8
+ # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8
+ 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
+
+ # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair,
+ # which decodes to a 4-byte UTF-8 string
+ 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes
+ 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80]
end
end
diff --git a/spec/ruby/core/integer/element_reference_spec.rb b/spec/ruby/core/integer/element_reference_spec.rb
index 7197ecdc03..cb7e0dc9b0 100644
--- a/spec/ruby/core/integer/element_reference_spec.rb
+++ b/spec/ruby/core/integer/element_reference_spec.rb
@@ -79,81 +79,79 @@ describe "Integer#[]" do
3[bignum_value.to_f].should == 0
end
- ruby_version_is "2.7" do
- context "when index and length passed" do
- it "returns specified number of bits from specified position" do
- 0b101001101[2, 4].should == 0b0011
- 0b101001101[2, 5].should == 0b10011
- 0b101001101[2, 7].should == 0b1010011
- end
+ context "when index and length passed" do
+ it "returns specified number of bits from specified position" do
+ 0b101001101[2, 4].should == 0b0011
+ 0b101001101[2, 5].should == 0b10011
+ 0b101001101[2, 7].should == 0b1010011
+ end
- it "ensures n[i, len] equals to (n >> i) & ((1 << len) - 1)" do
- n = 0b101001101; i = 2; len = 4
- n[i, len].should == (n >> i) & ((1 << len) - 1)
- end
+ it "ensures n[i, len] equals to (n >> i) & ((1 << len) - 1)" do
+ n = 0b101001101; i = 2; len = 4
+ n[i, len].should == (n >> i) & ((1 << len) - 1)
+ end
- it "moves start position to the most significant bits when negative index passed" do
- 0b000001[-1, 4].should == 0b10
- 0b000001[-2, 4].should == 0b100
- 0b000001[-3, 4].should == 0b1000
- end
+ it "moves start position to the most significant bits when negative index passed" do
+ 0b000001[-1, 4].should == 0b10
+ 0b000001[-2, 4].should == 0b100
+ 0b000001[-3, 4].should == 0b1000
+ end
- it "ignores negative length" do
- 0b101001101[1, -1].should == 0b10100110
- 0b101001101[2, -1].should == 0b1010011
- 0b101001101[3, -1].should == 0b101001
+ it "ignores negative length" do
+ 0b101001101[1, -1].should == 0b10100110
+ 0b101001101[2, -1].should == 0b1010011
+ 0b101001101[3, -1].should == 0b101001
- 0b101001101[3, -5].should == 0b101001
- 0b101001101[3, -15].should == 0b101001
- 0b101001101[3, -125].should == 0b101001
- end
+ 0b101001101[3, -5].should == 0b101001
+ 0b101001101[3, -15].should == 0b101001
+ 0b101001101[3, -125].should == 0b101001
end
+ end
- context "when range passed" do
- it "returns bits specified by range" do
- 0b101001101[2..5].should == 0b0011
- 0b101001101[2..6].should == 0b10011
- 0b101001101[2..8].should == 0b1010011
- end
+ context "when range passed" do
+ it "returns bits specified by range" do
+ 0b101001101[2..5].should == 0b0011
+ 0b101001101[2..6].should == 0b10011
+ 0b101001101[2..8].should == 0b1010011
+ end
- it "ensures n[i..j] equals to (n >> i) & ((1 << (j - i + 1)) - 1)" do
- n = 0b101001101; i = 2; j = 5
- n[i..j].should == (n >> i) & ((1 << (j - i + 1)) - 1)
- end
+ it "ensures n[i..j] equals to (n >> i) & ((1 << (j - i + 1)) - 1)" do
+ n = 0b101001101; i = 2; j = 5
+ n[i..j].should == (n >> i) & ((1 << (j - i + 1)) - 1)
+ end
- it "ensures n[i..] equals to (n >> i)" do
- eval("0b101001101[3..]").should == 0b101001101 >> 3
- end
+ it "ensures n[i..] equals to (n >> i)" do
+ eval("0b101001101[3..]").should == 0b101001101 >> 3
+ end
- it "moves lower boundary to the most significant bits when negative value passed" do
- 0b000001[-1, 4].should == 0b10
- 0b000001[-2, 4].should == 0b100
- 0b000001[-3, 4].should == 0b1000
- end
+ it "moves lower boundary to the most significant bits when negative value passed" do
+ 0b000001[-1, 4].should == 0b10
+ 0b000001[-2, 4].should == 0b100
+ 0b000001[-3, 4].should == 0b1000
+ end
- it "ignores upper boundary smaller than lower boundary" do
- 0b101001101[4..1].should == 0b10100
- 0b101001101[4..2].should == 0b10100
- 0b101001101[-4..-5].should == 0b1010011010000
- end
+ it "ignores upper boundary smaller than lower boundary" do
+ 0b101001101[4..1].should == 0b10100
+ 0b101001101[4..2].should == 0b10100
+ 0b101001101[-4..-5].should == 0b1010011010000
+ end
+
+ it "raises FloatDomainError if any boundary is infinity" do
+ -> { 0x0001[3..Float::INFINITY] }.should raise_error(FloatDomainError, /Infinity/)
+ -> { 0x0001[-Float::INFINITY..3] }.should raise_error(FloatDomainError, /-Infinity/)
+ end
- it "raises FloatDomainError if any boundary is infinity" do
- -> { 0x0001[3..Float::INFINITY] }.should raise_error(FloatDomainError, /Infinity/)
- -> { 0x0001[-Float::INFINITY..3] }.should raise_error(FloatDomainError, /-Infinity/)
+ context "when passed (..i)" do
+ it "returns 0 if all i bits equal 0" do
+ eval("0b10000[..1]").should == 0
+ eval("0b10000[..2]").should == 0
+ eval("0b10000[..3]").should == 0
end
- context "when passed (..i)" do
- it "returns 0 if all i bits equal 0" do
- eval("0b10000[..1]").should == 0
- eval("0b10000[..2]").should == 0
- eval("0b10000[..3]").should == 0
- end
-
- it "raises ArgumentError if any of i bit equals 1" do
- -> {
- eval("0b111110[..3]")
- }.should raise_error(ArgumentError, /The beginless range for Integer#\[\] results in infinity/)
- end
+ it "raises ArgumentError if any of i bit equals 1" do
+ -> {
+ eval("0b111110[..3]")
+ }.should raise_error(ArgumentError, /The beginless range for Integer#\[\] results in infinity/)
end
end
end
diff --git a/spec/ruby/core/integer/fdiv_spec.rb b/spec/ruby/core/integer/fdiv_spec.rb
index 6de170278f..d99a19eb0f 100644
--- a/spec/ruby/core/integer/fdiv_spec.rb
+++ b/spec/ruby/core/integer/fdiv_spec.rb
@@ -9,6 +9,52 @@ describe "Integer#fdiv" do
8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE)
end
+ it "performs floating-point division between self bignum and a bignum" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ num.fdiv(den).should == 500.0
+ end
+
+ it "rounds to the correct value for bignums" do
+ den = 9 * 10**342
+
+ num = 1 * 10**344
+ num.fdiv(den).should == 11.11111111111111
+
+ num = 1 * 10**343
+ num.fdiv(den).should == 1.1111111111111112
+
+ num = 1 * 10**342
+ num.fdiv(den).should == 0.1111111111111111
+
+ num = 2 * 10**342
+ num.fdiv(den).should == 0.2222222222222222
+
+ num = 3 * 10**342
+ num.fdiv(den).should == 0.3333333333333333
+
+ num = 4 * 10**342
+ num.fdiv(den).should == 0.4444444444444444
+
+ num = 5 * 10**342
+ num.fdiv(den).should == 0.5555555555555556
+
+ num = 6 * 10**342
+ num.fdiv(den).should == 0.6666666666666666
+
+ num = 7 * 10**342
+ num.fdiv(den).should == 0.7777777777777778
+
+ num = 8 * 10**342
+ num.fdiv(den).should == 0.8888888888888888
+
+ num = 9 * 10**342
+ num.fdiv(den).should == 1.0
+
+ num = -5 * 10**342
+ num.fdiv(den).should == -0.5555555555555556
+ end
+
it "performs floating-point division between self and a Float" do
8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE)
end
diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb
index a3cd180b66..42238f6201 100644
--- a/spec/ruby/core/io/gets_spec.rb
+++ b/spec/ruby/core/io/gets_spec.rb
@@ -38,14 +38,6 @@ describe "IO#gets" do
IOSpecs.lines.each { |line| line.should == @io.gets }
end
- ruby_version_is ''...'2.7' do
- it "returns tainted strings" do
- while line = @io.gets
- line.should.tainted?
- end
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets
@io.lineno.should == @count += 1
@@ -64,14 +56,6 @@ describe "IO#gets" do
@io.gets(nil).should == IOSpecs.lines.join("")
end
- ruby_version_is ''...'2.7' do
- it "returns tainted strings" do
- while line = @io.gets(nil)
- line.should.tainted?
- end
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets(nil)
@io.lineno.should == @count += 1
@@ -100,14 +84,6 @@ describe "IO#gets" do
@io.gets.should == IOSpecs.lines[4]
end
- ruby_version_is ''...'2.7' do
- it "returns tainted strings" do
- while line = @io.gets("")
- line.should.tainted?
- end
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets("")
@io.lineno.should == @count += 1
@@ -126,14 +102,6 @@ describe "IO#gets" do
@io.gets("la linea").should == "Voici la ligne une.\nQui \303\250 la linea"
end
- ruby_version_is ''...'2.7' do
- it "returns tainted strings" do
- while line = @io.gets("la")
- line.should.tainted?
- end
- end
- end
-
it "updates lineno with each invocation" do
while (@io.gets("la"))
@io.lineno.should == @count += 1
diff --git a/spec/ruby/core/io/set_encoding_by_bom_spec.rb b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
index 7368ec7677..b52d3a943a 100644
--- a/spec/ruby/core/io/set_encoding_by_bom_spec.rb
+++ b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
@@ -12,66 +12,64 @@ describe "IO#set_encoding_by_bom" do
rm_r @name
end
- ruby_version_is "2.7" do
- it "returns the result encoding if found BOM UTF-8 sequence" do
- File.binwrite(@name, "\u{FEFF}abc")
+ it "returns the result encoding if found BOM UTF-8 sequence" do
+ File.binwrite(@name, "\u{FEFF}abc")
- @io.set_encoding_by_bom.should == Encoding::UTF_8
- @io.external_encoding.should == Encoding::UTF_8
- end
+ @io.set_encoding_by_bom.should == Encoding::UTF_8
+ @io.external_encoding.should == Encoding::UTF_8
+ end
- it "returns the result encoding if found BOM UTF_16LE sequence" do
- File.binwrite(@name, "\xFF\xFEabc")
+ it "returns the result encoding if found BOM UTF_16LE sequence" do
+ File.binwrite(@name, "\xFF\xFEabc")
- @io.set_encoding_by_bom.should == Encoding::UTF_16LE
- @io.external_encoding.should == Encoding::UTF_16LE
- end
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ end
- it "returns the result encoding if found BOM UTF_16BE sequence" do
- File.binwrite(@name, "\xFE\xFFabc")
+ it "returns the result encoding if found BOM UTF_16BE sequence" do
+ File.binwrite(@name, "\xFE\xFFabc")
- @io.set_encoding_by_bom.should == Encoding::UTF_16BE
- @io.external_encoding.should == Encoding::UTF_16BE
- end
+ @io.set_encoding_by_bom.should == Encoding::UTF_16BE
+ @io.external_encoding.should == Encoding::UTF_16BE
+ end
- it "returns the result encoding if found BOM UTF_32LE sequence" do
- File.binwrite(@name, "\xFF\xFE\x00\x00abc")
+ it "returns the result encoding if found BOM UTF_32LE sequence" do
+ File.binwrite(@name, "\xFF\xFE\x00\x00abc")
- @io.set_encoding_by_bom.should == Encoding::UTF_32LE
- @io.external_encoding.should == Encoding::UTF_32LE
- end
+ @io.set_encoding_by_bom.should == Encoding::UTF_32LE
+ @io.external_encoding.should == Encoding::UTF_32LE
+ end
- it "returns the result encoding if found BOM UTF_32BE sequence" do
- File.binwrite(@name, "\x00\x00\xFE\xFFabc")
+ it "returns the result encoding if found BOM UTF_32BE sequence" do
+ File.binwrite(@name, "\x00\x00\xFE\xFFabc")
- @io.set_encoding_by_bom.should == Encoding::UTF_32BE
- @io.external_encoding.should == Encoding::UTF_32BE
- end
+ @io.set_encoding_by_bom.should == Encoding::UTF_32BE
+ @io.external_encoding.should == Encoding::UTF_32BE
+ end
- it "returns nil if found BOM sequence not provided" do
- File.write(@name, "abc")
+ it "returns nil if found BOM sequence not provided" do
+ File.write(@name, "abc")
- @io.set_encoding_by_bom.should == nil
- end
+ @io.set_encoding_by_bom.should == nil
+ end
- it 'returns exception if io not in binary mode' do
- not_binary_io = new_io(@name, 'r')
+ it 'returns exception if io not in binary mode' do
+ not_binary_io = new_io(@name, 'r')
- -> { not_binary_io.set_encoding_by_bom }.should raise_error(ArgumentError, 'ASCII incompatible encoding needs binmode')
- ensure
- not_binary_io.close
- end
+ -> { not_binary_io.set_encoding_by_bom }.should raise_error(ArgumentError, 'ASCII incompatible encoding needs binmode')
+ ensure
+ not_binary_io.close
+ end
- it 'returns exception if encoding already set' do
- @io.set_encoding("utf-8")
+ it 'returns exception if encoding already set' do
+ @io.set_encoding("utf-8")
- -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding is set to UTF-8 already')
- end
+ -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding is set to UTF-8 already')
+ end
- it 'returns exception if encoding conversion is already set' do
- @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
+ it 'returns exception if encoding conversion is already set' do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
- -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding conversion is set')
- end
+ -> { @io.set_encoding_by_bom }.should raise_error(ArgumentError, 'encoding conversion is set')
end
end
diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb
index 776707205a..716743a6af 100644
--- a/spec/ruby/core/io/ungetbyte_spec.rb
+++ b/spec/ruby/core/io/ungetbyte_spec.rb
@@ -36,20 +36,10 @@ describe "IO#ungetbyte" do
@io.getbyte.should == 97
end
- ruby_version_is ''...'2.6.1' do
- it "is an RangeError if the integer is not in 8bit" do
- for i in [4095, 0x4f7574206f6620636861722072616e6765] do
- -> { @io.ungetbyte(i) }.should raise_error(RangeError)
- end
- end
- end
-
- ruby_version_is '2.6.1' do
- it "never raises RangeError" do
- for i in [4095, 0x4f7574206f6620636861722072616e67ff] do
- @io.ungetbyte(i).should be_nil
- @io.getbyte.should == 255
- end
+ it "never raises RangeError" do
+ for i in [4095, 0x4f7574206f6620636861722072616e67ff] do
+ @io.ungetbyte(i).should be_nil
+ @io.getbyte.should == 255
end
end
diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb
index 3ec8f0f432..5994b28fa3 100644
--- a/spec/ruby/core/kernel/caller_locations_spec.rb
+++ b/spec/ruby/core/kernel/caller_locations_spec.rb
@@ -34,12 +34,10 @@ describe 'Kernel#caller_locations' do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end
- ruby_version_is "2.7" do
- it "works with beginless ranges" do
- locations1 = caller_locations(0)
- locations2 = caller_locations(eval("(...5)"))
- locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(...5)")].map(&:to_s)[eval("(2..)")]
- end
+ it "works with beginless ranges" do
+ locations1 = caller_locations(0)
+ locations2 = caller_locations((...5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(...5)].map(&:to_s)[eval("(2..)")]
end
it "can be called with a range whose end is negative" do
diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb
index dba65ddcb0..f1ff7044b8 100644
--- a/spec/ruby/core/kernel/caller_spec.rb
+++ b/spec/ruby/core/kernel/caller_spec.rb
@@ -50,12 +50,10 @@ describe 'Kernel#caller' do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end
- ruby_version_is "2.7" do
- it "works with beginless ranges" do
- locations1 = KernelSpecs::CallerTest.locations(0)
- locations2 = KernelSpecs::CallerTest.locations(eval("(..5)"))
- locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(..5)")].map(&:to_s)[eval("(2..)")]
- end
+ it "works with beginless ranges" do
+ locations1 = KernelSpecs::CallerTest.locations(0)
+ locations2 = KernelSpecs::CallerTest.locations((..5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(..5)].map(&:to_s)[eval("(2..)")]
end
guard -> { Kernel.instance_method(:tap).source_location } do
diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb
index 38ae1984c0..a87c7544fe 100644
--- a/spec/ruby/core/kernel/clone_spec.rb
+++ b/spec/ruby/core/kernel/clone_spec.rb
@@ -206,11 +206,4 @@ describe "Kernel#clone" do
cloned.bar.should == ['a']
end
-
- ruby_version_is ''...'2.7' do
- it 'copies tainted?' do
- o = ''.taint.clone
- o.tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/kernel/inspect_spec.rb b/spec/ruby/core/kernel/inspect_spec.rb
index e6fca8bf6f..1f9ce834ab 100644
--- a/spec/ruby/core/kernel/inspect_spec.rb
+++ b/spec/ruby/core/kernel/inspect_spec.rb
@@ -6,16 +6,6 @@ describe "Kernel#inspect" do
Object.new.inspect.should be_an_instance_of(String)
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if self is tainted" do
- Object.new.taint.inspect.tainted?.should be_true
- end
-
- it "returns an untrusted string if self is untrusted" do
- Object.new.untrust.inspect.untrusted?.should be_true
- end
- end
-
it "does not call #to_s if it is defined" do
# We must use a bare Object here
obj = Object.new
diff --git a/spec/ruby/core/kernel/method_spec.rb b/spec/ruby/core/kernel/method_spec.rb
index 25c6691e10..caf2ec948b 100644
--- a/spec/ruby/core/kernel/method_spec.rb
+++ b/spec/ruby/core/kernel/method_spec.rb
@@ -34,4 +34,28 @@ describe "Kernel#method" do
m.should be_an_instance_of(Method)
m.call(1, 2, 3).should == "Done handled_privately([1, 2, 3])"
end
+
+ it "can call a #method_missing accepting zero or one arguments" do
+ cls = Class.new do
+ def respond_to_missing?(name, *)
+ name == :foo or super
+ end
+ def method_missing
+ :no_args
+ end
+ end
+ m = cls.new.method(:foo)
+ -> { m.call }.should raise_error(ArgumentError)
+
+ cls = Class.new do
+ def respond_to_missing?(name, *)
+ name == :bar or super
+ end
+ def method_missing(m)
+ m
+ end
+ end
+ m = cls.new.method(:bar)
+ m.call.should == :bar
+ end
end
diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb
index dfe178420b..231c1f0dfb 100644
--- a/spec/ruby/core/kernel/proc_spec.rb
+++ b/spec/ruby/core/kernel/proc_spec.rb
@@ -40,15 +40,7 @@ describe "Kernel#proc" do
proc
end
- ruby_version_is ""..."2.7" do
- it "uses the implicit block from an enclosing method" do
- prc = some_method { "hello" }
-
- prc.call.should == "hello"
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "can be created when called with no block" do
-> {
some_method { "hello" }
diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb
index 84ad49cbde..4fac6006e1 100644
--- a/spec/ruby/core/kernel/shared/dup_clone.rb
+++ b/spec/ruby/core/kernel/shared/dup_clone.rb
@@ -52,18 +52,6 @@ describe :kernel_dup_clone, shared: true do
o2.original.should equal(o)
end
- ruby_version_is ''...'2.7' do
- it "preserves tainted state from the original" do
- o = ObjectSpecDupInitCopy.new
- o2 = o.send(@method)
- o.taint
- o3 = o.send(@method)
-
- o2.should_not.tainted?
- o3.should.tainted?
- end
- end
-
it "does not preserve the object_id" do
o1 = ObjectSpecDupInitCopy.new
old_object_id = o1.object_id
@@ -71,18 +59,6 @@ describe :kernel_dup_clone, shared: true do
o2.object_id.should_not == old_object_id
end
- ruby_version_is ''...'2.7' do
- it "preserves untrusted state from the original" do
- o = ObjectSpecDupInitCopy.new
- o2 = o.send(@method)
- o.untrust
- o3 = o.send(@method)
-
- o2.should_not.untrusted?
- o3.should.untrusted?
- end
- end
-
it "returns nil for NilClass" do
nil.send(@method).should == nil
end
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index 9a2c38be1a..cf01b9dc52 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -251,7 +251,7 @@ describe :kernel_require, shared: true do
ScratchPad.recorded.should == [:loaded]
end
- ruby_bug "#16926", "2.7"..."3.0" do
+ ruby_bug "#16926", ""..."3.0" do
it "does not load a feature twice when $LOAD_PATH has been modified" do
$LOAD_PATH.replace [CODE_LOADING_DIR]
@object.require("load_fixture").should be_true
@@ -547,9 +547,7 @@ describe :kernel_require, shared: true do
end
provided = %w[complex enumerator rational thread]
- ruby_version_is "2.7" do
- provided << 'ruby2_keywords'
- end
+ provided << 'ruby2_keywords'
it "#{provided.join(', ')} are already required" do
features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb
index 8ba9869af2..9a58bb5f04 100644
--- a/spec/ruby/core/kernel/taint_spec.rb
+++ b/spec/ruby/core/kernel/taint_spec.rb
@@ -2,50 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#taint" do
- ruby_version_is ''...'2.7' do
- it "returns self" do
- o = Object.new
- o.taint.should equal(o)
- end
-
- it "sets the tainted bit" do
- o = Object.new
- o.taint
- o.should.tainted?
- end
-
- it "raises FrozenError on an untainted, frozen object" do
- o = Object.new.freeze
- -> { o.taint }.should raise_error(FrozenError)
- end
-
- it "does not raise an error on a tainted, frozen object" do
- o = Object.new.taint.freeze
- o.taint.should equal(o)
- end
-
- it "has no effect on immediate values" do
- [nil, true, false].each do |v|
- v.taint
- v.should_not.tainted?
- end
- end
-
- it "no raises a RuntimeError on symbols" do
- v = :sym
- -> { v.taint }.should_not raise_error(RuntimeError)
- v.should_not.tainted?
- end
-
- it "no raises error on integer values" do
- [1].each do |v|
- -> { v.taint }.should_not raise_error(RuntimeError)
- v.should_not.tainted?
- end
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = Object.new
o.taint
diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb
index 022938bfc1..7511c730c9 100644
--- a/spec/ruby/core/kernel/tainted_spec.rb
+++ b/spec/ruby/core/kernel/tainted_spec.rb
@@ -2,17 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#tainted?" do
- ruby_version_is ''...'2.7' do
- it "returns true if Object is tainted" do
- o = mock('o')
- p = mock('p')
- p.taint
- o.should_not.tainted?
- p.should.tainted?
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = mock('o')
p = mock('p')
diff --git a/spec/ruby/core/kernel/to_s_spec.rb b/spec/ruby/core/kernel/to_s_spec.rb
index 64b40f46e5..ea4b00151e 100644
--- a/spec/ruby/core/kernel/to_s_spec.rb
+++ b/spec/ruby/core/kernel/to_s_spec.rb
@@ -5,14 +5,4 @@ describe "Kernel#to_s" do
it "returns a String containing the name of self's class" do
Object.new.to_s.should =~ /Object/
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted result if self is tainted" do
- Object.new.taint.to_s.tainted?.should be_true
- end
-
- it "returns an untrusted result if self is untrusted" do
- Object.new.untrust.to_s.untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb
index 399983f74d..4665036da6 100644
--- a/spec/ruby/core/kernel/trust_spec.rb
+++ b/spec/ruby/core/kernel/trust_spec.rb
@@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#trust" do
- ruby_version_is ''...'2.7' do
- it "returns self" do
- o = Object.new
- o.trust.should equal(o)
- end
-
- it "clears the untrusted bit" do
- o = Object.new.untrust
- o.trust
- o.should_not.untrusted?
- end
-
- it "raises FrozenError on an untrusted, frozen object" do
- o = Object.new.untrust.freeze
- -> { o.trust }.should raise_error(FrozenError)
- end
-
- it "does not raise an error on a trusted, frozen object" do
- o = Object.new.freeze
- o.trust.should equal(o)
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = Object.new.untrust
o.should_not.untrusted?
diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb
index 44d87da5d5..42fe8a4239 100644
--- a/spec/ruby/core/kernel/untaint_spec.rb
+++ b/spec/ruby/core/kernel/untaint_spec.rb
@@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untaint" do
- ruby_version_is ''...'2.7' do
- it "returns self" do
- o = Object.new
- o.untaint.should equal(o)
- end
-
- it "clears the tainted bit" do
- o = Object.new.taint
- o.untaint
- o.should_not.tainted?
- end
-
- it "raises FrozenError on a tainted, frozen object" do
- o = Object.new.taint.freeze
- -> { o.untaint }.should raise_error(FrozenError)
- end
-
- it "does not raise an error on an untainted, frozen object" do
- o = Object.new.freeze
- o.untaint.should equal(o)
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = Object.new.taint
o.should_not.tainted?
diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb
index aff0fec57b..ba0e073cf0 100644
--- a/spec/ruby/core/kernel/untrust_spec.rb
+++ b/spec/ruby/core/kernel/untrust_spec.rb
@@ -2,30 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untrust" do
- ruby_version_is ''...'2.7' do
- it "returns self" do
- o = Object.new
- o.untrust.should equal(o)
- end
-
- it "sets the untrusted bit" do
- o = Object.new
- o.untrust
- o.should.untrusted?
- end
-
- it "raises FrozenError on a trusted, frozen object" do
- o = Object.new.freeze
- -> { o.untrust }.should raise_error(FrozenError)
- end
-
- it "does not raise an error on an untrusted, frozen object" do
- o = Object.new.untrust.freeze
- o.untrust.should equal(o)
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = Object.new
o.untrust
diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb
index 5347c90093..517bd4711b 100644
--- a/spec/ruby/core/kernel/untrusted_spec.rb
+++ b/spec/ruby/core/kernel/untrusted_spec.rb
@@ -2,33 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untrusted?" do
- ruby_version_is ''...'2.7' do
- it "returns the untrusted status of an object" do
- o = mock('o')
- o.should_not.untrusted?
- o.untrust
- o.should.untrusted?
- end
-
- it "has no effect on immediate values" do
- a = nil
- b = true
- c = false
- a.untrust
- b.untrust
- c.untrust
- a.should_not.untrusted?
- b.should_not.untrusted?
- c.should_not.untrusted?
- end
-
- it "has effect on immediate values" do
- d = 1
- -> { d.untrust }.should_not raise_error(RuntimeError)
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "is a no-op" do
o = mock('o')
o.should_not.untrusted?
diff --git a/spec/ruby/core/main/ruby2_keywords_spec.rb b/spec/ruby/core/main/ruby2_keywords_spec.rb
index 0999cddeed..27ceae3253 100644
--- a/spec/ruby/core/main/ruby2_keywords_spec.rb
+++ b/spec/ruby/core/main/ruby2_keywords_spec.rb
@@ -1,11 +1,9 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "main.ruby2_keywords" do
- it "is the same as Object.ruby2_keywords" do
- main = TOPLEVEL_BINDING.receiver
- main.should have_private_method(:ruby2_keywords)
- end
+describe "main.ruby2_keywords" do
+ it "is the same as Object.ruby2_keywords" do
+ main = TOPLEVEL_BINDING.receiver
+ main.should have_private_method(:ruby2_keywords)
end
end
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index a54a4c6735..079010e554 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -604,30 +604,4 @@ describe "Marshal.dump" do
m = Mutex.new
-> { Marshal.dump(m) }.should raise_error(TypeError)
end
-
- ruby_version_is ''...'2.7' do
- it "returns an untainted string if object is untainted" do
- Marshal.dump(Object.new).tainted?.should be_false
- end
-
- it "returns a tainted string if object is tainted" do
- Marshal.dump(Object.new.taint).tainted?.should be_true
- end
-
- it "returns a tainted string if nested object is tainted" do
- Marshal.dump([[Object.new.taint]]).tainted?.should be_true
- end
-
- it "returns a trusted string if object is trusted" do
- Marshal.dump(Object.new).untrusted?.should be_false
- end
-
- it "returns an untrusted string if object is untrusted" do
- Marshal.dump(Object.new.untrust).untrusted?.should be_true
- end
-
- it "returns an untrusted string if nested object is untrusted" do
- Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index b70bca55bf..98fae44296 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -306,89 +306,6 @@ describe :marshal_load, shared: true do
end
end
- ruby_version_is ''...'2.7' do
- it "returns an untainted object if source is untainted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.tainted?.should be_false
- end
-
- describe "when source is tainted" do
- it "returns a tainted object" do
- x = Object.new
- x.taint
- s = Marshal.dump(x)
- y = Marshal.send(@method, s)
- y.tainted?.should be_true
-
- # note that round-trip via Marshal does not preserve
- # the taintedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
-
- it "does not taint Symbols" do
- x = [:x]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Fixnums" do
- x = [1]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Bignums" do
- x = [bignum_value]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Floats" do
- x = [1.2]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
- end
-
- it "preserves taintedness of nested structure" do
- x = Object.new
- a = [[x]]
- x.taint
- y = Marshal.send(@method, Marshal.dump(a))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
-
- it "returns a trusted object if source is trusted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_false
- end
-
- it "returns an untrusted object if source is untrusted" do
- x = Object.new
- x.untrust
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_true
-
- # note that round-trip via Marshal does not preserve
- # the untrustedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.untrusted?.should be_true
- y.first.untrusted?.should be_true
- y.first.first.untrusted?.should be_true
- end
- end
-
# Note: Ruby 1.9 should be compatible with older marshal format
MarshalSpec::DATA.each do |description, (object, marshal, attributes)|
it "loads a #{description}" do
diff --git a/spec/ruby/core/matchdata/allocate_spec.rb b/spec/ruby/core/matchdata/allocate_spec.rb
index 9f3ada4018..142ce639c2 100644
--- a/spec/ruby/core/matchdata/allocate_spec.rb
+++ b/spec/ruby/core/matchdata/allocate_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
describe "MatchData.allocate" do
- ruby_version_is "2.7" do
- it "is undefined" do
- # https://bugs.ruby-lang.org/issues/16294
- -> { MatchData.allocate }.should raise_error(NoMethodError)
- end
+ it "is undefined" do
+ # https://bugs.ruby-lang.org/issues/16294
+ -> { MatchData.allocate }.should raise_error(NoMethodError)
end
end
diff --git a/spec/ruby/core/matchdata/element_reference_spec.rb b/spec/ruby/core/matchdata/element_reference_spec.rb
index 3b976cb1c4..8965f902a0 100644
--- a/spec/ruby/core/matchdata/element_reference_spec.rb
+++ b/spec/ruby/core/matchdata/element_reference_spec.rb
@@ -16,6 +16,12 @@ describe "MatchData#[]" do
it "supports accessors [start, length]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[1, 2].should == %w|H X|
/(.)(.)(\d+)(\d)/.match("THX1138.")[-3, 2].should == %w|X 113|
+
+ # negative index is larger than the number of match values
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[-30, 2].should == nil
+
+ # length argument larger than number of match values is capped to match value length
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3, 10].should == %w|113 8|
end
it "supports ranges [start..end]" do
diff --git a/spec/ruby/core/matchdata/post_match_spec.rb b/spec/ruby/core/matchdata/post_match_spec.rb
index 1a4ca0a83f..d3aa4c8900 100644
--- a/spec/ruby/core/matchdata/post_match_spec.rb
+++ b/spec/ruby/core/matchdata/post_match_spec.rb
@@ -7,24 +7,6 @@ describe "MatchData#post_match" do
$'.should == ': The Movie'
end
- ruby_version_is ''...'2.7' do
- it "keeps taint status from the source string" do
- str = "THX1138: The Movie"
- str.taint
- res = /(.)(.)(\d+)(\d)/.match(str).post_match
- res.tainted?.should be_true
- $'.tainted?.should be_true
- end
-
- it "keeps untrusted status from the source string" do
- str = "THX1138: The Movie"
- str.untrust
- res = /(.)(.)(\d+)(\d)/.match(str).post_match
- res.untrusted?.should be_true
- $'.untrusted?.should be_true
- end
- end
-
it "sets the encoding to the encoding of the source String" do
str = "abc".force_encoding Encoding::EUC_JP
str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
diff --git a/spec/ruby/core/matchdata/pre_match_spec.rb b/spec/ruby/core/matchdata/pre_match_spec.rb
index 9b50336c7d..b43be5fb41 100644
--- a/spec/ruby/core/matchdata/pre_match_spec.rb
+++ b/spec/ruby/core/matchdata/pre_match_spec.rb
@@ -7,24 +7,6 @@ describe "MatchData#pre_match" do
$`.should == 'T'
end
- ruby_version_is ''...'2.7' do
- it "keeps taint status from the source string" do
- str = "THX1138: The Movie"
- str.taint
- res = /(.)(.)(\d+)(\d)/.match(str).pre_match
- res.tainted?.should be_true
- $`.tainted?.should be_true
- end
-
- it "keeps untrusted status from the source string" do
- str = "THX1138: The Movie"
- str.untrust
- res = /(.)(.)(\d+)(\d)/.match(str).pre_match
- res.untrusted?.should be_true
- $`.untrusted?.should be_true
- end
- end
-
it "sets the encoding to the encoding of the source String" do
str = "abc".force_encoding Encoding::EUC_JP
str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb
index 0dcae41b59..6fdeaaf99c 100644
--- a/spec/ruby/core/method/shared/to_s.rb
+++ b/spec/ruby/core/method/shared/to_s.rb
@@ -24,19 +24,17 @@ describe :method_to_s, shared: true do
@string.should =~ /\#bar/
end
- ruby_version_is "2.7" do
- it "returns a String containing method arguments" do
- obj = MethodSpecs::Methods.new
- obj.method(:zero).send(@method).should.include?("()")
- obj.method(:one_req).send(@method).should.include?("(a)")
- obj.method(:one_req_named).send(@method).should.include?("(a:)")
- obj.method(:zero_with_block).send(@method).should.include?("(&blk)")
- obj.method(:one_opt).send(@method).should.include?("(a=...)")
- obj.method(:one_opt_named).send(@method).should.include?("(a: ...)")
- obj.method(:zero_with_splat).send(@method).should.include?("(*a)")
- obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)")
- obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
- end
+ it "returns a String containing method arguments" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:zero).send(@method).should.include?("()")
+ obj.method(:one_req).send(@method).should.include?("(a)")
+ obj.method(:one_req_named).send(@method).should.include?("(a:)")
+ obj.method(:zero_with_block).send(@method).should.include?("(&blk)")
+ obj.method(:one_opt).send(@method).should.include?("(a=...)")
+ obj.method(:one_opt_named).send(@method).should.include?("(a: ...)")
+ obj.method(:zero_with_splat).send(@method).should.include?("(*a)")
+ obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)")
+ obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
end
it "returns a String containing the Module the method is defined in" do
@@ -79,11 +77,9 @@ describe :method_to_s, shared: true do
@string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
end
- ruby_version_is '2.7' do
- ruby_bug '#17428', '2.7'...'3.0' do
- it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
- String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
- end
+ ruby_bug '#17428', ''...'3.0' do
+ it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
+ String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
end
end
end
diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb
index d960798eef..1724cde5d6 100644
--- a/spec/ruby/core/module/append_features_spec.rb
+++ b/spec/ruby/core/module/append_features_spec.rb
@@ -47,20 +47,6 @@ describe "Module#append_features" do
end
- ruby_version_is ''...'2.7' do
- it "copies own tainted status to the given module" do
- other = Module.new
- Module.new.taint.send :append_features, other
- other.tainted?.should be_true
- end
-
- it "copies own untrusted status to the given module" do
- other = Module.new
- Module.new.untrust.send :append_features, other
- other.untrusted?.should be_true
- end
- end
-
describe "when other is frozen" do
before :each do
@receiver = Module.new
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index 1d61646db5..7e7e7a2139 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -18,16 +18,14 @@ describe "Module#autoload?" do
ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload).should == "another_autoload.rb"
end
- ruby_version_is "2.7" do
- it "returns nil if an ancestor defined that autoload but recursion is disabled" do
- ModuleSpecs::Autoload::Parent.autoload :InheritedAutoload, "inherited_autoload.rb"
- ModuleSpecs::Autoload::Child.autoload?(:InheritedAutoload, false).should be_nil
- end
+ it "returns nil if an ancestor defined that autoload but recursion is disabled" do
+ ModuleSpecs::Autoload::Parent.autoload :InheritedAutoload, "inherited_autoload.rb"
+ ModuleSpecs::Autoload::Child.autoload?(:InheritedAutoload, false).should be_nil
+ end
- it "returns the name of the file that will be loaded if recursion is disabled but the autoload is defined on the class itself" do
- ModuleSpecs::Autoload::Child.autoload :ChildAutoload, "child_autoload.rb"
- ModuleSpecs::Autoload::Child.autoload?(:ChildAutoload, false).should == "child_autoload.rb"
- end
+ it "returns the name of the file that will be loaded if recursion is disabled but the autoload is defined on the class itself" do
+ ModuleSpecs::Autoload::Child.autoload :ChildAutoload, "child_autoload.rb"
+ ModuleSpecs::Autoload::Child.autoload?(:ChildAutoload, false).should == "child_autoload.rb"
end
end
@@ -514,9 +512,7 @@ describe "Module#autoload" do
it "does not load the file when accessing the constants table of the module" do
ModuleSpecs::Autoload.autoload :P, @non_existent
ModuleSpecs::Autoload.const_defined?(:P).should be_true
- ruby_bug "[Bug #15780]", ""..."2.7" do
- ModuleSpecs::Autoload.const_defined?("P").should be_true
- end
+ ModuleSpecs::Autoload.const_defined?("P").should be_true
end
it "loads the file when opening a module that is the autoloaded constant" do
diff --git a/spec/ruby/core/module/const_source_location_spec.rb b/spec/ruby/core/module/const_source_location_spec.rb
index 9e1f2c1c49..11a2e74756 100644
--- a/spec/ruby/core/module/const_source_location_spec.rb
+++ b/spec/ruby/core/module/const_source_location_spec.rb
@@ -6,215 +6,220 @@ describe "Module#const_source_location" do
@constants_fixture_path = File.expand_path('../../fixtures/constants.rb', __dir__)
end
- ruby_version_is "2.7" do
- describe "with dynamically assigned constants" do
- it "searches a path in the immediate class or module first" do
- ConstantSpecs::ClassA::CSL_CONST301 = :const301_1
- ConstantSpecs::ClassA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
-
- ConstantSpecs::ModuleA::CSL_CONST301 = :const301_2
- ConstantSpecs::ModuleA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+ describe "with dynamically assigned constants" do
+ it "searches a path in the immediate class or module first" do
+ ConstantSpecs::ClassA::CSL_CONST301 = :const301_1
+ ConstantSpecs::ClassA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
- ConstantSpecs::ParentA::CSL_CONST301 = :const301_3
- ConstantSpecs::ParentA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+ ConstantSpecs::ModuleA::CSL_CONST301 = :const301_2
+ ConstantSpecs::ModuleA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
- ConstantSpecs::ContainerA::ChildA::CSL_CONST301 = :const301_5
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
- end
+ ConstantSpecs::ParentA::CSL_CONST301 = :const301_3
+ ConstantSpecs::ParentA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
- it "searches a path in a module included in the immediate class before the superclass" do
- ConstantSpecs::ParentB::CSL_CONST302 = :const302_1
- ConstantSpecs::ModuleF::CSL_CONST302 = :const302_2
- ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST302).should == [__FILE__, __LINE__ - 1]
- end
-
- it "searches a path in the superclass before a module included in the superclass" do
- ConstantSpecs::ModuleE::CSL_CONST303 = :const303_1
- ConstantSpecs::ParentB::CSL_CONST303 = :const303_2
- ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST303).should == [__FILE__, __LINE__ - 1]
- end
-
- it "searches a path in a module included in the superclass" do
- ConstantSpecs::ModuleA::CSL_CONST304 = :const304_1
- ConstantSpecs::ModuleE::CSL_CONST304 = :const304_2
- ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST304).should == [__FILE__, __LINE__ - 1]
- end
-
- it "searches a path in the superclass chain" do
- ConstantSpecs::ModuleA::CSL_CONST305 = :const305
- ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST305).should == [__FILE__, __LINE__ - 1]
- end
-
- it "returns path to a toplevel constant when the receiver is a Class" do
- Object::CSL_CONST306 = :const306
- ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST306).should == [__FILE__, __LINE__ - 1]
- end
-
- it "returns path to a toplevel constant when the receiver is a Module" do
- Object::CSL_CONST308 = :const308
- ConstantSpecs.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 1]
- ConstantSpecs::ModuleA.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 2]
- end
-
- it "returns path to the updated value of a constant" do
- ConstantSpecs::ClassB::CSL_CONST309 = :const309_1
- ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 1]
+ ConstantSpecs::ContainerA::ChildA::CSL_CONST301 = :const301_5
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+ end
- -> {
- ConstantSpecs::ClassB::CSL_CONST309 = :const309_2
- }.should complain(/already initialized constant/)
- ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 2]
- end
+ it "searches a path in a module included in the immediate class before the superclass" do
+ ConstantSpecs::ParentB::CSL_CONST302 = :const302_1
+ ConstantSpecs::ModuleF::CSL_CONST302 = :const302_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST302).should == [__FILE__, __LINE__ - 1]
end
- describe "with statically assigned constants" do
- it "searches location path the immediate class or module first" do
- ConstantSpecs::ClassA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
- ConstantSpecs::ModuleA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST10_LINE]
- ConstantSpecs::ParentA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST10_LINE]
- ConstantSpecs::ContainerA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::CS_CONST10_LINE]
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::ChildA::CS_CONST10_LINE]
- end
+ it "searches a path in the superclass before a module included in the superclass" do
+ ConstantSpecs::ModuleE::CSL_CONST303 = :const303_1
+ ConstantSpecs::ParentB::CSL_CONST303 = :const303_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST303).should == [__FILE__, __LINE__ - 1]
+ end
- it "searches location path a module included in the immediate class before the superclass" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST15).should == [@constants_fixture_path, ConstantSpecs::ModuleC::CS_CONST15_LINE]
- end
+ it "searches a path in a module included in the superclass" do
+ ConstantSpecs::ModuleA::CSL_CONST304 = :const304_1
+ ConstantSpecs::ModuleE::CSL_CONST304 = :const304_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST304).should == [__FILE__, __LINE__ - 1]
+ end
- it "searches location path the superclass before a module included in the superclass" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST11).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST11_LINE]
- end
+ it "searches a path in the superclass chain" do
+ ConstantSpecs::ModuleA::CSL_CONST305 = :const305
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST305).should == [__FILE__, __LINE__ - 1]
+ end
- it "searches location path a module included in the superclass" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST12).should == [@constants_fixture_path, ConstantSpecs::ModuleB::CS_CONST12_LINE]
- end
+ it "returns path to a toplevel constant when the receiver is a Class" do
+ Object::CSL_CONST306 = :const306
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST306).should == [__FILE__, __LINE__ - 1]
+ end
- it "searches location path the superclass chain" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST13).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST13_LINE]
- end
+ it "returns path to a toplevel constant when the receiver is a Module" do
+ Object::CSL_CONST308 = :const308
+ ConstantSpecs.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 1]
+ ConstantSpecs::ModuleA.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 2]
+ end
- it "returns location path a toplevel constant when the receiver is a Class" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
- end
+ it "returns path to the updated value of a constant" do
+ ConstantSpecs::ClassB::CSL_CONST309 = :const309_1
+ ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 1]
- it "returns location path a toplevel constant when the receiver is a Module" do
- ConstantSpecs.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
- ConstantSpecs::ModuleA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
- end
+ -> {
+ ConstantSpecs::ClassB::CSL_CONST309 = :const309_2
+ }.should complain(/already initialized constant/)
+ ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 2]
end
+ end
- it "return empty path if constant defined in C code" do
- Object.const_source_location(:String).should == []
+ describe "with statically assigned constants" do
+ it "searches location path the immediate class or module first" do
+ ConstantSpecs::ClassA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST10_LINE]
+ ConstantSpecs::ParentA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST10_LINE]
+ ConstantSpecs::ContainerA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::CS_CONST10_LINE]
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::ChildA::CS_CONST10_LINE]
end
- it "accepts a String or Symbol name" do
- Object.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
- Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ it "searches location path a module included in the immediate class before the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST15).should == [@constants_fixture_path, ConstantSpecs::ModuleC::CS_CONST15_LINE]
end
- it "returns nil if no constant is defined in the search path" do
- ConstantSpecs.const_source_location(:CS_CONSTX).should == nil
+ it "searches location path the superclass before a module included in the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST11).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST11_LINE]
end
- it "raises a NameError if the name does not start with a capital letter" do
- -> { ConstantSpecs.const_source_location "name" }.should raise_error(NameError)
+ it "searches location path a module included in the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST12).should == [@constants_fixture_path, ConstantSpecs::ModuleB::CS_CONST12_LINE]
end
- it "raises a NameError if the name starts with a non-alphabetic character" do
- -> { ConstantSpecs.const_source_location "__CONSTX__" }.should raise_error(NameError)
- -> { ConstantSpecs.const_source_location "@CS_CONST1" }.should raise_error(NameError)
- -> { ConstantSpecs.const_source_location "!CS_CONST1" }.should raise_error(NameError)
+ it "searches location path the superclass chain" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST13).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST13_LINE]
end
- it "raises a NameError if the name contains non-alphabetic characters except '_'" do
- Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
- -> { ConstantSpecs.const_source_location "CS_CONST1=" }.should raise_error(NameError)
- -> { ConstantSpecs.const_source_location "CS_CONST1?" }.should raise_error(NameError)
+ it "returns location path a toplevel constant when the receiver is a Class" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
end
- it "calls #to_str to convert the given name to a String" do
- name = mock("ClassA")
- name.should_receive(:to_str).and_return("ClassA")
- ConstantSpecs.const_source_location(name).should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CLASS_A_LINE]
+ it "returns location path a toplevel constant when the receiver is a Module" do
+ ConstantSpecs.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
end
+ end
- it "raises a TypeError if conversion to a String by calling #to_str fails" do
- name = mock('123')
- -> { ConstantSpecs.const_source_location(name) }.should raise_error(TypeError)
+ it "return empty path if constant defined in C code" do
+ Object.const_source_location(:String).should == []
+ end
- name.should_receive(:to_str).and_return(123)
- -> { ConstantSpecs.const_source_location(name) }.should raise_error(TypeError)
- end
+ it "accepts a String or Symbol name" do
+ Object.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
- it "does not search the singleton class of a Class or Module" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST14).should == nil
- ConstantSpecs.const_source_location(:CS_CONST14).should == nil
- end
+ it "returns nil if no constant is defined in the search path" do
+ ConstantSpecs.const_source_location(:CS_CONSTX).should == nil
+ end
- it "does not search the containing scope" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST20).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST20_LINE]
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST5) == nil
- end
+ it "raises a NameError if the name does not start with a capital letter" do
+ -> { ConstantSpecs.const_source_location "name" }.should raise_error(NameError)
+ end
- it "returns nil if the constant is defined in the receiver's superclass and the inherit flag is false" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, false).should == nil
- end
+ it "raises a NameError if the name starts with a non-alphabetic character" do
+ -> { ConstantSpecs.const_source_location "__CONSTX__" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_source_location "@CS_CONST1" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_source_location "!CS_CONST1" }.should raise_error(NameError)
+ end
- it "searches into the receiver superclasses if the inherit flag is true" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, true).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST4_LINE]
- end
+ it "raises a NameError if the name contains non-alphabetic characters except '_'" do
+ Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ -> { ConstantSpecs.const_source_location "CS_CONST1=" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_source_location "CS_CONST1?" }.should raise_error(NameError)
+ end
- it "returns nil when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do
- ConstantSpecs::ModuleA.const_source_location(:CS_CONST1, false).should == nil
- end
+ it "calls #to_str to convert the given name to a String" do
+ name = mock("ClassA")
+ name.should_receive(:to_str).and_return("ClassA")
+ ConstantSpecs.const_source_location(name).should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CLASS_A_LINE]
+ end
- it "returns nil when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do
- ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1, false).should == nil
- end
+ it "raises a TypeError if conversion to a String by calling #to_str fails" do
+ name = mock('123')
+ -> { ConstantSpecs.const_source_location(name) }.should raise_error(TypeError)
- it "accepts a toplevel scope qualifier" do
- ConstantSpecs.const_source_location("::CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
- end
+ name.should_receive(:to_str).and_return(123)
+ -> { ConstantSpecs.const_source_location(name) }.should raise_error(TypeError)
+ end
- it "accepts a scoped constant name" do
- ConstantSpecs.const_source_location("ClassA::CS_CONST10").should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
- end
+ it "does not search the singleton class of a Class or Module" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST14).should == nil
+ ConstantSpecs.const_source_location(:CS_CONST14).should == nil
+ end
- it "raises a NameError if the name includes two successive scope separators" do
- -> { ConstantSpecs.const_source_location("ClassA::::CS_CONST10") }.should raise_error(NameError)
- end
+ it "does not search the containing scope" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST20).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST20_LINE]
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST5) == nil
+ end
- it "raises a NameError if only '::' is passed" do
- -> { ConstantSpecs.const_source_location("::") }.should raise_error(NameError)
- end
+ it "returns nil if the constant is defined in the receiver's superclass and the inherit flag is false" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, false).should == nil
+ end
- it "raises a NameError if a Symbol has a toplevel scope qualifier" do
- -> { ConstantSpecs.const_source_location(:'::CS_CONST1') }.should raise_error(NameError)
- end
+ it "searches into the receiver superclasses if the inherit flag is true" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, true).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST4_LINE]
+ end
- it "raises a NameError if a Symbol is a scoped constant name" do
- -> { ConstantSpecs.const_source_location(:'ClassA::CS_CONST10') }.should raise_error(NameError)
- end
+ it "returns nil when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST1, false).should == nil
+ end
- it "does search private constants path" do
- ConstantSpecs.const_source_location(:CS_PRIVATE).should == [@constants_fixture_path, ConstantSpecs::CS_PRIVATE_LINE]
- end
+ it "returns nil when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1, false).should == nil
+ end
+
+ it "accepts a toplevel scope qualifier" do
+ ConstantSpecs.const_source_location("::CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
+
+ it "accepts a scoped constant name" do
+ ConstantSpecs.const_source_location("ClassA::CS_CONST10").should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
+ end
+
+ it "returns updated location from const_set" do
+ mod = Module.new
+ const_line = __LINE__ + 1
+ mod.const_set :Foo, 1
+ mod.const_source_location(:Foo).should == [__FILE__, const_line]
+ end
+
+ it "raises a NameError if the name includes two successive scope separators" do
+ -> { ConstantSpecs.const_source_location("ClassA::::CS_CONST10") }.should raise_error(NameError)
+ end
+
+ it "raises a NameError if only '::' is passed" do
+ -> { ConstantSpecs.const_source_location("::") }.should raise_error(NameError)
+ end
- context 'autoload' do
- before :all do
- ConstantSpecs.autoload :CSL_CONST1, "#{__dir__}/notexisting.rb"
- @line = __LINE__ - 1
- end
+ it "raises a NameError if a Symbol has a toplevel scope qualifier" do
+ -> { ConstantSpecs.const_source_location(:'::CS_CONST1') }.should raise_error(NameError)
+ end
- it 'returns the autoload location while not resolved' do
- ConstantSpecs.const_source_location('CSL_CONST1').should == [__FILE__, @line]
- end
+ it "raises a NameError if a Symbol is a scoped constant name" do
+ -> { ConstantSpecs.const_source_location(:'ClassA::CS_CONST10') }.should raise_error(NameError)
+ end
+
+ it "does search private constants path" do
+ ConstantSpecs.const_source_location(:CS_PRIVATE).should == [@constants_fixture_path, ConstantSpecs::CS_PRIVATE_LINE]
+ end
+
+ context 'autoload' do
+ before :all do
+ ConstantSpecs.autoload :CSL_CONST1, "#{__dir__}/notexisting.rb"
+ @line = __LINE__ - 1
+ end
+
+ it 'returns the autoload location while not resolved' do
+ ConstantSpecs.const_source_location('CSL_CONST1').should == [__FILE__, @line]
+ end
- it 'returns where the constant was resolved when resolved' do
- file = fixture(__FILE__, 'autoload_location.rb')
- ConstantSpecs.autoload :CONST_LOCATION, file
- line = ConstantSpecs::CONST_LOCATION
- ConstantSpecs.const_source_location('CONST_LOCATION').should == [file, line]
- end
+ it 'returns where the constant was resolved when resolved' do
+ file = fixture(__FILE__, 'autoload_location.rb')
+ ConstantSpecs.autoload :CONST_LOCATION, file
+ line = ConstantSpecs::CONST_LOCATION
+ ConstantSpecs.const_source_location('CONST_LOCATION').should == [file, line]
end
end
end
diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb
index faacbea03e..aabef934c4 100644
--- a/spec/ruby/core/module/deprecate_constant_spec.rb
+++ b/spec/ruby/core/module/deprecate_constant_spec.rb
@@ -31,17 +31,15 @@ describe "Module#deprecate_constant" do
-> { @module.const_get :PRIVATE }.should complain(/warning: constant .+::PRIVATE is deprecated/)
end
- ruby_version_is '2.7' do
- it "does not warn if Warning[:deprecated] is false" do
- @module.deprecate_constant :PUBLIC1
-
- deprecated = Warning[:deprecated]
- begin
- Warning[:deprecated] = false
- -> { @module::PUBLIC1 }.should_not complain
- ensure
- Warning[:deprecated] = deprecated
- end
+ it "does not warn if Warning[:deprecated] is false" do
+ @module.deprecate_constant :PUBLIC1
+
+ deprecated = Warning[:deprecated]
+ begin
+ Warning[:deprecated] = false
+ -> { @module::PUBLIC1 }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
end
end
end
diff --git a/spec/ruby/core/module/extend_object_spec.rb b/spec/ruby/core/module/extend_object_spec.rb
index e66b87efef..1fd1abc0b5 100644
--- a/spec/ruby/core/module/extend_object_spec.rb
+++ b/spec/ruby/core/module/extend_object_spec.rb
@@ -42,20 +42,6 @@ describe "Module#extend_object" do
ScratchPad.recorded.should == :extended
end
- ruby_version_is ''...'2.7' do
- it "does not copy own tainted status to the given object" do
- other = Object.new
- Module.new.taint.send :extend_object, other
- other.tainted?.should be_false
- end
-
- it "does not copy own untrusted status to the given object" do
- other = Object.new
- Module.new.untrust.send :extend_object, other
- other.untrusted?.should be_false
- end
- end
-
describe "when given a frozen object" do
before :each do
@receiver = Module.new
diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb
index ca9106a973..b78bbfcc80 100644
--- a/spec/ruby/core/module/name_spec.rb
+++ b/spec/ruby/core/module/name_spec.rb
@@ -118,27 +118,13 @@ describe "Module#name" do
m::N.name.should == "ModuleSpecs::Anonymous::E::N"
end
- ruby_version_is ""..."2.7" do
- it "returns a mutable string" do
- ModuleSpecs.name.frozen?.should be_false
- end
-
- it "returns a mutable string that when mutated does not modify the original module name" do
- ModuleSpecs.name << "foo"
-
- ModuleSpecs.name.should == "ModuleSpecs"
- end
+ it "returns a frozen String" do
+ ModuleSpecs.name.should.frozen?
end
- ruby_version_is "2.7" do
- it "returns a frozen String" do
- ModuleSpecs.name.should.frozen?
- end
-
- it "always returns the same String for a given Module" do
- s1 = ModuleSpecs.name
- s2 = ModuleSpecs.name
- s1.should equal(s2)
- end
+ it "always returns the same String for a given Module" do
+ s1 = ModuleSpecs.name
+ s2 = ModuleSpecs.name
+ s1.should equal(s2)
end
end
diff --git a/spec/ruby/core/module/prepend_features_spec.rb b/spec/ruby/core/module/prepend_features_spec.rb
index 2d1fa713b7..09c15c5c15 100644
--- a/spec/ruby/core/module/prepend_features_spec.rb
+++ b/spec/ruby/core/module/prepend_features_spec.rb
@@ -28,20 +28,6 @@ describe "Module#prepend_features" do
}.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "copies own tainted status to the given module" do
- other = Module.new
- Module.new.taint.send :prepend_features, other
- other.tainted?.should be_true
- end
-
- it "copies own untrusted status to the given module" do
- other = Module.new
- Module.new.untrust.send :prepend_features, other
- other.untrusted?.should be_true
- end
- end
-
it "clears caches of the given module" do
parent = Class.new do
def bar; :bar; end
diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb
index 56ffc7ead2..841900cf87 100644
--- a/spec/ruby/core/module/refine_spec.rb
+++ b/spec/ruby/core/module/refine_spec.rb
@@ -518,115 +518,55 @@ describe "Module#refine" do
result.should == "hello from refinement"
end
- ruby_version_is "" ... "2.7" do
- it "is not honored by Kernel#method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
+ it "is honored by Kernel#method" do
+ klass = Class.new
+ refinement = Module.new do
+ refine klass do
+ def foo; end
end
-
- -> {
- Module.new do
- using refinement
- klass.new.method(:foo)
- end
- }.should raise_error(NameError, /undefined method `foo'/)
end
- end
-
- ruby_version_is "2.7" do
- it "is honored by Kernel#method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = klass.new.method(:foo).class
- end
- result.should == Method
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.new.method(:foo).class
end
- end
-
- ruby_version_is "" ... "2.7" do
- it "is not honored by Kernel#public_method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
- end
- -> {
- Module.new do
- using refinement
- klass.new.public_method(:foo)
- end
- }.should raise_error(NameError, /undefined method `foo'/)
- end
+ result.should == Method
end
- ruby_version_is "2.7" do
- it "is honored by Kernel#public_method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = klass.new.public_method(:foo).class
+ it "is honored by Kernel#public_method" do
+ klass = Class.new
+ refinement = Module.new do
+ refine klass do
+ def foo; end
end
-
- result.should == Method
end
- end
- ruby_version_is "" ... "2.7" do
- it "is not honored by Kernel#instance_method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
- end
-
- -> {
- Module.new do
- using refinement
- klass.instance_method(:foo)
- end
- }.should raise_error(NameError, /undefined method `foo'/)
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.new.public_method(:foo).class
end
- end
- ruby_version_is "2.7" do
- it "is honored by Kernel#instance_method" do
- klass = Class.new
- refinement = Module.new do
- refine klass do
- def foo; end
- end
- end
+ result.should == Method
+ end
- result = nil
- Module.new do
- using refinement
- result = klass.instance_method(:foo).class
+ it "is honored by Kernel#instance_method" do
+ klass = Class.new
+ refinement = Module.new do
+ refine klass do
+ def foo; end
end
+ end
- result.should == UnboundMethod
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.instance_method(:foo).class
end
+
+ result.should == UnboundMethod
end
it "is honored by Kernel#respond_to?" do
diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb
index 6de3fdec80..80a99e2624 100644
--- a/spec/ruby/core/module/ruby2_keywords_spec.rb
+++ b/spec/ruby/core/module/ruby2_keywords_spec.rb
@@ -1,215 +1,319 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "2.7" do
- describe "Module#ruby2_keywords" do
- it "marks the final hash argument as keyword hash" do
- obj = Object.new
+describe "Module#ruby2_keywords" do
+ class << self
+ ruby2_keywords def mark(*args)
+ args
+ end
+ end
- obj.singleton_class.class_exec do
- def foo(*a) a.last end
- ruby2_keywords :foo
+ it "marks the final hash argument as keyword hash" do
+ last = mark(1, 2, a: "a").last
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ it "makes a copy of the hash and only marks the copy as keyword hash" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def regular(*args)
+ args.last
end
+ end
- last = obj.foo(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ h = {a: 1}
+ ruby_version_is "3.0" do
+ obj.regular(**h).should.equal?(h)
end
- it "makes a copy of the hash and only marks the copy as keyword hash" do
- obj = Object.new
- obj.singleton_class.class_exec do
- def regular(*args)
- args.last
- end
+ last = mark(**h).last
+ Hash.ruby2_keywords_hash?(last).should == true
+ Hash.ruby2_keywords_hash?(h).should == false
- ruby2_keywords def foo(*args)
- args.last
- end
- end
+ last2 = mark(**last).last # last is already marked
+ Hash.ruby2_keywords_hash?(last2).should == true
+ Hash.ruby2_keywords_hash?(last).should == true
+ last2.should_not.equal?(last)
+ Hash.ruby2_keywords_hash?(h).should == false
+ end
- h = {a: 1}
- ruby_version_is "3.0" do
- obj.regular(**h).should.equal?(h)
+ it "makes a copy and unmark the Hash when calling a method taking (arg)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def single(arg)
+ arg
end
+ end
- last = obj.foo(**h)
- Hash.ruby2_keywords_hash?(last).should == true
- Hash.ruby2_keywords_hash?(h).should == false
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ after_usage = obj.single(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+ end
- last2 = obj.foo(**last) # last is already marked
- Hash.ruby2_keywords_hash?(last2).should == true
- Hash.ruby2_keywords_hash?(last).should == true
- last2.should_not.equal?(last)
- Hash.ruby2_keywords_hash?(h).should == false
+ it "makes a copy and unmark the Hash when calling a method taking (**kw)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def kwargs(**kw)
+ kw
+ end
end
- it "makes a copy and unmark at the call site when calling with marked *args" do
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ after_usage = obj.kwargs(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+ end
+
+ ruby_version_is "3.2" do
+ it "makes a copy and unmark the Hash when calling a method taking (*args)" do
obj = Object.new
obj.singleton_class.class_exec do
- ruby2_keywords def foo(*args)
- args
- end
-
- def single(arg)
- arg
+ def splat(*args)
+ args.last
end
- def splat(*args)
+ def splat1(arg, *args)
args.last
end
- def kwargs(**kw)
- kw
+ def proc_call(*args)
+ -> *a { a.last }.call(*args)
end
end
h = { a: 1 }
- args = obj.foo(**h)
+ args = mark(**h)
marked = args.last
Hash.ruby2_keywords_hash?(marked).should == true
- after_usage = obj.single(*args)
+ after_usage = obj.splat(*args)
after_usage.should == h
after_usage.should_not.equal?(h)
after_usage.should_not.equal?(marked)
Hash.ruby2_keywords_hash?(after_usage).should == false
Hash.ruby2_keywords_hash?(marked).should == true
- after_usage = obj.splat(*args)
+ args = mark(1, **h)
+ marked = args.last
+ after_usage = obj.splat1(*args)
after_usage.should == h
after_usage.should_not.equal?(h)
after_usage.should_not.equal?(marked)
- ruby_bug "#18625", ""..."3.3" do # might be fixed in 3.2
- Hash.ruby2_keywords_hash?(after_usage).should == false
- end
+ Hash.ruby2_keywords_hash?(after_usage).should == false
Hash.ruby2_keywords_hash?(marked).should == true
- after_usage = obj.kwargs(*args)
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.proc_call(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.send(:splat, *args)
after_usage.should == h
after_usage.should_not.equal?(h)
after_usage.should_not.equal?(marked)
Hash.ruby2_keywords_hash?(after_usage).should == false
Hash.ruby2_keywords_hash?(marked).should == true
end
+ end
- it "applies to the underlying method and applies across aliasing" do
+ ruby_version_is ""..."3.2" do
+ # https://bugs.ruby-lang.org/issues/18625
+ it "does NOT copy the Hash when calling a method taking (*args)" do
obj = Object.new
-
obj.singleton_class.class_exec do
- def foo(*a) a.last end
- alias_method :bar, :foo
- ruby2_keywords :foo
+ def splat(*args)
+ args.last
+ end
- def baz(*a) a.last end
- ruby2_keywords :baz
- alias_method :bob, :baz
+ def splat1(arg, *args)
+ args.last
+ end
+
+ def proc_call(*args)
+ -> *a { a.last }.call(*args)
+ end
end
- last = obj.foo(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
- last = obj.bar(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ after_usage = obj.splat(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should.equal?(marked) # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(after_usage).should == true # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(marked).should == true
- last = obj.baz(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ args = mark(1, **h)
+ marked = args.last
+ after_usage = obj.splat1(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should.equal?(marked) # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(after_usage).should == true # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(marked).should == true
- last = obj.bob(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.proc_call(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should.equal?(marked) # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(after_usage).should == true # https://bugs.ruby-lang.org/issues/18625
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.send(:splat, *args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ send_copies = RUBY_ENGINE == "ruby" # inconsistent with Proc#call above for CRuby
+ after_usage.equal?(marked).should == !send_copies
+ Hash.ruby2_keywords_hash?(after_usage).should == !send_copies
+ Hash.ruby2_keywords_hash?(marked).should == true
end
+ end
- ruby_version_is "2.7" ... "3.0" do
- it "fixes delegation warnings when calling a method accepting keywords" do
- obj = Object.new
+ it "applies to the underlying method and applies across aliasing" do
+ obj = Object.new
- obj.singleton_class.class_exec do
- def foo(*a) bar(*a) end
- def bar(*a, **b) end
- end
+ obj.singleton_class.class_exec do
+ def foo(*a) a.last end
+ alias_method :bar, :foo
+ ruby2_keywords :foo
- -> { obj.foo(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
+ def baz(*a) a.last end
+ ruby2_keywords :baz
+ alias_method :bob, :baz
+ end
- obj.singleton_class.class_exec do
- ruby2_keywords :foo
- end
+ last = obj.foo(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
- -> { obj.foo(1, 2, {a: "a"}) }.should_not complain
- end
- end
+ last = obj.bar(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
- it "returns nil" do
+ last = obj.baz(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+
+ last = obj.bob(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ ruby_version_is ""..."3.0" do
+ it "fixes delegation warnings when calling a method accepting keywords" do
obj = Object.new
obj.singleton_class.class_exec do
- def foo(*a) end
+ def foo(*a) bar(*a) end
+ def bar(*a, **b) end
+ end
- ruby2_keywords(:foo).should == nil
+ -> { obj.foo(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
+
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
end
+
+ -> { obj.foo(1, 2, {a: "a"}) }.should_not complain
end
+ end
- it "raises NameError when passed not existing method name" do
- obj = Object.new
+ it "returns nil" do
+ obj = Object.new
- -> {
- obj.singleton_class.class_exec do
- ruby2_keywords :not_existing
- end
- }.should raise_error(NameError, /undefined method `not_existing'/)
+ obj.singleton_class.class_exec do
+ def foo(*a) end
+
+ ruby2_keywords(:foo).should == nil
end
+ end
- it "accepts String as well" do
- obj = Object.new
+ it "raises NameError when passed not existing method name" do
+ obj = Object.new
+ -> {
obj.singleton_class.class_exec do
- def foo(*a) a.last end
- ruby2_keywords "foo"
+ ruby2_keywords :not_existing
end
+ }.should raise_error(NameError, /undefined method `not_existing'/)
+ end
- last = obj.foo(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
+ it "accepts String as well" do
+ obj = Object.new
+
+ obj.singleton_class.class_exec do
+ def foo(*a) a.last end
+ ruby2_keywords "foo"
end
- it "raises TypeError when passed not Symbol or String" do
- obj = Object.new
+ last = obj.foo(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
- -> {
- obj.singleton_class.class_exec do
- ruby2_keywords Object.new
- end
- }.should raise_error(TypeError, /is not a symbol nor a string/)
- end
+ it "raises TypeError when passed not Symbol or String" do
+ obj = Object.new
- it "prints warning when a method does not accept argument splat" do
- obj = Object.new
- def obj.foo(a, b, c) end
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords Object.new
+ end
+ }.should raise_error(TypeError, /is not a symbol nor a string/)
+ end
- -> {
- obj.singleton_class.class_exec do
- ruby2_keywords :foo
- end
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ it "prints warning when a method does not accept argument splat" do
+ obj = Object.new
+ def obj.foo(a, b, c) end
- it "prints warning when a method accepts keywords" do
- obj = Object.new
- def obj.foo(a:, b:) end
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
- -> {
- obj.singleton_class.class_exec do
- ruby2_keywords :foo
- end
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ it "prints warning when a method accepts keywords" do
+ obj = Object.new
+ def obj.foo(a:, b:) end
- it "prints warning when a method accepts keyword splat" do
- obj = Object.new
- def obj.foo(**a) end
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
- -> {
- obj.singleton_class.class_exec do
- ruby2_keywords :foo
- end
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ it "prints warning when a method accepts keyword splat" do
+ obj = Object.new
+ def obj.foo(**a) end
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
end
end
diff --git a/spec/ruby/core/nil/to_s_spec.rb b/spec/ruby/core/nil/to_s_spec.rb
index 283d26477a..fa0b929677 100644
--- a/spec/ruby/core/nil/to_s_spec.rb
+++ b/spec/ruby/core/nil/to_s_spec.rb
@@ -5,13 +5,11 @@ describe "NilClass#to_s" do
nil.to_s.should == ""
end
- ruby_version_is "2.7" do
- it "returns a frozen string" do
- nil.to_s.should.frozen?
- end
+ it "returns a frozen string" do
+ nil.to_s.should.frozen?
+ end
- it "always returns the same string" do
- nil.to_s.should equal(nil.to_s)
- end
+ it "always returns the same string" do
+ nil.to_s.should equal(nil.to_s)
end
end
diff --git a/spec/ruby/core/objectspace/weakmap/element_set_spec.rb b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb
index 2b53650148..8588877158 100644
--- a/spec/ruby/core/objectspace/weakmap/element_set_spec.rb
+++ b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb
@@ -17,45 +17,22 @@ describe "ObjectSpace::WeakMap#[]=" do
map[key1].should == ref1
end
- ruby_version_is ""..."2.7" do
- it "does not accept primitive or frozen keys or values" do
- map = ObjectSpace::WeakMap.new
- x = Object.new
- -> { map[true] = x }.should raise_error(ArgumentError)
- -> { map[false] = x }.should raise_error(ArgumentError)
- -> { map[nil] = x }.should raise_error(ArgumentError)
- -> { map[42] = x }.should raise_error(ArgumentError)
- -> { map[:foo] = x }.should raise_error(ArgumentError)
- -> { map[x] = true }.should raise_error(ArgumentError)
- -> { map[x] = false }.should raise_error(ArgumentError)
- -> { map[x] = nil }.should raise_error(ArgumentError)
- -> { map[x] = 42 }.should raise_error(ArgumentError)
- -> { map[x] = :foo }.should raise_error(ArgumentError)
-
- y = Object.new.freeze
- -> { map[x] = y}.should raise_error(FrozenError)
- -> { map[y] = x}.should raise_error(FrozenError)
- end
- end
-
- ruby_version_is "2.7" do
- it "accepts primitive or frozen keys or values" do
- map = ObjectSpace::WeakMap.new
- x = Object.new
- should_accept(map, true, x)
- should_accept(map, false, x)
- should_accept(map, nil, x)
- should_accept(map, 42, x)
- should_accept(map, :foo, x)
+ it "accepts primitive or frozen keys or values" do
+ map = ObjectSpace::WeakMap.new
+ x = Object.new
+ should_accept(map, true, x)
+ should_accept(map, false, x)
+ should_accept(map, nil, x)
+ should_accept(map, 42, x)
+ should_accept(map, :foo, x)
- should_accept(map, x, true)
- should_accept(map, x, false)
- should_accept(map, x, 42)
- should_accept(map, x, :foo)
+ should_accept(map, x, true)
+ should_accept(map, x, false)
+ should_accept(map, x, 42)
+ should_accept(map, x, :foo)
- y = Object.new.freeze
- should_accept(map, x, y)
- should_accept(map, y, x)
- end
+ y = Object.new.freeze
+ should_accept(map, x, y)
+ should_accept(map, y, x)
end
end
diff --git a/spec/ruby/core/objectspace/weakmap/shared/include.rb b/spec/ruby/core/objectspace/weakmap/shared/include.rb
index f9c174b6d1..1770eeac8b 100644
--- a/spec/ruby/core/objectspace/weakmap/shared/include.rb
+++ b/spec/ruby/core/objectspace/weakmap/shared/include.rb
@@ -20,15 +20,11 @@ describe :weakmap_include?, shared: true do
map.send(@method, key2).should == false
end
- ruby_version_is "2.7" do
- ruby_bug "#16826", "2.7.0"..."2.7.2" do
- it "reports true if the pair exists and the value is nil" do
- map = ObjectSpace::WeakMap.new
- key = Object.new
- map[key] = nil
- map.size.should == 1
- map.send(@method, key).should == true
- end
- end
+ it "reports true if the pair exists and the value is nil" do
+ map = ObjectSpace::WeakMap.new
+ key = Object.new
+ map[key] = nil
+ map.size.should == 1
+ map.send(@method, key).should == true
end
end
diff --git a/spec/ruby/core/proc/block_pass_spec.rb b/spec/ruby/core/proc/block_pass_spec.rb
index 99255139d4..411c0bf3db 100644
--- a/spec/ruby/core/proc/block_pass_spec.rb
+++ b/spec/ruby/core/proc/block_pass_spec.rb
@@ -19,25 +19,3 @@ describe "Proc as a block pass argument" do
p.should == p2
end
end
-
-ruby_version_is ""..."2.7" do
- describe "Proc as an implicit block pass argument" do
- def revivify
- Proc.new
- end
-
- it "remains the same object if re-vivified by the target method" do
- p = Proc.new {}
- p2 = revivify(&p)
- p.should equal p2
- p.should == p2
- end
-
- it "remains the same object if reconstructed with Proc.new" do
- p = Proc.new {}
- p2 = Proc.new(&p)
- p.should equal p2
- p.should == p2
- end
- end
-end
diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb
index 6d5eb67a4b..cb52e94f44 100644
--- a/spec/ruby/core/proc/new_spec.rb
+++ b/spec/ruby/core/proc/new_spec.rb
@@ -94,20 +94,6 @@ describe "Proc.new with an associated block" do
obj.first.should == :a
obj.second.should == 2
end
-
- ruby_version_is ""..."2.7" do
- it "returns a new Proc instance from the block passed to the containing method" do
- prc = ProcSpecs.new_proc_in_method { "hello" }
- prc.should be_an_instance_of(Proc)
- prc.call.should == "hello"
- end
-
- it "returns a new Proc instance from the block passed to the containing method" do
- prc = ProcSpecs.new_proc_subclass_in_method { "hello" }
- prc.should be_an_instance_of(ProcSpecs::ProcSubclass)
- prc.call.should == "hello"
- end
- end
end
describe "Proc.new with a block argument" do
@@ -180,30 +166,7 @@ describe "Proc.new without a block" do
-> { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError)
end
- ruby_version_is ""..."2.7" do
- it "uses the implicit block from an enclosing method" do
- def some_method
- Proc.new
- end
-
- prc = some_method { "hello" }
-
- prc.call.should == "hello"
- end
-
- it "uses the implicit block from an enclosing method when called inside a block" do
- def some_method
- proc do |&block|
- Proc.new
- end.call { "failing" }
- end
- prc = some_method { "hello" }
-
- prc.call.should == "hello"
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "can be created if invoked from within a method with a block" do
-> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/)
end
diff --git a/spec/ruby/core/proc/ruby2_keywords_spec.rb b/spec/ruby/core/proc/ruby2_keywords_spec.rb
index 1fba3b9398..c6eb03e693 100644
--- a/spec/ruby/core/proc/ruby2_keywords_spec.rb
+++ b/spec/ruby/core/proc/ruby2_keywords_spec.rb
@@ -1,80 +1,78 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Proc#ruby2_keywords" do
- it "marks the final hash argument as keyword hash" do
- f = -> *a { a.last }
- f.ruby2_keywords
+describe "Proc#ruby2_keywords" do
+ it "marks the final hash argument as keyword hash" do
+ f = -> *a { a.last }
+ f.ruby2_keywords
- last = f.call(1, 2, a: "a")
- Hash.ruby2_keywords_hash?(last).should == true
- end
+ last = f.call(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
- it "applies to the underlying method and applies across duplication" do
- f1 = -> *a { a.last }
- f1.ruby2_keywords
- f2 = f1.dup
+ it "applies to the underlying method and applies across duplication" do
+ f1 = -> *a { a.last }
+ f1.ruby2_keywords
+ f2 = f1.dup
- Hash.ruby2_keywords_hash?(f1.call(1, 2, a: "a")).should == true
- Hash.ruby2_keywords_hash?(f2.call(1, 2, a: "a")).should == true
+ Hash.ruby2_keywords_hash?(f1.call(1, 2, a: "a")).should == true
+ Hash.ruby2_keywords_hash?(f2.call(1, 2, a: "a")).should == true
- f3 = -> *a { a.last }
- f4 = f3.dup
- f3.ruby2_keywords
+ f3 = -> *a { a.last }
+ f4 = f3.dup
+ f3.ruby2_keywords
- Hash.ruby2_keywords_hash?(f3.call(1, 2, a: "a")).should == true
- Hash.ruby2_keywords_hash?(f4.call(1, 2, a: "a")).should == true
- end
+ Hash.ruby2_keywords_hash?(f3.call(1, 2, a: "a")).should == true
+ Hash.ruby2_keywords_hash?(f4.call(1, 2, a: "a")).should == true
+ end
- ruby_version_is "2.7" ... "3.0" do
- it "fixes delegation warnings when calling a method accepting keywords" do
- obj = Object.new
- def obj.foo(*a, **b) end
+ ruby_version_is ""..."3.0" do
+ it "fixes delegation warnings when calling a method accepting keywords" do
+ obj = Object.new
+ def obj.foo(*a, **b) end
- f = -> *a { obj.foo(*a) }
+ f = -> *a { obj.foo(*a) }
- -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
- f.ruby2_keywords
- -> { f.call(1, 2, {a: "a"}) }.should_not complain
- end
+ -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
+ f.ruby2_keywords
+ -> { f.call(1, 2, {a: "a"}) }.should_not complain
+ end
- it "fixes delegation warnings when calling a proc accepting keywords" do
- g = -> *a, **b { }
- f = -> *a { g.call(*a) }
+ it "fixes delegation warnings when calling a proc accepting keywords" do
+ g = -> *a, **b { }
+ f = -> *a { g.call(*a) }
- -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
- f.ruby2_keywords
- -> { f.call(1, 2, {a: "a"}) }.should_not complain
- end
+ -> { f.call(1, 2, {a: "a"}) }.should complain(/Using the last argument as keyword parameters is deprecated/)
+ f.ruby2_keywords
+ -> { f.call(1, 2, {a: "a"}) }.should_not complain
end
+ end
- it "returns self" do
- f = -> *a { }
- f.ruby2_keywords.should equal f
- end
+ it "returns self" do
+ f = -> *a { }
+ f.ruby2_keywords.should equal f
+ end
- it "prints warning when a proc does not accept argument splat" do
- f = -> a, b, c { }
+ it "prints warning when a proc does not accept argument splat" do
+ f = -> a, b, c { }
- -> {
- f.ruby2_keywords
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
- it "prints warning when a proc accepts keywords" do
- f = -> a:, b: { }
+ it "prints warning when a proc accepts keywords" do
+ f = -> a:, b: { }
- -> {
- f.ruby2_keywords
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
- it "prints warning when a proc accepts keyword splat" do
- f = -> **a { }
+ it "prints warning when a proc accepts keyword splat" do
+ f = -> **a { }
- -> {
- f.ruby2_keywords
- }.should complain(/Skipping set of ruby2_keywords flag for/)
- end
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
end
end
diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb
index e3ae7f76b8..3d3f3b310d 100644
--- a/spec/ruby/core/proc/shared/compose.rb
+++ b/spec/ruby/core/proc/shared/compose.rb
@@ -1,47 +1,22 @@
describe :proc_compose, shared: true do
- ruby_version_is ""..."2.7" do
- it "raises NoMethodError when called if passed not callable object" do
- not_callable = Object.new
- composed = @object.call.send(@method, not_callable)
+ it "raises TypeError if passed not callable object" do
+ lhs = @object.call
+ not_callable = Object.new
- -> {
- composed.call('a')
- }.should raise_error(NoMethodError, /undefined method `call' for/)
+ -> {
+ lhs.send(@method, not_callable)
+ }.should raise_error(TypeError, "callable object is expected")
- end
-
- it "when called does not try to coerce argument with #to_proc" do
- succ = Object.new
- def succ.to_proc(s); s.succ; end
-
- composed = @object.call.send(@method, succ)
-
- -> {
- composed.call('a')
- }.should raise_error(NoMethodError, /undefined method `call' for/)
- end
end
- ruby_version_is "2.7" do # https://bugs.ruby-lang.org/issues/15428
- it "raises TypeError if passed not callable object" do
- lhs = @object.call
- not_callable = Object.new
-
- -> {
- lhs.send(@method, not_callable)
- }.should raise_error(TypeError, "callable object is expected")
-
- end
-
- it "does not try to coerce argument with #to_proc" do
- lhs = @object.call
+ it "does not try to coerce argument with #to_proc" do
+ lhs = @object.call
- succ = Object.new
- def succ.to_proc(s); s.succ; end
+ succ = Object.new
+ def succ.to_proc(s); s.succ; end
- -> {
- lhs.send(@method, succ)
- }.should raise_error(TypeError, "callable object is expected")
- end
+ -> {
+ lhs.send(@method, succ)
+ }.should raise_error(TypeError, "callable object is expected")
end
end
diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb
index 7f167a3d9d..f1e2f416fc 100644
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ b/spec/ruby/core/proc/shared/to_s.rb
@@ -1,9 +1,7 @@
describe :proc_to_s, shared: true do
- sep = ruby_version_is("2.7") ? " " : "@"
-
describe "for a proc created with Proc.new" do
it "returns a description including file and line number" do
- Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
end
it "has a binary encoding" do
@@ -13,7 +11,7 @@ describe :proc_to_s, shared: true do
describe "for a proc created with lambda" do
it "returns a description including '(lambda)' and including file and line number" do
- -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
+ -> { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
end
it "has a binary encoding" do
@@ -23,7 +21,7 @@ describe :proc_to_s, shared: true do
describe "for a proc created with proc" do
it "returns a description including file and line number" do
- proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
end
it "has a binary encoding" do
@@ -36,7 +34,7 @@ describe :proc_to_s, shared: true do
def hello; end
s = method("hello").to_proc.send(@method)
if s.include? __FILE__
- s.should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
+ s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
else
s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/
end
diff --git a/spec/ruby/core/process/wait2_spec.rb b/spec/ruby/core/process/wait2_spec.rb
index 6eb7fc6d06..673d3cdb9d 100644
--- a/spec/ruby/core/process/wait2_spec.rb
+++ b/spec/ruby/core/process/wait2_spec.rb
@@ -33,4 +33,13 @@ describe "Process.wait2" do
-> { Process.wait2 }.should raise_error(Errno::ECHILD)
-> { Process.wait2 }.should raise_error(StandardError)
end
+
+ it "returns nil if the child process is still running when given the WNOHANG flag" do
+ IO.popen(ruby_cmd('STDIN.getbyte'), "w") do |io|
+ pid, status = Process.wait2(io.pid, Process::WNOHANG)
+ pid.should be_nil
+ status.should be_nil
+ io.write('a')
+ end
+ end
end
diff --git a/spec/ruby/core/range/bsearch_spec.rb b/spec/ruby/core/range/bsearch_spec.rb
index 438c7ce314..9c93671d85 100644
--- a/spec/ruby/core/range/bsearch_spec.rb
+++ b/spec/ruby/core/range/bsearch_spec.rb
@@ -330,108 +330,106 @@ describe "Range#bsearch" do
end
- ruby_version_is "2.7" do
- context "with beginless ranges and Integer values" do
- context "with a block returning true or false" do
- it "returns the smallest element for which block returns true" do
- eval("(..10)").bsearch { |x| x >= 2 }.should == 2
- eval("(...-1)").bsearch { |x| x >= -10 }.should == -10
- end
- end
-
- context "with a block returning negative, zero, positive numbers" do
- it "returns nil if the block returns greater than zero for every element" do
- eval("(..0)").bsearch { |x| 1 }.should be_nil
- end
-
- it "returns nil if the block never returns zero" do
- eval("(..0)").bsearch { |x| x > 5 ? -1 : 1 }.should be_nil
- end
-
- it "accepts Float::INFINITY from the block" do
- eval("(..0)").bsearch { |x| Float::INFINITY }.should be_nil
- end
-
- it "returns an element at an index for which block returns 0.0" do
- result = eval("(..10)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
- result.should == 2
- end
-
- it "returns an element at an index for which block returns 0" do
- result = eval("(...10)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- [1, 2, 3].should include(result)
- end
+ context "with beginless ranges and Integer values" do
+ context "with a block returning true or false" do
+ it "returns the smallest element for which block returns true" do
+ (..10).bsearch { |x| x >= 2 }.should == 2
+ (...-1).bsearch { |x| x >= -10 }.should == -10
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns greater than zero for every element" do
+ (..0).bsearch { |x| 1 }.should be_nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ (..0).bsearch { |x| x > 5 ? -1 : 1 }.should be_nil
+ end
+
+ it "accepts Float::INFINITY from the block" do
+ (..0).bsearch { |x| Float::INFINITY }.should be_nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = (..10).bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = (...10).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ [1, 2, 3].should include(result)
end
end
+ end
+
+ context "with beginless ranges and Float values" do
+ context "with a block returning true or false" do
+ it "returns nil if the block returns true for every element" do
+ (..-0.1).bsearch { |x| x > 0.0 }.should be_nil
+ (...-0.1).bsearch { |x| x > 0.0 }.should be_nil
+ end
+
+ it "returns nil if the block returns nil for every element" do
+ (..-0.1).bsearch { |x| nil }.should be_nil
+ (...-0.1).bsearch { |x| nil }.should be_nil
+ end
+
+ it "returns the smallest element for which block returns true" do
+ (..10).bsearch { |x| x >= 2 }.should == 2
+ (..10).bsearch { |x| x >= 1 }.should == 1
+ end
- context "with beginless ranges and Float values" do
- context "with a block returning true or false" do
- it "returns nil if the block returns true for every element" do
- eval("(..-0.1)").bsearch { |x| x > 0.0 }.should be_nil
- eval("(...-0.1)").bsearch { |x| x > 0.0 }.should be_nil
- end
-
- it "returns nil if the block returns nil for every element" do
- eval("(..-0.1)").bsearch { |x| nil }.should be_nil
- eval("(...-0.1)").bsearch { |x| nil }.should be_nil
- end
-
- it "returns the smallest element for which block returns true" do
- eval("(..10)").bsearch { |x| x >= 2 }.should == 2
- eval("(..10)").bsearch { |x| x >= 1 }.should == 1
- end
-
- it "works with infinity bounds" do
- inf = Float::INFINITY
- eval("(..inf)").bsearch { |x| true }.should == -inf
- eval("(...inf)").bsearch { |x| true }.should == -inf
- eval("(..-inf)").bsearch { |x| true }.should == -inf
- eval("(...-inf)").bsearch { |x| true }.should == nil
- end
- end
-
- context "with a block returning negative, zero, positive numbers" do
- it "returns nil if the block returns less than zero for every element" do
- eval("(..5.0)").bsearch { |x| -1 }.should be_nil
- eval("(...5.0)").bsearch { |x| -1 }.should be_nil
- end
-
- it "returns nil if the block returns greater than zero for every element" do
- eval("(..1.1)").bsearch { |x| 1 }.should be_nil
- eval("(...1.1)").bsearch { |x| 1 }.should be_nil
- end
-
- it "returns nil if the block never returns zero" do
- eval("(..6.3)").bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
- end
-
- it "accepts (+/-)Float::INFINITY from the block" do
- eval("(..5.0)").bsearch { |x| Float::INFINITY }.should be_nil
- eval("(..7.0)").bsearch { |x| -Float::INFINITY }.should be_nil
- end
-
- it "returns an element at an index for which block returns 0.0" do
- result = eval("(..8.0)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
- result.should == 2
- end
-
- it "returns an element at an index for which block returns 0" do
- result = eval("(..8.0)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- result.should >= 1
- result.should <= 3
- end
-
- it "works with infinity bounds" do
- inf = Float::INFINITY
- eval("(..-inf)").bsearch { |x| 1 }.should == nil
- eval("(...-inf)").bsearch { |x| 1 }.should == nil
- eval("(..inf)").bsearch { |x| x == inf ? 0 : 1 }.should == inf
- eval("(...inf)").bsearch { |x| x == inf ? 0 : 1 }.should == nil
- eval("(..-inf)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
- eval("(...-inf)").bsearch { |x| x == -inf ? 0 : -1 }.should == nil
- eval("(..inf)").bsearch { |x| 3 - x }.should == 3
- eval("(...inf)").bsearch { |x| 3 - x }.should == 3
- end
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (..inf).bsearch { |x| true }.should == -inf
+ (...inf).bsearch { |x| true }.should == -inf
+ (..-inf).bsearch { |x| true }.should == -inf
+ (...-inf).bsearch { |x| true }.should == nil
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ (..5.0).bsearch { |x| -1 }.should be_nil
+ (...5.0).bsearch { |x| -1 }.should be_nil
+ end
+
+ it "returns nil if the block returns greater than zero for every element" do
+ (..1.1).bsearch { |x| 1 }.should be_nil
+ (...1.1).bsearch { |x| 1 }.should be_nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ (..6.3).bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
+ end
+
+ it "accepts (+/-)Float::INFINITY from the block" do
+ (..5.0).bsearch { |x| Float::INFINITY }.should be_nil
+ (..7.0).bsearch { |x| -Float::INFINITY }.should be_nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = (..8.0).bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = (..8.0).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ result.should >= 1
+ result.should <= 3
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (..-inf).bsearch { |x| 1 }.should == nil
+ (...-inf).bsearch { |x| 1 }.should == nil
+ (..inf).bsearch { |x| x == inf ? 0 : 1 }.should == inf
+ (...inf).bsearch { |x| x == inf ? 0 : 1 }.should == nil
+ (..-inf).bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ (...-inf).bsearch { |x| x == -inf ? 0 : -1 }.should == nil
+ (..inf).bsearch { |x| 3 - x }.should == 3
+ (...inf).bsearch { |x| 3 - x }.should == 3
end
end
end
diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb
index e795026230..4a3faa3163 100644
--- a/spec/ruby/core/range/case_compare_spec.rb
+++ b/spec/ruby/core/range/case_compare_spec.rb
@@ -8,8 +8,6 @@ describe "Range#===" do
(range === RangeSpecs::WithoutSucc.new(2)).should == true
end
- ruby_version_is "2.7" do
- it_behaves_like :range_cover_and_include, :===
- it_behaves_like :range_cover, :===
- end
+ it_behaves_like :range_cover_and_include, :===
+ it_behaves_like :range_cover, :===
end
diff --git a/spec/ruby/core/range/count_spec.rb b/spec/ruby/core/range/count_spec.rb
index f6f60fa054..24d4a9caf3 100644
--- a/spec/ruby/core/range/count_spec.rb
+++ b/spec/ruby/core/range/count_spec.rb
@@ -1,14 +1,12 @@
require_relative '../../spec_helper'
describe "Range#count" do
- ruby_version_is "2.7" do
- it "returns Infinity for beginless ranges without arguments or blocks" do
- inf = Float::INFINITY
- eval("('a'...)").count.should == inf
- eval("(7..)").count.should == inf
- eval("(...'a')").count.should == inf
- eval("(...nil)").count.should == inf
- eval("(..10.0)").count.should == inf
- end
+ it "returns Infinity for beginless ranges without arguments or blocks" do
+ inf = Float::INFINITY
+ eval("('a'...)").count.should == inf
+ eval("(7..)").count.should == inf
+ (...'a').count.should == inf
+ (...nil).count.should == inf
+ (..10.0).count.should == inf
end
end
diff --git a/spec/ruby/core/range/each_spec.rb b/spec/ruby/core/range/each_spec.rb
index 6b33f57737..ecae17c881 100644
--- a/spec/ruby/core/range/each_spec.rb
+++ b/spec/ruby/core/range/each_spec.rb
@@ -58,10 +58,8 @@ describe "Range#each" do
a.should == ["A", "B", "C", "D"]
end
- ruby_version_is "2.7" do
- it "raises a TypeError beginless ranges" do
- -> { eval("(..2)").each { |x| x } }.should raise_error(TypeError)
- end
+ it "raises a TypeError beginless ranges" do
+ -> { (..2).each { |x| x } }.should raise_error(TypeError)
end
it "raises a TypeError if the first element does not respond to #succ" do
diff --git a/spec/ruby/core/range/equal_value_spec.rb b/spec/ruby/core/range/equal_value_spec.rb
index 0aaebfb59a..83dcf5cec8 100644
--- a/spec/ruby/core/range/equal_value_spec.rb
+++ b/spec/ruby/core/range/equal_value_spec.rb
@@ -12,9 +12,7 @@ describe "Range#==" do
eval("(1.0..)").should == eval("(1.0..)")
end
- ruby_version_is "2.7" do
- it "returns true if the endpoints are == for beginless ranges" do
- eval("(...10)").should == eval("(...10)")
- end
+ it "returns true if the endpoints are == for beginless ranges" do
+ (...10).should == (...10)
end
end
diff --git a/spec/ruby/core/range/first_spec.rb b/spec/ruby/core/range/first_spec.rb
index c5c90800ac..2af935f439 100644
--- a/spec/ruby/core/range/first_spec.rb
+++ b/spec/ruby/core/range/first_spec.rb
@@ -47,9 +47,7 @@ describe "Range#first" do
-> { (2..3).first("1") }.should raise_error(TypeError)
end
- ruby_version_is "2.7" do
- it "raises a RangeError when called on an beginless range" do
- -> { eval("(..1)").first }.should raise_error(RangeError)
- end
+ it "raises a RangeError when called on an beginless range" do
+ -> { (..1).first }.should raise_error(RangeError)
end
end
diff --git a/spec/ruby/core/range/frozen_spec.rb b/spec/ruby/core/range/frozen_spec.rb
index 9a3e6eb373..298ffc87cb 100644
--- a/spec/ruby/core/range/frozen_spec.rb
+++ b/spec/ruby/core/range/frozen_spec.rb
@@ -6,7 +6,7 @@ describe "Range#frozen?" do
it "is true for literal ranges" do
(1..2).should.frozen?
(1..).should.frozen?
- eval("(..1)").should.frozen?
+ (..1).should.frozen?
end
it "is true for Range.new" do
diff --git a/spec/ruby/core/range/inspect_spec.rb b/spec/ruby/core/range/inspect_spec.rb
index f49882e6ce..072de123b7 100644
--- a/spec/ruby/core/range/inspect_spec.rb
+++ b/spec/ruby/core/range/inspect_spec.rb
@@ -17,29 +17,13 @@ describe "Range#inspect" do
eval("(0.1...)").inspect.should == "0.1..."
end
- ruby_version_is '2.7' do
- it "works for beginless ranges" do
- eval("(..1)").inspect.should == "..1"
- eval("(...0.1)").inspect.should == "...0.1"
- end
-
- it "works for nil ... nil ranges" do
- eval("(..nil)").inspect.should == "nil..nil"
- eval("(nil...)").inspect.should == "nil...nil"
- end
+ it "works for beginless ranges" do
+ (..1).inspect.should == "..1"
+ (...0.1).inspect.should == "...0.1"
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if either end is tainted" do
- (("a".taint)..."c").inspect.tainted?.should be_true
- ("a"...("c".taint)).inspect.tainted?.should be_true
- ("a"..."c").taint.inspect.tainted?.should be_true
- end
-
- it "returns a untrusted string if either end is untrusted" do
- (("a".untrust)..."c").inspect.untrusted?.should be_true
- ("a"...("c".untrust)).inspect.untrusted?.should be_true
- ("a"..."c").untrust.inspect.untrusted?.should be_true
- end
+ it "works for nil ... nil ranges" do
+ (..nil).inspect.should == "nil..nil"
+ eval("(nil...)").inspect.should == "nil...nil"
end
end
diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb
index a970144d66..6c9ada2a3c 100644
--- a/spec/ruby/core/range/max_spec.rb
+++ b/spec/ruby/core/range/max_spec.rb
@@ -52,13 +52,13 @@ describe "Range#max" do
ruby_version_is "3.0" do
it "returns the end point for beginless ranges" do
- eval("(..1)").max.should == 1
- eval("(..1.0)").max.should == 1.0
+ (..1).max.should == 1
+ (..1.0).max.should == 1.0
end
it "raises for an exclusive beginless range" do
-> {
- eval("(...1)").max
+ (...1).max
}.should raise_error(TypeError, 'cannot exclude end value with non Integer begin value')
end
end
@@ -97,9 +97,7 @@ describe "Range#max given a block" do
(5...5).max {|x,y| x <=> y}.should be_nil
end
- ruby_version_is "2.7" do
- it "raises RangeError when called with custom comparison method on an beginless range" do
- -> { eval("(..1)").max {|a, b| a} }.should raise_error(RangeError)
- end
+ it "raises RangeError when called with custom comparison method on an beginless range" do
+ -> { (..1).max {|a, b| a} }.should raise_error(RangeError)
end
end
diff --git a/spec/ruby/core/range/min_spec.rb b/spec/ruby/core/range/min_spec.rb
index 6e56cc733b..89310ee589 100644
--- a/spec/ruby/core/range/min_spec.rb
+++ b/spec/ruby/core/range/min_spec.rb
@@ -44,10 +44,8 @@ describe "Range#min" do
eval("(1.0...)").min.should == 1.0
end
- ruby_version_is "2.7" do
- it "raises RangeError when called on an beginless range" do
- -> { eval("(..1)").min }.should raise_error(RangeError)
- end
+ it "raises RangeError when called on an beginless range" do
+ -> { (..1).min }.should raise_error(RangeError)
end
end
diff --git a/spec/ruby/core/range/minmax_spec.rb b/spec/ruby/core/range/minmax_spec.rb
index 1db9bfce38..b2b4fd61a1 100644
--- a/spec/ruby/core/range/minmax_spec.rb
+++ b/spec/ruby/core/range/minmax_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
-# These specs use Range.new instead of the literal notation for beginless Ranges so they parse fine on Ruby < 2.7
describe 'Range#minmax' do
before(:each) do
@x = mock('x')
@@ -13,37 +12,26 @@ describe 'Range#minmax' do
end
describe 'on an inclusive range' do
- ruby_version_is ''...'2.7' do
- it 'should try to iterate endlessly on an endless range' do
- @x.should_receive(:succ).once.and_return(@y)
- range = (@x..)
-
- -> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
- end
- end
-
- ruby_version_is '2.7' do
- it 'should raise RangeError on an endless range without iterating the range' do
- @x.should_not_receive(:succ)
+ it 'should raise RangeError on an endless range without iterating the range' do
+ @x.should_not_receive(:succ)
- range = (@x..)
+ range = (@x..)
- -> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
- end
+ -> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
+ end
- it 'raises RangeError or ArgumentError on a beginless range' do
- range = Range.new(nil, @x)
-
- -> { range.minmax }.should raise_error(StandardError) { |e|
- if RangeError === e
- # error from #min
- -> { raise e }.should raise_error(RangeError, 'cannot get the minimum of beginless range')
- else
- # error from #max
- -> { raise e }.should raise_error(ArgumentError, 'comparison of NilClass with MockObject failed')
- end
- }
- end
+ it 'raises RangeError or ArgumentError on a beginless range' do
+ range = (..@x)
+
+ -> { range.minmax }.should raise_error(StandardError) { |e|
+ if RangeError === e
+ # error from #min
+ -> { raise e }.should raise_error(RangeError, 'cannot get the minimum of beginless range')
+ else
+ # error from #max
+ -> { raise e }.should raise_error(ArgumentError, 'comparison of NilClass with MockObject failed')
+ end
+ }
end
it 'should return beginning of range if beginning and end are equal without iterating the range' do
@@ -58,34 +46,22 @@ describe 'Range#minmax' do
(@y..@x).minmax.should == [nil, nil]
end
- ruby_version_is ''...'2.7' do
- it 'should return the minimum and maximum values for a non-numeric range by iterating the range' do
- @x.should_receive(:succ).once.and_return(@y)
-
- (@x..@y).minmax.should == [@x, @y]
- end
- end
-
- ruby_version_is '2.7' do
- it 'should return the minimum and maximum values for a non-numeric range without iterating the range' do
- @x.should_not_receive(:succ)
+ it 'should return the minimum and maximum values for a non-numeric range without iterating the range' do
+ @x.should_not_receive(:succ)
- (@x..@y).minmax.should == [@x, @y]
- end
+ (@x..@y).minmax.should == [@x, @y]
end
it 'should return the minimum and maximum values for a numeric range' do
(1..3).minmax.should == [1, 3]
end
- ruby_version_is '2.7' do
- it 'should return the minimum and maximum values for a numeric range without iterating the range' do
- # We cannot set expectations on integers,
- # so we "prevent" iteration by picking a value that would iterate until the spec times out.
- range_end = Float::INFINITY
+ it 'should return the minimum and maximum values for a numeric range without iterating the range' do
+ # We cannot set expectations on integers,
+ # so we "prevent" iteration by picking a value that would iterate until the spec times out.
+ range_end = Float::INFINITY
- (1..range_end).minmax.should == [1, range_end]
- end
+ (1..range_end).minmax.should == [1, range_end]
end
it 'should return the minimum and maximum values according to the provided block by iterating the range' do
@@ -96,33 +72,21 @@ describe 'Range#minmax' do
end
describe 'on an exclusive range' do
- ruby_version_is ''...'2.7' do
- # Endless ranges introduced in 2.6
- it 'should try to iterate endlessly on an endless range' do
- @x.should_receive(:succ).once.and_return(@y)
- range = (@x...)
+ it 'should raise RangeError on an endless range' do
+ @x.should_not_receive(:succ)
+ range = (@x...)
- -> { range.minmax }.should raise_error(NoMethodError, /^undefined method `succ' for/)
- end
+ -> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
end
- ruby_version_is '2.7' do
- it 'should raise RangeError on an endless range' do
- @x.should_not_receive(:succ)
- range = (@x...)
+ it 'should raise RangeError on a beginless range' do
+ range = (...@x)
- -> { range.minmax }.should raise_error(RangeError, 'cannot get the maximum of endless range')
- end
-
- it 'should raise RangeError on a beginless range' do
- range = Range.new(nil, @x, true)
-
- -> { range.minmax }.should raise_error(RangeError,
- /cannot get the maximum of beginless range with custom comparison method|cannot get the minimum of beginless range/)
- end
+ -> { range.minmax }.should raise_error(RangeError,
+ /cannot get the maximum of beginless range with custom comparison method|cannot get the minimum of beginless range/)
end
- ruby_bug "#17014", "2.7.0"..."3.0" do
+ ruby_bug "#17014", ""..."3.0" do
it 'should return nil pair if beginning and end are equal without iterating the range' do
@x.should_not_receive(:succ)
@@ -146,19 +110,17 @@ describe 'Range#minmax' do
(1...3).minmax.should == [1, 2]
end
- ruby_version_is '2.7' do
- it 'should return the minimum and maximum values for a numeric range without iterating the range' do
- # We cannot set expectations on integers,
- # so we "prevent" iteration by picking a value that would iterate until the spec times out.
- range_end = bignum_value
+ it 'should return the minimum and maximum values for a numeric range without iterating the range' do
+ # We cannot set expectations on integers,
+ # so we "prevent" iteration by picking a value that would iterate until the spec times out.
+ range_end = bignum_value
- (1...range_end).minmax.should == [1, range_end - 1]
- end
+ (1...range_end).minmax.should == [1, range_end - 1]
+ end
- it 'raises TypeError if the end value is not an integer' do
- range = (0...Float::INFINITY)
- -> { range.minmax }.should raise_error(TypeError, 'cannot exclude non Integer end value')
- end
+ it 'raises TypeError if the end value is not an integer' do
+ range = (0...Float::INFINITY)
+ -> { range.minmax }.should raise_error(TypeError, 'cannot exclude non Integer end value')
end
it 'should return the minimum and maximum values according to the provided block by iterating the range' do
diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb
index a4de4963e7..85e99babff 100644
--- a/spec/ruby/core/range/new_spec.rb
+++ b/spec/ruby/core/range/new_spec.rb
@@ -42,24 +42,16 @@ describe "Range.new" do
end
describe "beginless/endless range" do
- ruby_version_is ""..."2.7" do
- it "does not allow range without left boundary" do
- -> { Range.new(nil, 1) }.should raise_error(ArgumentError, /bad value for range/)
- end
+ it "allows beginless left boundary" do
+ range = Range.new(nil, 1)
+ range.begin.should == nil
end
- ruby_version_is "2.7" do
- it "allows beginless left boundary" do
- range = Range.new(nil, 1)
- range.begin.should == nil
- end
-
- it "distinguishes ranges with included and excluded right boundary" do
- range_exclude = Range.new(nil, 1, true)
- range_include = Range.new(nil, 1, false)
+ it "distinguishes ranges with included and excluded right boundary" do
+ range_exclude = Range.new(nil, 1, true)
+ range_include = Range.new(nil, 1, false)
- range_exclude.should_not == range_include
- end
+ range_exclude.should_not == range_include
end
it "allows endless right boundary" do
diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb
index f3c7d22668..0b41a26455 100644
--- a/spec/ruby/core/range/shared/cover.rb
+++ b/spec/ruby/core/range/shared/cover.rb
@@ -151,45 +151,43 @@ describe :range_cover_subrange, shared: true do
end
end
- ruby_version_is "2.7" do
- it "allows self to be a beginless range" do
- eval("(...10)").send(@method, (3..7)).should be_true
- eval("(...10)").send(@method, (3..15)).should be_false
+ it "allows self to be a beginless range" do
+ (...10).send(@method, (3..7)).should be_true
+ (...10).send(@method, (3..15)).should be_false
- eval("(..7.9)").send(@method, (2.5..6.5)).should be_true
- eval("(..7.9)").send(@method, (2.5..8.5)).should be_false
+ (..7.9).send(@method, (2.5..6.5)).should be_true
+ (..7.9).send(@method, (2.5..8.5)).should be_false
- eval("(..'i')").send(@method, ('d'..'f')).should be_true
- eval("(..'i')").send(@method, ('d'..'z')).should be_false
- end
+ (..'i').send(@method, ('d'..'f')).should be_true
+ (..'i').send(@method, ('d'..'z')).should be_false
+ end
- it "allows self to be a endless range" do
- eval("(0...)").send(@method, (3..7)).should be_true
- eval("(5...)").send(@method, (3..15)).should be_false
+ it "allows self to be a endless range" do
+ eval("(0...)").send(@method, (3..7)).should be_true
+ eval("(5...)").send(@method, (3..15)).should be_false
- eval("(1.1..)").send(@method, (2.5..6.5)).should be_true
- eval("(3.3..)").send(@method, (2.5..8.5)).should be_false
+ eval("(1.1..)").send(@method, (2.5..6.5)).should be_true
+ eval("(3.3..)").send(@method, (2.5..8.5)).should be_false
- eval("('a'..)").send(@method, ('d'..'f')).should be_true
- eval("('p'..)").send(@method, ('d'..'z')).should be_false
- end
+ eval("('a'..)").send(@method, ('d'..'f')).should be_true
+ eval("('p'..)").send(@method, ('d'..'z')).should be_false
+ end
- it "accepts beginless range argument" do
- eval("(..10)").send(@method, eval("(...10)")).should be_true
- (0..10).send(@method, eval("(...10)")).should be_false
+ it "accepts beginless range argument" do
+ (..10).send(@method, (...10)).should be_true
+ (0..10).send(@method, (...10)).should be_false
- (1.1..7.9).send(@method, eval("(...10.5)")).should be_false
+ (1.1..7.9).send(@method, (...10.5)).should be_false
- ('c'..'i').send(@method, eval("(..'i')")).should be_false
- end
+ ('c'..'i').send(@method, (..'i')).should be_false
+ end
- it "accepts endless range argument" do
- eval("(0..)").send(@method, eval("(0...)")).should be_true
- (0..10).send(@method, eval("(0...)")).should be_false
+ it "accepts endless range argument" do
+ eval("(0..)").send(@method, eval("(0...)")).should be_true
+ (0..10).send(@method, eval("(0...)")).should be_false
- (1.1..7.9).send(@method, eval("(0.8...)")).should be_false
+ (1.1..7.9).send(@method, eval("(0.8...)")).should be_false
- ('c'..'i').send(@method, eval("('a'..)")).should be_false
- end
+ ('c'..'i').send(@method, eval("('a'..)")).should be_false
end
end
diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb
index e978e39af5..7028afaa89 100644
--- a/spec/ruby/core/range/shared/cover_and_include.rb
+++ b/spec/ruby/core/range/shared/cover_and_include.rb
@@ -24,11 +24,9 @@ describe :range_cover_and_include, shared: true do
eval("(0.5...)").send(@method, 2.4).should == true
end
- ruby_version_is "2.7" do
- it "returns true if other is an element of self for beginless ranges" do
- eval("(..10)").send(@method, 2.4).should == true
- eval("(...10.5)").send(@method, 2.4).should == true
- end
+ it "returns true if other is an element of self for beginless ranges" do
+ (..10).send(@method, 2.4).should == true
+ (...10.5).send(@method, 2.4).should == true
end
it "compares values using <=>" do
diff --git a/spec/ruby/core/range/size_spec.rb b/spec/ruby/core/range/size_spec.rb
index 0019c5ff00..5462a1a5e1 100644
--- a/spec/ruby/core/range/size_spec.rb
+++ b/spec/ruby/core/range/size_spec.rb
@@ -34,13 +34,11 @@ describe "Range#size" do
eval("([]...)").size.should == nil
end
- ruby_version_is "2.7" do
- it 'returns Float::INFINITY for all beginless ranges' do
- eval("(..1)").size.should == Float::INFINITY
- eval("(...0.5)").size.should == Float::INFINITY
- eval("(..nil)").size.should == Float::INFINITY
- eval("(...'o')").size.should == Float::INFINITY
- end
+ it 'returns Float::INFINITY for all beginless ranges' do
+ (..1).size.should == Float::INFINITY
+ (...0.5).size.should == Float::INFINITY
+ (..nil).size.should == Float::INFINITY
+ (...'o').size.should == Float::INFINITY
end
it "returns nil if first and last are not Numeric" do
diff --git a/spec/ruby/core/range/step_spec.rb b/spec/ruby/core/range/step_spec.rb
index 4c69073854..61ddc5205d 100644
--- a/spec/ruby/core/range/step_spec.rb
+++ b/spec/ruby/core/range/step_spec.rb
@@ -481,11 +481,9 @@ describe "Range#step" do
end
end
- ruby_version_is "2.7" do
- context "when begin is not defined and end is numeric" do
- it "returns an instance of Enumerator::ArithmeticSequence" do
- eval("(..10)").step.class.should == Enumerator::ArithmeticSequence
- end
+ context "when begin is not defined and end is numeric" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ (..10).step.class.should == Enumerator::ArithmeticSequence
end
end
@@ -499,11 +497,9 @@ describe "Range#step" do
end
end
- ruby_version_is "2.7" do
- context "when range is beginless and endless" do
- it "returns an instance of Enumerator" do
- Range.new(nil, nil).step.class.should == Enumerator
- end
+ context "when range is beginless and endless" do
+ it "returns an instance of Enumerator" do
+ Range.new(nil, nil).step.class.should == Enumerator
end
end
diff --git a/spec/ruby/core/range/to_a_spec.rb b/spec/ruby/core/range/to_a_spec.rb
index 52ebc02941..b1d3de32db 100644
--- a/spec/ruby/core/range/to_a_spec.rb
+++ b/spec/ruby/core/range/to_a_spec.rb
@@ -33,9 +33,7 @@ describe "Range#to_a" do
-> { eval("(1..)").to_a }.should raise_error(RangeError)
end
- ruby_version_is "2.7" do
- it "throws an exception for beginless ranges" do
- -> { eval("(..1)").to_a }.should raise_error(TypeError)
- end
+ it "throws an exception for beginless ranges" do
+ -> { (..1).to_a }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/core/range/to_s_spec.rb b/spec/ruby/core/range/to_s_spec.rb
index 581c2e7d90..460c330912 100644
--- a/spec/ruby/core/range/to_s_spec.rb
+++ b/spec/ruby/core/range/to_s_spec.rb
@@ -16,24 +16,8 @@ describe "Range#to_s" do
eval("(1.0...)").to_s.should == "1.0..."
end
- ruby_version_is "2.7" do
- it "can show beginless ranges" do
- eval("(..1)").to_s.should == "..1"
- eval("(...1.0)").to_s.should == "...1.0"
- end
- end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if either end is tainted" do
- (("a".taint)..."c").to_s.tainted?.should be_true
- ("a"...("c".taint)).to_s.tainted?.should be_true
- ("a"..."c").taint.to_s.tainted?.should be_true
- end
-
- it "returns a untrusted string if either end is untrusted" do
- (("a".untrust)..."c").to_s.untrusted?.should be_true
- ("a"...("c".untrust)).to_s.untrusted?.should be_true
- ("a"..."c").untrust.to_s.untrusted?.should be_true
- end
+ it "can show beginless ranges" do
+ (..1).to_s.should == "..1"
+ (...1.0).to_s.should == "...1.0"
end
end
diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb
index b2e3d326ba..37c7994700 100644
--- a/spec/ruby/core/string/b_spec.rb
+++ b/spec/ruby/core/string/b_spec.rb
@@ -12,13 +12,4 @@ describe "String#b" do
str.b.should_not equal(str)
str.should == "こんちには"
end
-
- ruby_version_is ''...'2.7' do
- it "copies own tainted/untrusted status to the returning value" do
- utf_8 = "こんちには".taint.untrust
- ret = utf_8.b
- ret.tainted?.should be_true
- ret.untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb
index 21df18a5ae..ca8df88fec 100644
--- a/spec/ruby/core/string/capitalize_spec.rb
+++ b/spec/ruby/core/string/capitalize_spec.rb
@@ -12,13 +12,6 @@ describe "String#capitalize" do
"123ABC".capitalize.should == "123abc"
end
- ruby_version_is ''...'2.7' do
- it "taints resulting string when self is tainted" do
- "".taint.capitalize.should.tainted?
- "hello".taint.capitalize.should.tainted?
- end
- end
-
describe "full Unicode case mapping" do
it "works for all of Unicode with no option" do
"äöÜ".capitalize.should == "Äöü"
diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb
index b66015172c..76da6e1e09 100644
--- a/spec/ruby/core/string/center_spec.rb
+++ b/spec/ruby/core/string/center_spec.rb
@@ -47,16 +47,6 @@ describe "String#center with length, padding" do
"radiology".center(8, '-').should == "radiology"
end
- ruby_version_is ''...'2.7' do
- it "taints result when self or padstr is tainted" do
- "x".taint.center(4).should.tainted?
- "x".taint.center(0).should.tainted?
- "".taint.center(0).should.tainted?
- "x".taint.center(4, "*").should.tainted?
- "x".center(4, "*".taint).should.tainted?
- end
- end
-
it "calls #to_int to convert length to an integer" do
"_".center(3.8, "^").should == "^_^"
@@ -113,14 +103,6 @@ describe "String#center with length, padding" do
end
end
- ruby_version_is ''...'2.7' do
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".center(4, 'X'.taint).tainted?.should be_false
- "hello".center(5, 'X'.taint).tainted?.should be_false
- "hello".center(6, 'X'.taint).tainted?.should be_true
- end
- end
-
describe "with width" do
it "returns a String in the same encoding as the original" do
str = "abc".force_encoding Encoding::IBM437
diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb
index 3d6207f876..c03bfc7951 100644
--- a/spec/ruby/core/string/chomp_spec.rb
+++ b/spec/ruby/core/string/chomp_spec.rb
@@ -40,12 +40,6 @@ describe "String#chomp" do
"".chomp.should == ""
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp.tainted?.should be_true
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns subclass instances when called on a subclass" do
str = StringSpecs::MyString.new("hello\n").chomp
@@ -80,12 +74,6 @@ describe "String#chomp" do
str.chomp(nil).should_not equal(str)
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp(nil).tainted?.should be_true
- end
- end
-
it "returns an empty String when self is empty" do
"".chomp(nil).should == ""
end
@@ -112,12 +100,6 @@ describe "String#chomp" do
"abc\r\n\r\n\r\n".chomp("").should == "abc"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("").tainted?.should be_true
- end
- end
-
it "returns an empty String when self is empty" do
"".chomp("").should == ""
end
@@ -140,12 +122,6 @@ describe "String#chomp" do
"abc\r\n\r\n".chomp("\n").should == "abc\r\n"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("\n").tainted?.should be_true
- end
- end
-
it "returns an empty String when self is empty" do
"".chomp("\n").should == ""
end
@@ -178,16 +154,6 @@ describe "String#chomp" do
"".chomp("abc").should == ""
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp("abc".taint).tainted?.should be_false
- end
- end
-
it "returns an empty String when the argument equals self" do
"abc".chomp("abc").should == ""
end
@@ -232,12 +198,6 @@ describe "String#chomp!" do
"".chomp!.should be_nil
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!.tainted?.should be_true
- end
- end
-
it "returns subclass instances when called on a subclass" do
str = StringSpecs::MyString.new("hello\n").chomp!
str.should be_an_instance_of(StringSpecs::MyString)
@@ -280,12 +240,6 @@ describe "String#chomp!" do
"abc\r\n\r\n\r\n".chomp!("").should == "abc"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("").tainted?.should be_true
- end
- end
-
it "returns nil when self is empty" do
"".chomp!("").should be_nil
end
@@ -304,12 +258,6 @@ describe "String#chomp!" do
"abc\r\n\r\n".chomp!("\n").should == "abc\r\n"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("\n").tainted?.should be_true
- end
- end
-
it "returns nil when self is empty" do
"".chomp!("\n").should be_nil
end
@@ -341,16 +289,6 @@ describe "String#chomp!" do
it "returns nil when self is empty" do
"".chomp!("abc").should be_nil
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "abc".taint.chomp!("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp!("abc".taint).tainted?.should be_false
- end
- end
end
it "raises a FrozenError on a frozen instance when it is modified" do
diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb
index 9b4e7363c6..266d973f67 100644
--- a/spec/ruby/core/string/chop_spec.rb
+++ b/spec/ruby/core/string/chop_spec.rb
@@ -49,18 +49,6 @@ describe "String#chop" do
s.chop.should_not equal(s)
end
- ruby_version_is ''...'2.7' do
- it "taints result when self is tainted" do
- "hello".taint.chop.should.tainted?
- "".taint.chop.should.tainted?
- end
-
- it "untrusts result when self is untrusted" do
- "hello".untrust.chop.should.untrusted?
- "".untrust.chop.should.untrusted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns subclass instances when called on a subclass" do
StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(StringSpecs::MyString)
diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb
index b947702492..06f84c70a4 100644
--- a/spec/ruby/core/string/crypt_spec.rb
+++ b/spec/ruby/core/string/crypt_spec.rb
@@ -25,21 +25,6 @@ describe "String#crypt" do
"mypassword".crypt(obj).should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2."
end
- ruby_version_is ''...'2.7' do
- it "taints the result if either salt or self is tainted" do
- tainted_salt = "$2a$04$0WVaz0pV3jzfZ5G5tpmHWu"
- tainted_str = "mypassword"
-
- tainted_salt.taint
- tainted_str.taint
-
- "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should_not.tainted?
- tainted_str.crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should.tainted?
- "mypassword".crypt(tainted_salt).should.tainted?
- tainted_str.crypt(tainted_salt).should.tainted?
- end
- end
-
it "doesn't return subclass instances" do
StringSpecs::MyString.new("mypassword").crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should be_an_instance_of(String)
"mypassword".crypt(StringSpecs::MyString.new("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu")).should be_an_instance_of(String)
@@ -85,21 +70,6 @@ describe "String#crypt" do
"".crypt(obj).should == "aaQSqAReePlq6"
end
- ruby_version_is ''...'2.7' do
- it "taints the result if either salt or self is tainted" do
- tainted_salt = "aa"
- tainted_str = "hello"
-
- tainted_salt.taint
- tainted_str.taint
-
- "hello".crypt("aa").should_not.tainted?
- tainted_str.crypt("aa").should.tainted?
- "hello".crypt(tainted_salt).should.tainted?
- tainted_str.crypt(tainted_salt).should.tainted?
- end
- end
-
it "doesn't return subclass instances" do
StringSpecs::MyString.new("hello").crypt("aa").should be_an_instance_of(String)
"hello".crypt(StringSpecs::MyString.new("aa")).should be_an_instance_of(String)
diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb
index 8469791f74..a063e443d8 100644
--- a/spec/ruby/core/string/delete_prefix_spec.rb
+++ b/spec/ruby/core/string/delete_prefix_spec.rb
@@ -21,13 +21,6 @@ describe "String#delete_prefix" do
r.should == s
end
- ruby_version_is ''...'2.7' do
- it "taints resulting strings when other is tainted" do
- 'hello'.taint.delete_prefix('hell').should.tainted?
- 'hello'.taint.delete_prefix('').should.tainted?
- end
- end
-
it "doesn't set $~" do
$~ = nil
diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb
index ebca0b7dae..b91e88b76f 100644
--- a/spec/ruby/core/string/delete_spec.rb
+++ b/spec/ruby/core/string/delete_spec.rb
@@ -68,15 +68,6 @@ describe "String#delete" do
-> { "hello".delete("^h-e") }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "taints result when self is tainted" do
- "hello".taint.delete("e").should.tainted?
- "hello".taint.delete("a-z").should.tainted?
-
- "hello".delete("e".taint).should_not.tainted?
- end
- end
-
it "tries to convert each set arg to a string using to_str" do
other_string = mock('lo')
other_string.should_receive(:to_str).and_return("lo")
diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb
index 12d0ee175e..3d3274bc5b 100644
--- a/spec/ruby/core/string/delete_suffix_spec.rb
+++ b/spec/ruby/core/string/delete_suffix_spec.rb
@@ -21,13 +21,6 @@ describe "String#delete_suffix" do
r.should == s
end
- ruby_version_is ''...'2.7' do
- it "taints resulting strings when other is tainted" do
- 'hello'.taint.delete_suffix('ello').should.tainted?
- 'hello'.taint.delete_suffix('').should.tainted?
- end
- end
-
it "doesn't set $~" do
$~ = nil
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 4427c9df10..86d8480889 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -68,14 +68,6 @@ describe "String#downcase" do
-> { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "taints result when self is tainted" do
- "".taint.downcase.should.tainted?
- "x".taint.downcase.should.tainted?
- "X".taint.downcase.should.tainted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns a subclass instance for subclasses" do
StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(StringSpecs::MyString)
diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb
index 817dec6c4d..79a8b55e6d 100644
--- a/spec/ruby/core/string/dump_spec.rb
+++ b/spec/ruby/core/string/dump_spec.rb
@@ -3,18 +3,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "String#dump" do
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "foo".taint.dump.should.tainted?
- "foo\n".taint.dump.should.tainted?
- end
-
- it "untrusts the result if self is untrusted" do
- "foo".untrust.dump.should.untrusted?
- "foo\n".untrust.dump.should.untrusted?
- end
- end
-
it "does not take into account if a string is frozen" do
"foo".freeze.dump.should_not.frozen?
end
diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb
index 0aabbacd0e..881b4343d4 100644
--- a/spec/ruby/core/string/element_set_spec.rb
+++ b/spec/ruby/core/string/element_set_spec.rb
@@ -14,18 +14,6 @@ describe "String#[]= with Integer index" do
a.should == "bamelo"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0] = "".taint
- a.should.tainted?
-
- a = "hello"
- a[0] = "x".taint
- a.should.tainted?
- end
- end
-
it "raises an IndexError without changing self if idx is outside of self" do
str = "hello"
@@ -493,18 +481,6 @@ describe "String#[]= with Integer index, count" do
a.should == "hellobob"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0, 0] = "".taint
- a.should.tainted?
-
- a = "hello"
- a[1, 4] = "x".taint
- a.should.tainted?
- end
- end
-
it "calls #to_int to convert the index and count objects" do
index = mock("string element set index")
index.should_receive(:to_int).and_return(-4)
diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb
index ad41b7e0a2..3211ebbd0a 100644
--- a/spec/ruby/core/string/gsub_spec.rb
+++ b/spec/ruby/core/string/gsub_spec.rb
@@ -160,56 +160,12 @@ describe "String#gsub with pattern and replacement" do
it_behaves_like :string_gsub_named_capture, :gsub
- ruby_version_is ''...'2.7' do
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.gsub(/./, a).should.tainted?
- hello_t.gsub(/./, empty).should.tainted?
-
- hello.gsub(/./, a_t).should.tainted?
- hello.gsub(/./, empty_t).should.tainted?
- hello.gsub(//, empty_t).should.tainted?
-
- hello.gsub(//.taint, "foo").should_not.tainted?
- end
- end
-
it "handles pattern collapse" do
str = "こにちわ"
reg = %r!!
str.gsub(reg, ".").should == ".こ.に.ち.わ."
end
- ruby_version_is ''...'2.7' do
- it "untrusts the result if the original string or replacement is untrusted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.untrust; a_t.untrust; empty_t.untrust
-
- hello_t.gsub(/./, a).should.untrusted?
- hello_t.gsub(/./, empty).should.untrusted?
-
- hello.gsub(/./, a_t).should.untrusted?
- hello.gsub(/./, empty_t).should.untrusted?
- hello.gsub(//, empty_t).should.untrusted?
-
- hello.gsub(//.untrust, "foo").should_not.untrusted?
- end
- end
-
it "tries to convert pattern to a string using to_str" do
pattern = mock('.')
def pattern.to_str() "." end
@@ -336,28 +292,6 @@ describe "String#gsub with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".gsub(/(.+)/, 'hello' => repl ).should == repl
end
-
- ruby_version_is ''...'2.7' do
- it "untrusts the result if the original string is untrusted" do
- str = "Ghana".untrust
- str.gsub(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts the result if a hash value is untrusted" do
- str = "Ghana"
- str.gsub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "taints the result if the original string is tainted" do
- str = "Ghana".taint
- str.gsub(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints the result if a hash value is tainted" do
- str = "Ghana"
- str.gsub(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
- end
end
describe "String#gsub! with pattern and Hash" do
@@ -426,28 +360,6 @@ describe "String#gsub! with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".gsub!(/(.+)/, 'hello' => repl ).should == repl
end
-
- ruby_version_is ''...'2.7' do
- it "keeps untrusted state" do
- str = "Ghana".untrust
- str.gsub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts self if a hash value is untrusted" do
- str = "Ghana"
- str.gsub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "keeps tainted state" do
- str = "Ghana".taint
- str.gsub!(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints self if a hash value is tainted" do
- str = "Ghana"
- str.gsub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
- end
end
describe "String#gsub with pattern and block" do
@@ -526,28 +438,6 @@ describe "String#gsub with pattern and block" do
"hello".gsub(/.+/) { obj }.should == "ok"
end
- ruby_version_is ''...'2.7' do
- it "untrusts the result if the original string or replacement is untrusted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.untrust; a_t.untrust; empty_t.untrust
-
- hello_t.gsub(/./) { a }.should.untrusted?
- hello_t.gsub(/./) { empty }.should.untrusted?
-
- hello.gsub(/./) { a_t }.should.untrusted?
- hello.gsub(/./) { empty_t }.should.untrusted?
- hello.gsub(//) { empty_t }.should.untrusted?
-
- hello.gsub(//.untrust) { "foo" }.should_not.untrusted?
- end
- end
-
it "uses the compatible encoding if they are compatible" do
s = "hello"
s2 = "#{195.chr}#{192.chr}#{195.chr}"
@@ -615,20 +505,6 @@ describe "String#gsub! with pattern and replacement" do
a.should == "*¿** **é*?*"
end
- ruby_version_is ''...'2.7' do
- it "taints self if replacement is tainted" do
- a = "hello"
- a.gsub!(/./.taint, "foo").should_not.tainted?
- a.gsub!(/./, "foo".taint).should.tainted?
- end
-
- it "untrusts self if replacement is untrusted" do
- a = "hello"
- a.gsub!(/./.untrust, "foo").should_not.untrusted?
- a.gsub!(/./, "foo".untrust).should.untrusted?
- end
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.gsub!(/z/, '*').should == nil
@@ -654,20 +530,6 @@ describe "String#gsub! with pattern and block" do
a.should == "h*ll*"
end
- ruby_version_is ''...'2.7' do
- it "taints self if block's result is tainted" do
- a = "hello"
- a.gsub!(/./.taint) { "foo" }.should_not.tainted?
- a.gsub!(/./) { "foo".taint }.should.tainted?
- end
-
- it "untrusts self if block's result is untrusted" do
- a = "hello"
- a.gsub!(/./.untrust) { "foo" }.should_not.untrusted?
- a.gsub!(/./) { "foo".untrust }.should.untrusted?
- end
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.gsub!(/z/) { '*' }.should == nil
diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb
index 752cbb2f37..db42a37941 100644
--- a/spec/ruby/core/string/insert_spec.rb
+++ b/spec/ruby/core/string/insert_spec.rb
@@ -41,18 +41,6 @@ describe "String#insert with index, other" do
"abcd".insert(-3, other).should == "abXYZcd"
end
- ruby_version_is ''...'2.7' do
- it "taints self if string to insert is tainted" do
- str = "abcd"
- str.insert(0, "T".taint).should.tainted?
-
- str = "abcd"
- other = mock('T')
- def other.to_str() "T".taint end
- str.insert(0, other).should.tainted?
- end
- end
-
it "raises a TypeError if other can't be converted to string" do
-> { "abcd".insert(-6, Object.new)}.should raise_error(TypeError)
-> { "abcd".insert(-6, []) }.should raise_error(TypeError)
diff --git a/spec/ruby/core/string/inspect_spec.rb b/spec/ruby/core/string/inspect_spec.rb
index 98b5b32b61..8bfd465144 100644
--- a/spec/ruby/core/string/inspect_spec.rb
+++ b/spec/ruby/core/string/inspect_spec.rb
@@ -3,18 +3,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "String#inspect" do
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "foo".taint.inspect.should.tainted?
- "foo\n".taint.inspect.should.tainted?
- end
-
- it "untrusts the result if self is untrusted" do
- "foo".untrust.inspect.should.untrusted?
- "foo\n".untrust.inspect.should.untrusted?
- end
- end
-
it "does not return a subclass instance" do
StringSpecs::MyString.new.inspect.should be_an_instance_of(String)
end
diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb
index 0c3b2a2f44..9a25d3abd4 100644
--- a/spec/ruby/core/string/ljust_spec.rb
+++ b/spec/ruby/core/string/ljust_spec.rb
@@ -31,16 +31,6 @@ describe "String#ljust with length, padding" do
"radiology".ljust(8, '-').should == "radiology"
end
- ruby_version_is ''...'2.7' do
- it "taints result when self or padstr is tainted" do
- "x".taint.ljust(4).should.tainted?
- "x".taint.ljust(0).should.tainted?
- "".taint.ljust(0).should.tainted?
- "x".taint.ljust(4, "*").should.tainted?
- "x".ljust(4, "*".taint).should.tainted?
- end
- end
-
it "tries to convert length to an integer using to_int" do
"^".ljust(3.8, "_^").should == "^_^"
@@ -96,14 +86,6 @@ describe "String#ljust with length, padding" do
end
end
- ruby_version_is ''...'2.7' do
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".ljust(4, 'X'.taint).tainted?.should be_false
- "hello".ljust(5, 'X'.taint).tainted?.should be_false
- "hello".ljust(6, 'X'.taint).tainted?.should be_true
- end
- end
-
describe "with width" do
it "returns a String in the same encoding as the original" do
str = "abc".force_encoding Encoding::IBM437
diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb
index 8b5dd1b467..6e868eac4f 100644
--- a/spec/ruby/core/string/lstrip_spec.rb
+++ b/spec/ruby/core/string/lstrip_spec.rb
@@ -18,14 +18,6 @@ describe "String#lstrip" do
"\000 \000hello\000 \000".lstrip.should == "hello\000 \000"
end
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- "".taint.lstrip.should.tainted?
- "ok".taint.lstrip.should.tainted?
- " ok".taint.lstrip.should.tainted?
- end
- end
end
describe "String#lstrip!" do
diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb
index dc11ced4e2..99c1694417 100644
--- a/spec/ruby/core/string/modulo_spec.rb
+++ b/spec/ruby/core/string/modulo_spec.rb
@@ -302,29 +302,6 @@ describe "String#%" do
end
end
- ruby_version_is ''...'2.7' do
- it "always taints the result when the format string is tainted" do
- universal = mock('0')
- def universal.to_int() 0 end
- def universal.to_str() "0" end
- def universal.to_f() 0.0 end
-
- [
- "", "foo",
- "%b", "%B", "%c", "%d", "%e", "%E",
- "%f", "%g", "%G", "%i", "%o", "%p",
- "%s", "%u", "%x", "%X"
- ].each do |format|
- subcls_format = StringSpecs::MyString.new(format)
- subcls_format.taint
- format.taint
-
- (format % universal).should.tainted?
- (subcls_format % universal).should.tainted?
- end
- end
- end
-
it "supports binary formats using %b for positive numbers" do
("%b" % 10).should == "1010"
("% b" % 10).should == " 1010"
@@ -578,20 +555,6 @@ describe "String#%" do
# ("%p" % obj).should == "obj"
end
- ruby_version_is ''...'2.7' do
- it "taints result for %p when argument.inspect is tainted" do
- obj = mock('x')
- def obj.inspect() "x".taint end
-
- ("%p" % obj).should.tainted?
-
- obj = mock('x'); obj.taint
- def obj.inspect() "x" end
-
- ("%p" % obj).should_not.tainted?
- end
- end
-
it "supports string formats using %s" do
("%s" % "hello").should == "hello"
("%s" % "").should == ""
@@ -620,13 +583,6 @@ describe "String#%" do
# ("%s" % obj).should == "obj"
end
- ruby_version_is ''...'2.7' do
- it "taints result for %s when argument is tainted" do
- ("%s" % "x".taint).should.tainted?
- ("%s" % mock('x').taint).should.tainted?
- end
- end
-
# MRI crashes on this one.
# See http://groups.google.com/group/ruby-core-google/t/c285c18cd94c216d
it "raises an ArgumentError for huge precisions for %s" do
@@ -786,12 +742,6 @@ describe "String#%" do
it "behaves as if calling Kernel#Float for #{format} arguments, when the passed argument is hexadecimal string" do
(format % "0xA").should == (format % 0xA)
end
-
- ruby_version_is ''...'2.7' do
- it "doesn't taint the result for #{format} when argument is tainted" do
- (format % "5".taint).should_not.tainted?
- end
- end
end
describe "when format string contains %{} sections" do
diff --git a/spec/ruby/core/string/plus_spec.rb b/spec/ruby/core/string/plus_spec.rb
index 9f0db6427c..5ff198f07e 100644
--- a/spec/ruby/core/string/plus_spec.rb
+++ b/spec/ruby/core/string/plus_spec.rb
@@ -32,18 +32,5 @@ describe "String#+" do
("hello" + StringSpecs::MyString.new("")).should be_an_instance_of(String)
end
- ruby_version_is ''...'2.7' do
- it "taints the result when self or other is tainted" do
- strs = ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- strs.each do |other|
- (str + other).tainted?.should == (str.tainted? | other.tainted?)
- end
- end
- end
- end
-
it_behaves_like :string_concat_encoding, :+
end
diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb
index a6074be3c6..a0393d4760 100644
--- a/spec/ruby/core/string/prepend_spec.rb
+++ b/spec/ruby/core/string/prepend_spec.rb
@@ -34,16 +34,6 @@ describe "String#prepend" do
a.should == "hello world"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other is tainted" do
- x = "x"
- x.prepend("".taint).tainted?.should be_true
-
- x = "x"
- x.prepend("y".taint).tainted?.should be_true
- end
- end
-
it "takes multiple arguments" do
str = " world"
str.prepend "he", "", "llo"
diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb
index b45ff2cf6f..bade4685d9 100644
--- a/spec/ruby/core/string/reverse_spec.rb
+++ b/spec/ruby/core/string/reverse_spec.rb
@@ -26,13 +26,6 @@ describe "String#reverse" do
end
end
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- "".taint.reverse.should.tainted?
- "m".taint.reverse.should.tainted?
- end
- end
-
it "reverses a string with multi byte characters" do
"微軟正黑體".reverse.should == "體黑正軟微"
end
diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb
index f51aacff44..d067b7bdb3 100644
--- a/spec/ruby/core/string/rjust_spec.rb
+++ b/spec/ruby/core/string/rjust_spec.rb
@@ -31,16 +31,6 @@ describe "String#rjust with length, padding" do
"radiology".rjust(8, '-').should == "radiology"
end
- ruby_version_is ''...'2.7' do
- it "taints result when self or padstr is tainted" do
- "x".taint.rjust(4).should.tainted?
- "x".taint.rjust(0).should.tainted?
- "".taint.rjust(0).should.tainted?
- "x".taint.rjust(4, "*").should.tainted?
- "x".rjust(4, "*".taint).should.tainted?
- end
- end
-
it "tries to convert length to an integer using to_int" do
"^".rjust(3.8, "^_").should == "^_^"
@@ -96,14 +86,6 @@ describe "String#rjust with length, padding" do
end
end
- ruby_version_is ''...'2.7' do
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".rjust(4, 'X'.taint).tainted?.should be_false
- "hello".rjust(5, 'X'.taint).tainted?.should be_false
- "hello".rjust(6, 'X'.taint).tainted?.should be_true
- end
- end
-
describe "with width" do
it "returns a String in the same encoding as the original" do
str = "abc".force_encoding Encoding::IBM437
diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb
index a1453f91fe..2dc55182ae 100644
--- a/spec/ruby/core/string/rstrip_spec.rb
+++ b/spec/ruby/core/string/rstrip_spec.rb
@@ -16,14 +16,6 @@ describe "String#rstrip" do
it "returns a copy of self with all trailing whitespace and NULL bytes removed" do
"\x00 \x00hello\x00 \x00".rstrip.should == "\x00 \x00hello"
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- "".taint.rstrip.should.tainted?
- "ok".taint.rstrip.should.tainted?
- "ok ".taint.rstrip.should.tainted?
- end
- end
end
describe "String#rstrip!" do
diff --git a/spec/ruby/core/string/scan_spec.rb b/spec/ruby/core/string/scan_spec.rb
index 5f86dbbecc..ab73f5747b 100644
--- a/spec/ruby/core/string/scan_spec.rb
+++ b/spec/ruby/core/string/scan_spec.rb
@@ -65,28 +65,6 @@ describe "String#scan" do
-> { "cruel world".scan(mock('x')) }.should raise_error(TypeError)
end
- ruby_version_is ''...'2.7' do
- it "taints the results if the String argument is tainted" do
- a = "hello hello hello".scan("hello".taint)
- a.each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a String argument if self is tainted" do
- a = "hello hello hello".taint.scan("hello")
- a.each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results if the Regexp argument is tainted" do
- a = "hello".scan(/./.taint)
- a.each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a Regexp argument if self is tainted" do
- a = "hello".taint.scan(/./)
- a.each { |m| m.tainted?.should be_true }
- end
- end
-
# jruby/jruby#5513
it "does not raise any errors when passed a multi-byte string" do
"あああaaaあああ".scan("あああ").should == ["あああ", "あああ"]
@@ -173,24 +151,6 @@ describe "String#scan with pattern and block" do
$~.should == nil
end
- ruby_version_is ''...'2.7' do
- it "taints the results if the String argument is tainted" do
- "hello hello hello".scan("hello".taint).each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a String argument if self is tainted" do
- "hello hello hello".taint.scan("hello").each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results if the Regexp argument is tainted" do
- "hello".scan(/./.taint).each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a Regexp argument if self is tainted" do
- "hello".taint.scan(/./).each { |m| m.tainted?.should be_true }
- end
- end
-
it "passes block arguments as individual arguments when blocks are provided" do
"a b c\na b c\na b c".scan(/(\w*) (\w*) (\w*)/) do |first,second,third|
first.should == 'a';
diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb
index 1f045e4530..e9fdf89fd6 100644
--- a/spec/ruby/core/string/shared/chars.rb
+++ b/spec/ruby/core/string/shared/chars.rb
@@ -63,18 +63,4 @@ describe :string_chars, shared: true do
[0xA2].pack('C').force_encoding('SJIS')
]
end
-
- ruby_version_is ''...'2.7' do
- it "taints resulting strings when self is tainted" do
- str = "hello"
-
- str.send(@method) do |x|
- x.should_not.tainted?
- end
-
- str.dup.taint.send(@method) do |x|
- x.should.tainted?
- end
- end
- end
end
diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb
index d6ffad7d4d..54ac1035d3 100644
--- a/spec/ruby/core/string/shared/concat.rb
+++ b/spec/ruby/core/string/shared/concat.rb
@@ -39,18 +39,6 @@ describe :string_concat, shared: true do
str.should be_an_instance_of(StringSpecs::MyString)
end
- ruby_version_is ''...'2.7' do
- it "taints self if other is tainted" do
- "x".send(@method, "".taint).should.tainted?
- "x".send(@method, "y".taint).should.tainted?
- end
-
- it "untrusts self if other is untrusted" do
- "x".send(@method, "".untrust).should.untrusted?
- "x".send(@method, "y".untrust).should.untrusted?
- end
- end
-
describe "with Integer" do
it "concatenates the argument interpreted as a codepoint" do
b = "".send(@method, 33)
diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb
index f9c910596a..bfedf8f35a 100644
--- a/spec/ruby/core/string/shared/each_line.rb
+++ b/spec/ruby/core/string/shared/each_line.rb
@@ -40,14 +40,6 @@ describe :string_each_line, shared: true do
b.should == ["foo\n", "🤡🤡🤡🤡🤡🤡🤡\n", "bar\n", "baz\n"]
end
- ruby_version_is ''...'2.7' do
- it "taints substrings that are passed to the block if self is tainted" do
- "one\ntwo\r\nthree".taint.send(@method) { |s| s.should.tainted? }
-
- "x.y.".send(@method, ".".taint) { |s| s.should_not.tainted? }
- end
- end
-
it "passes self as a whole to the block if the separator is nil" do
a = []
"one\ntwo\r\nthree".send(@method, nil) { |s| a << s }
diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb
index 8dfac49f02..a5108d9e7c 100644
--- a/spec/ruby/core/string/shared/replace.rb
+++ b/spec/ruby/core/string/shared/replace.rb
@@ -10,36 +10,6 @@ describe :string_replace, shared: true do
a.should == "another string"
end
- ruby_version_is ''...'2.7' do
- it "taints self if other is tainted" do
- a = ""
- b = "".taint
- a.send(@method, b)
- a.should.tainted?
- end
-
- it "does not untaint self if other is untainted" do
- a = "".taint
- b = ""
- a.send(@method, b)
- a.should.tainted?
- end
-
- it "untrusts self if other is untrusted" do
- a = ""
- b = "".untrust
- a.send(@method, b)
- a.should.untrusted?
- end
-
- it "does not trust self if other is trusted" do
- a = "".untrust
- b = ""
- a.send(@method, b)
- a.should.untrusted?
- end
- end
-
it "replaces the encoding of self with that of other" do
a = "".encode("UTF-16LE")
b = "".encode("UTF-8")
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb
index 1db8fd6730..228af5f824 100644
--- a/spec/ruby/core/string/shared/slice.rb
+++ b/spec/ruby/core/string/shared/slice.rb
@@ -80,17 +80,6 @@ describe :string_slice_index_length, shared: true do
"hello there".send(@method, -3,2).should == "er"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.send(@method, 0,0).should.tainted?
- str.send(@method, 0,1).should.tainted?
- str.send(@method, 2,1).should.tainted?
- end
- end
-
it "returns a string with the same encoding" do
s = "hello there"
s.send(@method, 1, 9).encoding.should == s.encoding
@@ -249,20 +238,6 @@ describe :string_slice_range, shared: true do
"x".send(@method, 1...-1).should == ""
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.send(@method, 0..0).should.tainted?
- str.send(@method, 0...0).should.tainted?
- str.send(@method, 0..1).should.tainted?
- str.send(@method, 0...1).should.tainted?
- str.send(@method, 2..3).should.tainted?
- str.send(@method, 2..0).should.tainted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns subclass instances" do
s = StringSpecs::MyString.new("hello")
@@ -334,14 +309,12 @@ describe :string_slice_range, shared: true do
"hello there".send(@method, eval("(-4...)")).should == "here"
end
- ruby_version_is "2.7" do
- it "works with beginless ranges" do
- "hello there".send(@method, eval("(..5)")).should == "hello "
- "hello there".send(@method, eval("(...5)")).should == "hello"
- "hello there".send(@method, eval("(..-4)")).should == "hello th"
- "hello there".send(@method, eval("(...-4)")).should == "hello t"
- "hello there".send(@method, eval("(...nil)")).should == "hello there"
- end
+ it "works with beginless ranges" do
+ "hello there".send(@method, (..5)).should == "hello "
+ "hello there".send(@method, (...5)).should == "hello"
+ "hello there".send(@method, (..-4)).should == "hello th"
+ "hello there".send(@method, (...-4)).should == "hello t"
+ "hello there".send(@method, (...nil)).should == "hello there"
end
end
@@ -356,26 +329,6 @@ describe :string_slice_regexp, shared: true do
end
not_supported_on :opal do
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, //).tainted?.should == str.tainted?
- str.send(@method, /hello/).tainted?.should == str.tainted?
-
- tainted_re = /./
- tainted_re.taint
-
- str.send(@method, tainted_re).should.tainted?
- end
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- "hello".send(@method, /./.untrust).untrusted?.should be_true
- end
- end
end
ruby_version_is ''...'3.0' do
@@ -418,36 +371,6 @@ describe :string_slice_regexp_index, shared: true do
"har".send(@method, /(.)(.)(.)/, -3).should == "h"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, //, 0).tainted?.should == str.tainted?
- str.send(@method, /hello/, 0).tainted?.should == str.tainted?
-
- str.send(@method, /(.)(.)(.)/, 0).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, 1).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, -1).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, -2).tainted?.should == str.tainted?
-
- tainted_re = /(.)(.)(.)/
- tainted_re.taint
-
- str.send(@method, tainted_re, 0).should.tainted?
- str.send(@method, tainted_re, 1).should.tainted?
- str.send(@method, tainted_re, -1).should.tainted?
- end
- end
-
- not_supported_on :opal do
- it "returns an untrusted string if the regexp is untrusted" do
- "hello".send(@method, /(.)/.untrust, 1).untrusted?.should be_true
- end
- end
- end
-
it "returns nil if there is no match" do
"hello there".send(@method, /(what?)/, 1).should == nil
end
@@ -510,21 +433,6 @@ describe :string_slice_string, shared: true do
"hello there".send(@method, s).should == s
end
- ruby_version_is ''...'2.7' do
- it "taints resulting strings when other is tainted" do
- strs = ["", "hello world", "hello"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- strs.each do |other|
- r = str.send(@method, other)
-
- r.tainted?.should == !r.nil? & other.tainted?
- end
- end
- end
- end
-
it "doesn't set $~" do
$~ = nil
@@ -584,30 +492,6 @@ describe :string_slice_regexp_group, shared: true do
"hello there".send(@method, /(?<g>h(?<g>.))/, 'g').should == "e"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, /(?<hi>hello)/, 'hi').tainted?.should == str.tainted?
-
- str.send(@method, /(?<g>(.)(.)(.))/, 'g').tainted?.should == str.tainted?
- str.send(@method, /(?<h>.)(.)(.)/, 'h').tainted?.should == str.tainted?
- str.send(@method, /(.)(?<a>.)(.)/, 'a').tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(?<r>.)/, 'r').tainted?.should == str.tainted?
- str.send(@method, /(?<h>.)(?<a>.)(?<r>.)/, 'r').tainted?.should == str.tainted?
-
- tainted_re = /(?<a>.)(?<b>.)(?<c>.)/
- tainted_re.taint
-
- str.send(@method, tainted_re, 'a').tainted?.should be_true
- str.send(@method, tainted_re, 'b').tainted?.should be_true
- str.send(@method, tainted_re, 'c').tainted?.should be_true
- end
- end
- end
-
it "returns nil if there is no match" do
"hello there".send(@method, /(?<whut>what?)/, 'whut').should be_nil
end
diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb
index 25602103b6..66edf6dc82 100644
--- a/spec/ruby/core/string/shared/succ.rb
+++ b/spec/ruby/core/string/shared/succ.rb
@@ -74,14 +74,6 @@ describe :string_succ, shared: true do
StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(String)
end
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- ["", "a", "z", "Z", "9", "\xFF", "\xFF\xFF"].each do |s|
- s.taint.send(@method).should.tainted?
- end
- end
- end
end
describe :string_succ_bang, shared: true do
diff --git a/spec/ruby/core/string/shared/to_s.rb b/spec/ruby/core/string/shared/to_s.rb
index b8c9b8ab44..4b87a6cbe1 100644
--- a/spec/ruby/core/string/shared/to_s.rb
+++ b/spec/ruby/core/string/shared/to_s.rb
@@ -10,11 +10,4 @@ describe :string_to_s, shared: true do
s.should == "a string"
s.should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- "x".taint.send(@method).should.tainted?
- StringSpecs::MyString.new("x").taint.send(@method).should.tainted?
- end
- end
end
diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb
index 83b475c8b5..c9e13ed1bc 100644
--- a/spec/ruby/core/string/slice_spec.rb
+++ b/spec/ruby/core/string/slice_spec.rb
@@ -94,16 +94,6 @@ describe "String#slice! with index, length" do
a.should == "h"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.slice!(0, 0).should.tainted?
- str.slice!(2, 1).should.tainted?
- end
- end
-
it "returns nil if the given position is out of self" do
a = "hello"
a.slice(10, 3).should == nil
@@ -195,16 +185,6 @@ describe "String#slice! Range" do
b.should == "hello"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.slice!(0..0).should.tainted?
- str.slice!(2..3).should.tainted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns subclass instances" do
s = StringSpecs::MyString.new("hello")
@@ -294,30 +274,6 @@ describe "String#slice! with Regexp" do
s.should == "this is a string"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- str.slice!(//).tainted?.should == str.tainted?
- str.slice!(/hello/).tainted?.should == str.tainted?
-
- tainted_re = /./
- tainted_re.taint
-
- str.slice!(tainted_re).should.tainted?
- end
- end
-
- it "doesn't taint self when regexp is tainted" do
- s = "hello"
- s.slice!(/./.taint)
- s.should_not.tainted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns subclass instances" do
s = StringSpecs::MyString.new("hello")
@@ -365,30 +321,6 @@ describe "String#slice! with Regexp, index" do
str.should == "ho here"
end
- ruby_version_is ''...'2.7' do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- str.slice!(//, 0).tainted?.should == str.tainted?
- str.slice!(/hello/, 0).tainted?.should == str.tainted?
-
- tainted_re = /(.)(.)(.)/
- tainted_re.taint
-
- str.slice!(tainted_re, 1).should.tainted?
- end
- end
-
- it "doesn't taint self when regexp is tainted" do
- s = "hello"
- s.slice!(/(.)(.)/.taint, 1)
- s.should_not.tainted?
- end
- end
-
it "returns nil if there was no match" do
s = "this is a string"
s.slice!(/x(zzz)/, 1).should == nil
@@ -463,23 +395,6 @@ describe "String#slice! with String" do
c.should == "he hello"
end
- ruby_version_is ''...'2.7' do
- it "taints resulting strings when other is tainted" do
- strs = ["", "hello world", "hello"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- strs.each do |other|
- other = other.dup
- r = str.slice!(other)
-
- r.tainted?.should == !r.nil? & other.tainted?
- end
- end
- end
- end
-
it "doesn't set $~" do
$~ = nil
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index 2da71948b3..82911ef50b 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -89,21 +89,19 @@ describe "String#split with String" do
end
end
- ruby_version_is "2.7" do
- context "when $; is not nil" do
- before do
- suppress_warning do
- @old_value, $; = $;, 'foobar'
- end
+ context "when $; is not nil" do
+ before do
+ suppress_warning do
+ @old_value, $; = $;, 'foobar'
end
+ end
- after do
- $; = @old_value
- end
+ after do
+ $; = @old_value
+ end
- it "warns" do
- -> { "".split }.should complain(/warning: \$; is set to non-nil value/)
- end
+ it "warns" do
+ -> { "".split }.should complain(/warning: \$; is set to non-nil value/)
end
end
end
@@ -207,24 +205,6 @@ describe "String#split with String" do
end
end
- ruby_version_is ''...'2.7' do
- it "taints the resulting strings if self is tainted" do
- ["", "x.y.z.", " x y "].each do |str|
- ["", ".", " "].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.dup.taint.split(pat).each do |x|
- x.should.tainted?
- end
-
- str.split(pat.dup.taint).each do |x|
- x.should_not.tainted?
- end
- end
- end
- end
- end
- end
-
it "returns an empty array when whitespace is split on whitespace" do
" ".split(" ").should == []
" \n ".split(" ").should == []
@@ -426,37 +406,6 @@ describe "String#split with Regexp" do
end
end
- ruby_version_is ''...'2.7' do
- it "taints the resulting strings if self is tainted" do
- ["", "x:y:z:", " x y "].each do |str|
- [//, /:/, /\s+/].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.dup.taint.split(pat, limit).each do |x|
- # See the spec below for why the conditional is here
- x.tainted?.should be_true unless x.empty?
- end
- end
- end
- end
- end
-
- it "taints an empty string if self is tainted" do
- ":".taint.split(//, -1).last.tainted?.should be_true
- end
-
- it "doesn't taints the resulting strings if the Regexp is tainted" do
- ["", "x:y:z:", " x y "].each do |str|
- [//, /:/, /\s+/].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.split(pat.dup.taint, limit).each do |x|
- x.tainted?.should be_false
- end
- end
- end
- end
- end
- end
-
it "retains the encoding of the source string" do
ary = "а б в".split
encodings = ary.map { |s| s.encoding }
diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb
index 6f75402c9c..5dc12a4247 100644
--- a/spec/ruby/core/string/squeeze_spec.rb
+++ b/spec/ruby/core/string/squeeze_spec.rb
@@ -54,16 +54,6 @@ describe "String#squeeze" do
-> { s.squeeze("^e-b") }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- "hello".taint.squeeze("e").should.tainted?
- "hello".taint.squeeze("a-z").should.tainted?
-
- "hello".squeeze("e".taint).should_not.tainted?
- "hello".squeeze("l".taint).should_not.tainted?
- end
- end
-
it "tries to convert each set arg to a string using to_str" do
other_string = mock('lo')
other_string.should_receive(:to_str).and_return("lo")
diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb
index da06862d06..e841db54ce 100644
--- a/spec/ruby/core/string/strip_spec.rb
+++ b/spec/ruby/core/string/strip_spec.rb
@@ -16,14 +16,6 @@ describe "String#strip" do
" \x00 goodbye \x00 ".strip.should == "goodbye"
end
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- "".taint.strip.should.tainted?
- "ok".taint.strip.should.tainted?
- " ok ".taint.strip.should.tainted?
- end
- end
end
describe "String#strip!" do
diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb
index 5ae9a4bbf3..9effe88c27 100644
--- a/spec/ruby/core/string/sub_spec.rb
+++ b/spec/ruby/core/string/sub_spec.rb
@@ -137,28 +137,6 @@ describe "String#sub with pattern, replacement" do
"hello".sub(/./, 'hah\\').should == 'hah\\ello'
end
- ruby_version_is ''...'2.7' do
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.sub(/./, a).should.tainted?
- hello_t.sub(/./, empty).should.tainted?
-
- hello.sub(/./, a_t).should.tainted?
- hello.sub(/./, empty_t).should.tainted?
- hello.sub(//, empty_t).should.tainted?
-
- hello.sub(//.taint, "foo").should_not.tainted?
- end
- end
-
it "tries to convert pattern to a string using to_str" do
pattern = mock('.')
pattern.should_receive(:to_str).and_return(".")
@@ -297,28 +275,6 @@ describe "String#sub with pattern and block" do
obj.should_receive(:to_s).and_return("ok")
"hello".sub(/.+/) { obj }.should == "ok"
end
-
- ruby_version_is ''...'2.7' do
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.sub(/./) { a }.should.tainted?
- hello_t.sub(/./) { empty }.should.tainted?
-
- hello.sub(/./) { a_t }.should.tainted?
- hello.sub(/./) { empty_t }.should.tainted?
- hello.sub(//) { empty_t }.should.tainted?
-
- hello.sub(//.taint) { "foo" }.should_not.tainted?
- end
- end
end
describe "String#sub! with pattern, replacement" do
@@ -328,14 +284,6 @@ describe "String#sub! with pattern, replacement" do
a.should == "h*llo"
end
- ruby_version_is ''...'2.7' do
- it "taints self if replacement is tainted" do
- a = "hello"
- a.sub!(/./.taint, "foo").should_not.tainted?
- a.sub!(/./, "foo".taint).should.tainted?
- end
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.sub!(/z/, '*').should == nil
@@ -378,14 +326,6 @@ describe "String#sub! with pattern and block" do
offsets.should == [[1, 2]]
end
- ruby_version_is ''...'2.7' do
- it "taints self if block's result is tainted" do
- a = "hello"
- a.sub!(/./.taint) { "foo" }.should_not.tainted?
- a.sub!(/./) { "foo".taint }.should.tainted?
- end
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.sub!(/z/) { '*' }.should == nil
@@ -471,28 +411,6 @@ describe "String#sub with pattern and Hash" do
"hello".sub(/(.+)/, 'hello' => repl ).should == repl
end
- ruby_version_is ''...'2.7' do
- it "untrusts the result if the original string is untrusted" do
- str = "Ghana".untrust
- str.sub(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts the result if a hash value is untrusted" do
- str = "Ghana"
- str.sub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "taints the result if the original string is tainted" do
- str = "Ghana".taint
- str.sub(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints the result if a hash value is tainted" do
- str = "Ghana"
- str.sub(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
- end
-
end
describe "String#sub! with pattern and Hash" do
@@ -557,28 +475,6 @@ describe "String#sub! with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".sub!(/(.+)/, 'hello' => repl ).should == repl
end
-
- ruby_version_is ''...'2.7' do
- it "keeps untrusted state" do
- str = "Ghana".untrust
- str.sub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts self if a hash value is untrusted" do
- str = "Ghana"
- str.sub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "keeps tainted state" do
- str = "Ghana".taint
- str.sub!(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints self if a hash value is tainted" do
- str = "Ghana"
- str.sub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
- end
end
describe "String#sub with pattern and without replacement and block" do
diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb
index 32b358607e..417f6c6d8d 100644
--- a/spec/ruby/core/string/swapcase_spec.rb
+++ b/spec/ruby/core/string/swapcase_spec.rb
@@ -9,13 +9,6 @@ describe "String#swapcase" do
"+++---111222???".swapcase.should == "+++---111222???"
end
- ruby_version_is ''...'2.7' do
- it "taints resulting string when self is tainted" do
- "".taint.swapcase.should.tainted?
- "hello".taint.swapcase.should.tainted?
- end
- end
-
describe "full Unicode case mapping" do
it "works for all of Unicode with no option" do
"äÖü".swapcase.should == "ÄöÜ"
diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb
index c6ad12139e..e1bb20ce35 100644
--- a/spec/ruby/core/string/tr_s_spec.rb
+++ b/spec/ruby/core/string/tr_s_spec.rb
@@ -57,19 +57,6 @@ describe "String#tr_s" do
end
end
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- ["h", "hello"].each do |str|
- tainted_str = str.dup.taint
-
- tainted_str.tr_s("e", "a").should.tainted?
-
- str.tr_s("e".taint, "a").should_not.tainted?
- str.tr_s("e", "a".taint).should_not.tainted?
- end
- end
- end
-
# http://redmine.ruby-lang.org/issues/show/1839
it "can replace a 7-bit ASCII character with a multibyte one" do
a = "uber"
diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb
index 06be1e6641..72adb9f2eb 100644
--- a/spec/ruby/core/string/tr_spec.rb
+++ b/spec/ruby/core/string/tr_spec.rb
@@ -69,19 +69,6 @@ describe "String#tr" do
end
end
- ruby_version_is ''...'2.7' do
- it "taints the result when self is tainted" do
- ["h", "hello"].each do |str|
- tainted_str = str.dup.taint
-
- tainted_str.tr("e", "a").should.tainted?
-
- str.tr("e".taint, "a").should_not.tainted?
- str.tr("e", "a".taint).should_not.tainted?
- end
- end
- end
-
# http://redmine.ruby-lang.org/issues/show/1839
it "can replace a 7-bit ASCII character with a multibyte one" do
a = "uber"
diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb
index b990aa25ee..08058d9bd1 100644
--- a/spec/ruby/core/string/undump_spec.rb
+++ b/spec/ruby/core/string/undump_spec.rb
@@ -3,16 +3,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "String#undump" do
- ruby_version_is ''...'2.7' do
- it "taints the result if self is tainted" do
- '"foo"'.taint.undump.should.tainted?
- end
-
- it "untrusts the result if self is untrusted" do
- '"foo"'.untrust.undump.should.untrusted?
- end
- end
-
it "does not take into account if a string is frozen" do
'"foo"'.freeze.undump.should_not.frozen?
end
diff --git a/spec/ruby/core/string/unpack/p_spec.rb b/spec/ruby/core/string/unpack/p_spec.rb
index 3e187d674f..cd48c0523d 100644
--- a/spec/ruby/core/string/unpack/p_spec.rb
+++ b/spec/ruby/core/string/unpack/p_spec.rb
@@ -18,12 +18,6 @@ describe "String#unpack with format 'P'" do
-> { packed.to_sym.to_s.unpack("P5") }.should raise_error(ArgumentError, /no associated pointer/)
end
- ruby_version_is ''...'2.7' do
- it "taints the unpacked string" do
- ["hello"].pack("P").unpack("P5").first.tainted?.should be_true
- end
- end
-
it "reads as many characters as specified" do
["hello"].pack("P").unpack("P1").should == ["h"]
end
@@ -47,10 +41,4 @@ describe "String#unpack with format 'p'" do
packed.dup.unpack("p").should == ["hello"]
-> { packed.to_sym.to_s.unpack("p") }.should raise_error(ArgumentError, /no associated pointer/)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the unpacked string" do
- ["hello"].pack("p").unpack("p").first.tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/string/unpack/shared/taint.rb b/spec/ruby/core/string/unpack/shared/taint.rb
index 061a3e26ad..79c7251f01 100644
--- a/spec/ruby/core/string/unpack/shared/taint.rb
+++ b/spec/ruby/core/string/unpack/shared/taint.rb
@@ -1,83 +1,2 @@
describe :string_unpack_taint, shared: true do
- ruby_version_is ''...'2.7' do
- it "does not taint returned arrays if given an untainted format string" do
- "".unpack(unpack_format(2)).tainted?.should be_false
- end
-
- it "does not taint returned arrays if given a tainted format string" do
- format_string = unpack_format(2).dup
- format_string.taint
- "".unpack(format_string).tainted?.should be_false
- end
-
- it "does not taint returned strings if given an untainted format string" do
- "".unpack(unpack_format(2)).any?(&:tainted?).should be_false
- end
-
- it "does not taint returned strings if given a tainted format string" do
- format_string = unpack_format(2).dup
- format_string.taint
- "".unpack(format_string).any?(&:tainted?).should be_false
- end
-
- it "does not taint returned arrays if given an untainted packed string" do
- "".unpack(unpack_format(2)).tainted?.should be_false
- end
-
- it "does not taint returned arrays if given a tainted packed string" do
- packed_string = ""
- packed_string.taint
- packed_string.unpack(unpack_format(2)).tainted?.should be_false
- end
-
- it "does not taint returned strings if given an untainted packed string" do
- "".unpack(unpack_format(2)).any?(&:tainted?).should be_false
- end
-
- it "taints returned strings if given a tainted packed string" do
- packed_string = ""
- packed_string.taint
- packed_string.unpack(unpack_format(2)).all?(&:tainted?).should be_true
- end
-
- it "does not untrust returned arrays if given an untrusted format string" do
- "".unpack(unpack_format(2)).untrusted?.should be_false
- end
-
- it "does not untrust returned arrays if given a untrusted format string" do
- format_string = unpack_format(2).dup
- format_string.untrust
- "".unpack(format_string).untrusted?.should be_false
- end
-
- it "does not untrust returned strings if given an untainted format string" do
- "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false
- end
-
- it "does not untrust returned strings if given a untrusted format string" do
- format_string = unpack_format(2).dup
- format_string.untrust
- "".unpack(format_string).any?(&:untrusted?).should be_false
- end
-
- it "does not untrust returned arrays if given an trusted packed string" do
- "".unpack(unpack_format(2)).untrusted?.should be_false
- end
-
- it "does not untrust returned arrays if given a untrusted packed string" do
- packed_string = ""
- packed_string.untrust
- packed_string.unpack(unpack_format(2)).untrusted?.should be_false
- end
-
- it "does not untrust returned strings if given an trusted packed string" do
- "".unpack(unpack_format(2)).any?(&:untrusted?).should be_false
- end
-
- it "untrusts returned strings if given a untrusted packed string" do
- packed_string = ""
- packed_string.untrust
- packed_string.unpack(unpack_format(2)).all?(&:untrusted?).should be_true
- end
- end
end
diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb
index 6cf44b4703..b2b34190fe 100644
--- a/spec/ruby/core/string/upcase_spec.rb
+++ b/spec/ruby/core/string/upcase_spec.rb
@@ -65,14 +65,6 @@ describe "String#upcase" do
-> { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "taints result when self is tainted" do
- "".taint.upcase.should.tainted?
- "X".taint.upcase.should.tainted?
- "x".taint.upcase.should.tainted?
- end
- end
-
ruby_version_is ''...'3.0' do
it "returns a subclass instance for subclasses" do
StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(StringSpecs::MyString)
diff --git a/spec/ruby/core/struct/deconstruct_keys_spec.rb b/spec/ruby/core/struct/deconstruct_keys_spec.rb
index f0a1f50ad3..088803d028 100644
--- a/spec/ruby/core/struct/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/struct/deconstruct_keys_spec.rb
@@ -1,78 +1,76 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Struct#deconstruct_keys" do
- it "returns a hash of attributes" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
-
- s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
- end
-
- it "requires one argument" do
- struct = Struct.new(:x)
- obj = struct.new(1)
-
- -> {
- obj.deconstruct_keys
- }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
- end
-
- it "returns only specified keys" do
- struct = Struct.new(:x, :y, :z)
- s = struct.new(1, 2, 3)
-
- s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
- s.deconstruct_keys([:x] ).should == {x: 1}
- s.deconstruct_keys([] ).should == {}
- end
-
- it "accepts string attribute names" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
-
- s.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
- end
-
- it "accepts argument position number as well but returns them as keys" do
- struct = Struct.new(:x, :y, :z)
- s = struct.new(10, 20, 30)
-
- s.deconstruct_keys([0, 1, 2]).should == {0 => 10, 1 => 20, 2 => 30}
- s.deconstruct_keys([0, 1] ).should == {0 => 10, 1 => 20}
- s.deconstruct_keys([0] ).should == {0 => 10}
- end
-
- it "returns an empty hash when there are more keys than attributes" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
-
- s.deconstruct_keys([:x, :y, :a]).should == {}
- end
-
- it "returns at first not existing attribute name" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
-
- s.deconstruct_keys([:a, :x]).should == {}
- s.deconstruct_keys([:x, :a]).should == {x: 1}
- end
-
- it "accepts nil argument and return all the attributes" do
- struct = Struct.new(:x, :y)
- obj = struct.new(1, 2)
-
- obj.deconstruct_keys(nil).should == {x: 1, y: 2}
- end
-
- it "raise TypeError if passed anything accept nil or array" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
-
- -> { s.deconstruct_keys('x') }.should raise_error(TypeError, /expected Array or nil/)
- -> { s.deconstruct_keys(1) }.should raise_error(TypeError, /expected Array or nil/)
- -> { s.deconstruct_keys(:x) }.should raise_error(TypeError, /expected Array or nil/)
- -> { s.deconstruct_keys({}) }.should raise_error(TypeError, /expected Array or nil/)
- end
+describe "Struct#deconstruct_keys" do
+ it "returns a hash of attributes" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ end
+
+ it "requires one argument" do
+ struct = Struct.new(:x)
+ obj = struct.new(1)
+
+ -> {
+ obj.deconstruct_keys
+ }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
+
+ it "returns only specified keys" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(1, 2, 3)
+
+ s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ s.deconstruct_keys([:x] ).should == {x: 1}
+ s.deconstruct_keys([] ).should == {}
+ end
+
+ it "accepts string attribute names" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
+ end
+
+ it "accepts argument position number as well but returns them as keys" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(10, 20, 30)
+
+ s.deconstruct_keys([0, 1, 2]).should == {0 => 10, 1 => 20, 2 => 30}
+ s.deconstruct_keys([0, 1] ).should == {0 => 10, 1 => 20}
+ s.deconstruct_keys([0] ).should == {0 => 10}
+ end
+
+ it "returns an empty hash when there are more keys than attributes" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:x, :y, :a]).should == {}
+ end
+
+ it "returns at first not existing attribute name" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:a, :x]).should == {}
+ s.deconstruct_keys([:x, :a]).should == {x: 1}
+ end
+
+ it "accepts nil argument and return all the attributes" do
+ struct = Struct.new(:x, :y)
+ obj = struct.new(1, 2)
+
+ obj.deconstruct_keys(nil).should == {x: 1, y: 2}
+ end
+
+ it "raise TypeError if passed anything accept nil or array" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ -> { s.deconstruct_keys('x') }.should raise_error(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys(1) }.should raise_error(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys(:x) }.should raise_error(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys({}) }.should raise_error(TypeError, /expected Array or nil/)
end
end
diff --git a/spec/ruby/core/struct/deconstruct_spec.rb b/spec/ruby/core/struct/deconstruct_spec.rb
index 7518a40987..32d4f6bac4 100644
--- a/spec/ruby/core/struct/deconstruct_spec.rb
+++ b/spec/ruby/core/struct/deconstruct_spec.rb
@@ -1,12 +1,10 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Struct#deconstruct" do
- it "returns an array of attribute values" do
- struct = Struct.new(:x, :y)
- s = struct.new(1, 2)
+describe "Struct#deconstruct" do
+ it "returns an array of attribute values" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
- s.deconstruct.should == [1, 2]
- end
+ s.deconstruct.should == [1, 2]
end
end
diff --git a/spec/ruby/core/symbol/end_with_spec.rb b/spec/ruby/core/symbol/end_with_spec.rb
index 77dc4caf71..4b9f5a4996 100644
--- a/spec/ruby/core/symbol/end_with_spec.rb
+++ b/spec/ruby/core/symbol/end_with_spec.rb
@@ -3,8 +3,6 @@
require_relative '../../spec_helper'
require_relative '../../shared/string/end_with'
-ruby_version_is "2.7" do
- describe "Symbol#end_with?" do
- it_behaves_like :end_with, :to_sym
- end
+describe "Symbol#end_with?" do
+ it_behaves_like :end_with, :to_sym
end
diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb
index 3f07f6aedb..0df87e183d 100644
--- a/spec/ruby/core/symbol/shared/slice.rb
+++ b/spec/ruby/core/symbol/shared/slice.rb
@@ -190,16 +190,6 @@ describe :symbol_slice, shared: true do
:symbol.send(@method, /[0-9]+/)
$~.should be_nil
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if the regexp is tainted" do
- :symbol.send(@method, /./.taint).tainted?.should be_true
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- :symbol.send(@method, /./.untrust).untrusted?.should be_true
- end
- end
end
describe "with a capture index" do
@@ -221,16 +211,6 @@ describe :symbol_slice, shared: true do
:symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy"
end
- ruby_version_is ''...'2.7' do
- it "returns a tainted string if the regexp is tainted" do
- :symbol.send(@method, /(.)/.taint, 1).tainted?.should be_true
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- :symbol.send(@method, /(.)/.untrust, 1).untrusted?.should be_true
- end
- end
-
describe "and an index that cannot be converted to an Integer" do
it "raises a TypeError when given an Hash" do
-> { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError)
diff --git a/spec/ruby/core/symbol/start_with_spec.rb b/spec/ruby/core/symbol/start_with_spec.rb
index f54b3e499e..cd43279003 100644
--- a/spec/ruby/core/symbol/start_with_spec.rb
+++ b/spec/ruby/core/symbol/start_with_spec.rb
@@ -3,8 +3,6 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative '../../shared/string/start_with'
-ruby_version_is "2.7" do
- describe "Symbol#start_with?" do
- it_behaves_like :start_with, :to_sym
- end
+describe "Symbol#start_with?" do
+ it_behaves_like :start_with, :to_sym
end
diff --git a/spec/ruby/core/thread/backtrace_locations_spec.rb b/spec/ruby/core/thread/backtrace_locations_spec.rb
index 237941c214..c970ae023b 100644
--- a/spec/ruby/core/thread/backtrace_locations_spec.rb
+++ b/spec/ruby/core/thread/backtrace_locations_spec.rb
@@ -49,12 +49,10 @@ describe "Thread#backtrace_locations" do
locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
end
- ruby_version_is "2.7" do
- it "can be called with an beginless range" do
- locations1 = Thread.current.backtrace_locations(0)
- locations2 = Thread.current.backtrace_locations(eval("(..5)"))
- locations2.map(&:to_s)[eval("(2..)")].should == locations1[eval("(..5)")].map(&:to_s)[eval("(2..)")]
- end
+ it "can be called with an beginless range" do
+ locations1 = Thread.current.backtrace_locations(0)
+ locations2 = Thread.current.backtrace_locations((..5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(..5)].map(&:to_s)[eval("(2..)")]
end
it "returns nil if omitting more locations than available" do
diff --git a/spec/ruby/core/thread/report_on_exception_spec.rb b/spec/ruby/core/thread/report_on_exception_spec.rb
index e7f400819a..9279fa1da5 100644
--- a/spec/ruby/core/thread/report_on_exception_spec.rb
+++ b/spec/ruby/core/thread/report_on_exception_spec.rb
@@ -61,6 +61,36 @@ describe "Thread#report_on_exception=" do
}.should raise_error(RuntimeError, "Thread#report_on_exception specs")
end
+ ruby_version_is "3.0" do
+ it "prints a backtrace on $stderr in the regular backtrace order" do
+ line_raise = __LINE__ + 2
+ def foo
+ raise RuntimeError, "Thread#report_on_exception specs backtrace order"
+ end
+
+ line_call_foo = __LINE__ + 5
+ go = false
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ Thread.pass until go
+ foo
+ }
+
+ -> {
+ go = true
+ Thread.pass while t.alive?
+ }.should output("", <<ERR)
+#{t.inspect} terminated with exception (report_on_exception is true):
+#{__FILE__}:#{line_raise}:in `foo': Thread#report_on_exception specs backtrace order (RuntimeError)
+\tfrom #{__FILE__}:#{line_call_foo}:in `block (5 levels) in <top (required)>'
+ERR
+
+ -> {
+ t.join
+ }.should raise_error(RuntimeError, "Thread#report_on_exception specs backtrace order")
+ end
+ end
+
it "prints the backtrace even if the thread was killed just after Thread#raise" do
t = nil
ready = false
diff --git a/spec/ruby/core/thread/shared/to_s.rb b/spec/ruby/core/thread/shared/to_s.rb
index 45c04af627..43640deb33 100644
--- a/spec/ruby/core/thread/shared/to_s.rb
+++ b/spec/ruby/core/thread/shared/to_s.rb
@@ -1,12 +1,10 @@
require_relative '../fixtures/classes'
describe :thread_to_s, shared: true do
- sep = ruby_version_is("2.7") ? " " : "@"
-
it "returns a description including file and line number" do
thread, line = Thread.new { "hello" }, __LINE__
thread.join
- thread.send(@method).should =~ /^#<Thread:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{line} \w+>$/
+ thread.send(@method).should =~ /^#<Thread:([^ ]*?) #{Regexp.escape __FILE__}:#{line} \w+>$/
end
it "has a binary encoding" do
diff --git a/spec/ruby/core/time/ceil_spec.rb b/spec/ruby/core/time/ceil_spec.rb
index 86029554db..9d624a1ed0 100644
--- a/spec/ruby/core/time/ceil_spec.rb
+++ b/spec/ruby/core/time/ceil_spec.rb
@@ -1,46 +1,44 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Time#ceil" do
- before do
- @time = Time.utc(2010, 3, 30, 5, 43, "25.0123456789".to_r)
- end
-
- it "defaults to ceiling to 0 places" do
- @time.ceil.should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
- end
+describe "Time#ceil" do
+ before do
+ @time = Time.utc(2010, 3, 30, 5, 43, "25.0123456789".to_r)
+ end
- it "ceils to 0 decimal places with an explicit argument" do
- @time.ceil(0).should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
- end
+ it "defaults to ceiling to 0 places" do
+ @time.ceil.should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
+ end
- it "ceils to 2 decimal places with an explicit argument" do
- @time.ceil(2).should == Time.utc(2010, 3, 30, 5, 43, "25.02".to_r)
- end
+ it "ceils to 0 decimal places with an explicit argument" do
+ @time.ceil(0).should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
+ end
- it "ceils to 4 decimal places with an explicit argument" do
- @time.ceil(4).should == Time.utc(2010, 3, 30, 5, 43, "25.0124".to_r)
- end
+ it "ceils to 2 decimal places with an explicit argument" do
+ @time.ceil(2).should == Time.utc(2010, 3, 30, 5, 43, "25.02".to_r)
+ end
- it "ceils to 7 decimal places with an explicit argument" do
- @time.ceil(7).should == Time.utc(2010, 3, 30, 5, 43, "25.0123457".to_r)
- end
+ it "ceils to 4 decimal places with an explicit argument" do
+ @time.ceil(4).should == Time.utc(2010, 3, 30, 5, 43, "25.0124".to_r)
+ end
- it "returns an instance of Time, even if #ceil is called on a subclass" do
- subclass = Class.new(Time)
- instance = subclass.at(0)
- instance.class.should equal subclass
- instance.ceil.should be_an_instance_of(Time)
- end
+ it "ceils to 7 decimal places with an explicit argument" do
+ @time.ceil(7).should == Time.utc(2010, 3, 30, 5, 43, "25.0123457".to_r)
+ end
- it "copies own timezone to the returning value" do
- @time.zone.should == @time.ceil.zone
+ it "returns an instance of Time, even if #ceil is called on a subclass" do
+ subclass = Class.new(Time)
+ instance = subclass.at(0)
+ instance.class.should equal subclass
+ instance.ceil.should be_an_instance_of(Time)
+ end
- time = with_timezone "JST-9" do
- Time.at 0, 1
- end
+ it "copies own timezone to the returning value" do
+ @time.zone.should == @time.ceil.zone
- time.zone.should == time.ceil.zone
+ time = with_timezone "JST-9" do
+ Time.at 0, 1
end
+
+ time.zone.should == time.ceil.zone
end
end
diff --git a/spec/ruby/core/time/floor_spec.rb b/spec/ruby/core/time/floor_spec.rb
index a19585b787..b0003469c9 100644
--- a/spec/ruby/core/time/floor_spec.rb
+++ b/spec/ruby/core/time/floor_spec.rb
@@ -1,38 +1,36 @@
require_relative '../../spec_helper'
-ruby_version_is "2.7" do
- describe "Time#floor" do
- before do
- @time = Time.utc(2010, 3, 30, 5, 43, "25.123456789".to_r)
- end
-
- it "defaults to flooring to 0 places" do
- @time.floor.should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
- end
+describe "Time#floor" do
+ before do
+ @time = Time.utc(2010, 3, 30, 5, 43, "25.123456789".to_r)
+ end
- it "floors to 0 decimal places with an explicit argument" do
- @time.floor(0).should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
- end
+ it "defaults to flooring to 0 places" do
+ @time.floor.should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
+ end
- it "floors to 7 decimal places with an explicit argument" do
- @time.floor(7).should == Time.utc(2010, 3, 30, 5, 43, "25.1234567".to_r)
- end
+ it "floors to 0 decimal places with an explicit argument" do
+ @time.floor(0).should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
+ end
- it "returns an instance of Time, even if #floor is called on a subclass" do
- subclass = Class.new(Time)
- instance = subclass.at(0)
- instance.class.should equal subclass
- instance.floor.should be_an_instance_of(Time)
- end
+ it "floors to 7 decimal places with an explicit argument" do
+ @time.floor(7).should == Time.utc(2010, 3, 30, 5, 43, "25.1234567".to_r)
+ end
- it "copies own timezone to the returning value" do
- @time.zone.should == @time.floor.zone
+ it "returns an instance of Time, even if #floor is called on a subclass" do
+ subclass = Class.new(Time)
+ instance = subclass.at(0)
+ instance.class.should equal subclass
+ instance.floor.should be_an_instance_of(Time)
+ end
- time = with_timezone "JST-9" do
- Time.at 0, 1
- end
+ it "copies own timezone to the returning value" do
+ @time.zone.should == @time.floor.zone
- time.zone.should == time.floor.zone
+ time = with_timezone "JST-9" do
+ Time.at 0, 1
end
+
+ time.zone.should == time.floor.zone
end
end
diff --git a/spec/ruby/core/time/inspect_spec.rb b/spec/ruby/core/time/inspect_spec.rb
index 6f1b2e3ef1..c3a4519a24 100644
--- a/spec/ruby/core/time/inspect_spec.rb
+++ b/spec/ruby/core/time/inspect_spec.rb
@@ -4,32 +4,30 @@ require_relative 'shared/inspect'
describe "Time#inspect" do
it_behaves_like :inspect, :inspect
- ruby_version_is "2.7" do
- it "preserves microseconds" do
- t = Time.utc(2007, 11, 1, 15, 25, 0, 123456)
- t.inspect.should == "2007-11-01 15:25:00.123456 UTC"
- end
+ it "preserves microseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 123456)
+ t.inspect.should == "2007-11-01 15:25:00.123456 UTC"
+ end
- it "omits trailing zeros from microseconds" do
- t = Time.utc(2007, 11, 1, 15, 25, 0, 100000)
- t.inspect.should == "2007-11-01 15:25:00.1 UTC"
- end
+ it "omits trailing zeros from microseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 100000)
+ t.inspect.should == "2007-11-01 15:25:00.1 UTC"
+ end
- it "uses the correct time zone without microseconds" do
- t = Time.utc(2000, 1, 1)
- t = t.localtime(9*3600)
- t.inspect.should == "2000-01-01 09:00:00 +0900"
- end
+ it "uses the correct time zone without microseconds" do
+ t = Time.utc(2000, 1, 1)
+ t = t.localtime(9*3600)
+ t.inspect.should == "2000-01-01 09:00:00 +0900"
+ end
- it "uses the correct time zone with microseconds" do
- t = Time.utc(2000, 1, 1, 0, 0, 0, 123456)
- t = t.localtime(9*3600)
- t.inspect.should == "2000-01-01 09:00:00.123456 +0900"
- end
+ it "uses the correct time zone with microseconds" do
+ t = Time.utc(2000, 1, 1, 0, 0, 0, 123456)
+ t = t.localtime(9*3600)
+ t.inspect.should == "2000-01-01 09:00:00.123456 +0900"
+ end
- it "preserves nanoseconds" do
- t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
- t.inspect.should == "2007-11-01 15:25:00.123456789 UTC"
- end
+ it "preserves nanoseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
+ t.inspect.should == "2007-11-01 15:25:00.123456789 UTC"
end
end
diff --git a/spec/ruby/core/true/to_s_spec.rb b/spec/ruby/core/true/to_s_spec.rb
index f26cd138e2..fa1b53a580 100644
--- a/spec/ruby/core/true/to_s_spec.rb
+++ b/spec/ruby/core/true/to_s_spec.rb
@@ -5,13 +5,11 @@ describe "TrueClass#to_s" do
true.to_s.should == "true"
end
- ruby_version_is "2.7" do
- it "returns a frozen string" do
- true.to_s.should.frozen?
- end
+ it "returns a frozen string" do
+ true.to_s.should.frozen?
+ end
- it "always returns the same string" do
- true.to_s.should equal(true.to_s)
- end
+ it "always returns the same string" do
+ true.to_s.should equal(true.to_s)
end
end
diff --git a/spec/ruby/core/unboundmethod/bind_call_spec.rb b/spec/ruby/core/unboundmethod/bind_call_spec.rb
index c5d392156c..8f25f8bd0d 100644
--- a/spec/ruby/core/unboundmethod/bind_call_spec.rb
+++ b/spec/ruby/core/unboundmethod/bind_call_spec.rb
@@ -1,52 +1,50 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is '2.7' do
- describe "UnboundMethod#bind_call" do
- before :each do
- @normal_um = UnboundMethodSpecs::Methods.new.method(:foo).unbind
- @parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
- @child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
- @child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
- end
+describe "UnboundMethod#bind_call" do
+ before :each do
+ @normal_um = UnboundMethodSpecs::Methods.new.method(:foo).unbind
+ @parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
+ @child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
+ @child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
+ end
- it "raises TypeError if object is not kind_of? the Module the method defined in" do
- -> { @normal_um.bind_call(UnboundMethodSpecs::B.new) }.should raise_error(TypeError)
- end
+ it "raises TypeError if object is not kind_of? the Module the method defined in" do
+ -> { @normal_um.bind_call(UnboundMethodSpecs::B.new) }.should raise_error(TypeError)
+ end
- it "binds and calls the method if object is kind_of the Module the method defined in" do
- @normal_um.bind_call(UnboundMethodSpecs::Methods.new).should == true
- end
+ it "binds and calls the method if object is kind_of the Module the method defined in" do
+ @normal_um.bind_call(UnboundMethodSpecs::Methods.new).should == true
+ end
- it "binds and calls the method on any object when UnboundMethod is unbound from a module" do
- UnboundMethodSpecs::Mod.instance_method(:from_mod).bind_call(Object.new).should == nil
- end
+ it "binds and calls the method on any object when UnboundMethod is unbound from a module" do
+ UnboundMethodSpecs::Mod.instance_method(:from_mod).bind_call(Object.new).should == nil
+ end
- it "binds and calls the method for any object kind_of? the Module the method is defined in" do
- @parent_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
- @child1_um.bind_call(UnboundMethodSpecs::Parent.new).should == nil
- @child2_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
- end
+ it "binds and calls the method for any object kind_of? the Module the method is defined in" do
+ @parent_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
+ @child1_um.bind_call(UnboundMethodSpecs::Parent.new).should == nil
+ @child2_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
+ end
- it "binds and calls a Kernel method retrieved from Object on BasicObject" do
- Object.instance_method(:instance_of?).bind_call(BasicObject.new, BasicObject).should == true
- end
+ it "binds and calls a Kernel method retrieved from Object on BasicObject" do
+ Object.instance_method(:instance_of?).bind_call(BasicObject.new, BasicObject).should == true
+ end
- it "binds and calls a Parent's class method to any Child's class methods" do
- um = UnboundMethodSpecs::Parent.method(:class_method).unbind
- um.bind_call(UnboundMethodSpecs::Child1).should == "I am UnboundMethodSpecs::Child1"
- end
+ it "binds and calls a Parent's class method to any Child's class methods" do
+ um = UnboundMethodSpecs::Parent.method(:class_method).unbind
+ um.bind_call(UnboundMethodSpecs::Child1).should == "I am UnboundMethodSpecs::Child1"
+ end
- it "will raise when binding a an object singleton's method to another object" do
- other = UnboundMethodSpecs::Parent.new
- p = UnboundMethodSpecs::Parent.new
- class << p
- def singleton_method
- :single
- end
+ it "will raise when binding a an object singleton's method to another object" do
+ other = UnboundMethodSpecs::Parent.new
+ p = UnboundMethodSpecs::Parent.new
+ class << p
+ def singleton_method
+ :single
end
- um = p.method(:singleton_method).unbind
- ->{ um.bind_call(other) }.should raise_error(TypeError)
end
+ um = p.method(:singleton_method).unbind
+ ->{ um.bind_call(other) }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/core/warning/element_reference_spec.rb b/spec/ruby/core/warning/element_reference_spec.rb
index f51cc87de5..67728ca0f6 100644
--- a/spec/ruby/core/warning/element_reference_spec.rb
+++ b/spec/ruby/core/warning/element_reference_spec.rb
@@ -1,22 +1,20 @@
require_relative '../../spec_helper'
-ruby_version_is '2.7' do
- describe "Warning.[]" do
- ruby_version_is '2.7.2' do
- it "returns default values for categories :deprecated and :experimental" do
- ruby_exe('p Warning[:deprecated]').chomp.should == "false"
- ruby_exe('p Warning[:experimental]').chomp.should == "true"
- end
+describe "Warning.[]" do
+ ruby_version_is '2.7.2' do
+ it "returns default values for categories :deprecated and :experimental" do
+ ruby_exe('p Warning[:deprecated]').chomp.should == "false"
+ ruby_exe('p Warning[:experimental]').chomp.should == "true"
end
+ end
- it "raises for unknown category" do
- -> { Warning[:noop] }.should raise_error(ArgumentError, /unknown category: noop/)
- end
+ it "raises for unknown category" do
+ -> { Warning[:noop] }.should raise_error(ArgumentError, /unknown category: noop/)
+ end
- it "raises for non-Symbol category" do
- -> { Warning[42] }.should raise_error(TypeError)
- -> { Warning[false] }.should raise_error(TypeError)
- -> { Warning["noop"] }.should raise_error(TypeError)
- end
+ it "raises for non-Symbol category" do
+ -> { Warning[42] }.should raise_error(TypeError)
+ -> { Warning[false] }.should raise_error(TypeError)
+ -> { Warning["noop"] }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb
index 611060fb3a..d20ee215ad 100644
--- a/spec/ruby/core/warning/element_set_spec.rb
+++ b/spec/ruby/core/warning/element_set_spec.rb
@@ -1,37 +1,35 @@
require_relative '../../spec_helper'
-ruby_version_is '2.7' do
- describe "Warning.[]=" do
- it "emits and suppresses warnings for :deprecated" do
- ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/
- ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == ""
- end
-
- describe ":experimental" do
- before do
- ruby_version_is ""..."3.0" do
- @src = 'case [0, 1]; in [a, b]; end'
- end
+describe "Warning.[]=" do
+ it "emits and suppresses warnings for :deprecated" do
+ ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/
+ ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == ""
+ end
- ruby_version_is "3.0" do
- @src = 'warn "This is experimental warning.", category: :experimental'
- end
+ describe ":experimental" do
+ before do
+ ruby_version_is ""..."3.0" do
+ @src = 'case [0, 1]; in [a, b]; end'
end
- it "emits and suppresses warnings for :experimental" do
- ruby_exe("Warning[:experimental] = true; eval('#{@src}')", args: "2>&1").should =~ /is experimental/
- ruby_exe("Warning[:experimental] = false; eval('#{@src}')", args: "2>&1").should == ""
+ ruby_version_is "3.0" do
+ @src = 'warn "This is experimental warning.", category: :experimental'
end
end
- it "raises for unknown category" do
- -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/)
+ it "emits and suppresses warnings for :experimental" do
+ ruby_exe("Warning[:experimental] = true; eval('#{@src}')", args: "2>&1").should =~ /is experimental/
+ ruby_exe("Warning[:experimental] = false; eval('#{@src}')", args: "2>&1").should == ""
end
+ end
- it "raises for non-Symbol category" do
- -> { Warning[42] = false }.should raise_error(TypeError)
- -> { Warning[false] = false }.should raise_error(TypeError)
- -> { Warning["noop"] = false }.should raise_error(TypeError)
- end
+ it "raises for unknown category" do
+ -> { Warning[:noop] = false }.should raise_error(ArgumentError, /unknown category: noop/)
+ end
+
+ it "raises for non-Symbol category" do
+ -> { Warning[42] = false }.should raise_error(TypeError)
+ -> { Warning[false] = false }.should raise_error(TypeError)
+ -> { Warning["noop"] = false }.should raise_error(TypeError)
end
end
diff --git a/spec/ruby/language/alias_spec.rb b/spec/ruby/language/alias_spec.rb
index d1d06e3fac..c353390679 100644
--- a/spec/ruby/language/alias_spec.rb
+++ b/spec/ruby/language/alias_spec.rb
@@ -243,6 +243,19 @@ describe "The alias keyword" do
e.class.should == NameError
}
end
+
+ it "defines the method on the aliased class when the original method is from a parent class" do
+ parent = Class.new do
+ def parent_method
+ end
+ end
+ child = Class.new(parent) do
+ alias parent_method_alias parent_method
+ end
+
+ child.instance_method(:parent_method_alias).owner.should == child
+ child.instance_methods(false).should include(:parent_method_alias)
+ end
end
describe "The alias keyword" do
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index f213d68ba1..42652152a1 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -101,17 +101,7 @@ describe "A block yielded a single" do
end
end
- ruby_version_is ""..."2.7" do
- it "calls #to_hash on the argument and uses resulting hash as first argument when optional argument and keyword argument accepted" do
- obj = mock("coerce block keyword arguments")
- obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
-
- result = m([obj]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1, "b" => 2}, {}]
- end
- end
-
- ruby_version_is "2.7"...'3.0' do
+ ruby_version_is ""...'3.0' do
it "calls #to_hash on the argument but ignores result when optional argument and keyword argument accepted" do
obj = mock("coerce block keyword arguments")
obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
@@ -958,38 +948,18 @@ describe "Post-args" do
end
describe "with a circular argument reference" do
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local variable with same name" do
- a = 1
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
-
- it "warns and uses a nil value when there is an existing method with same name" do
- def a; 1; end
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
+ it "raises a SyntaxError if using an existing local with the same name as the argument" do
+ a = 1
+ -> {
+ @proc = eval "proc { |a=a| a }"
+ }.should raise_error(SyntaxError)
end
- ruby_version_is '2.7' do
- it "raises a SyntaxError if using an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should raise_error(SyntaxError)
- end
-
- it "raises a SyntaxError if there is an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should raise_error(SyntaxError)
- end
+ it "raises a SyntaxError if there is an existing method with the same name as the argument" do
+ def a; 1; end
+ -> {
+ @proc = eval "proc { |a=a| a }"
+ }.should raise_error(SyntaxError)
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
diff --git a/spec/ruby/language/comment_spec.rb b/spec/ruby/language/comment_spec.rb
index 690e844dc0..dd788e681c 100644
--- a/spec/ruby/language/comment_spec.rb
+++ b/spec/ruby/language/comment_spec.rb
@@ -1,15 +1,13 @@
require_relative '../spec_helper'
describe "The comment" do
- ruby_version_is "2.7" do
- it "can be placed between fluent dot now" do
- code = <<~CODE
- 10
- # some comment
- .to_s
- CODE
+ it "can be placed between fluent dot now" do
+ code = <<~CODE
+ 10
+ # some comment
+ .to_s
+ CODE
- eval(code).should == '10'
- end
+ eval(code).should == '10'
end
end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index d72f8fa888..c8531343c0 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -197,32 +197,15 @@ describe "An instance method with a default argument" do
foo(2,3,3).should == [2,3,[3]]
end
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local method with same name" do
- def bar
- 1
- end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should complain(/circular argument reference/)
- foo.should == nil
- foo(2).should == 2
- end
- end
-
- ruby_version_is '2.7' do
- it "raises a SyntaxError when there is an existing method with the same name as the local variable" do
- def bar
- 1
- end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should raise_error(SyntaxError)
+ it "raises a SyntaxError when there is an existing method with the same name as the local variable" do
+ def bar
+ 1
end
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end"
+ }.should raise_error(SyntaxError)
end
it "calls a method with the same name as the local when explicitly using ()" do
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index 38345c3727..ae2bf45bda 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -48,6 +48,20 @@ describe "The defined? keyword for literals" do
end
describe "The defined? keyword when called with a method name" do
+ before :each do
+ ScratchPad.clear
+ end
+
+ it "does not call the method" do
+ defined?(DefinedSpecs.side_effects).should == "method"
+ ScratchPad.recorded.should != :defined_specs_side_effects
+ end
+
+ it "does not execute the arguments" do
+ defined?(DefinedSpecs.any_args(DefinedSpecs.side_effects)).should == "method"
+ ScratchPad.recorded.should != :defined_specs_side_effects
+ end
+
describe "without a receiver" do
it "returns 'method' if the method is defined" do
ret = defined?(puts)
diff --git a/spec/ruby/language/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb
index 8e4183cbcc..3f24a79d5c 100644
--- a/spec/ruby/language/delegation_spec.rb
+++ b/spec/ruby/language/delegation_spec.rb
@@ -1,42 +1,40 @@
require_relative '../spec_helper'
require_relative 'fixtures/delegation'
-ruby_version_is "2.7" do
- describe "delegation with def(...)" do
- it "delegates rest and kwargs" do
- a = Class.new(DelegationSpecs::Target)
- a.class_eval(<<-RUBY)
- def delegate(...)
- target(...)
- end
- RUBY
+describe "delegation with def(...)" do
+ it "delegates rest and kwargs" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(...)
+ end
+ RUBY
- a.new.delegate(1, b: 2).should == [[1], {b: 2}]
- end
+ a.new.delegate(1, b: 2).should == [[1], {b: 2}]
+ end
- it "delegates block" do
- a = Class.new(DelegationSpecs::Target)
- a.class_eval(<<-RUBY)
- def delegate_block(...)
- target_block(...)
- end
- RUBY
+ it "delegates block" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate_block(...)
+ target_block(...)
+ end
+ RUBY
- a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
- end
+ a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
+ end
- it "parses as open endless Range when brackets are omitted" do
- a = Class.new(DelegationSpecs::Target)
- suppress_warning do
- a.class_eval(<<-RUBY)
- def delegate(...)
- target ...
- end
- RUBY
- end
+ it "parses as open endless Range when brackets are omitted" do
+ a = Class.new(DelegationSpecs::Target)
+ suppress_warning do
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target ...
+ end
+ RUBY
+ end
- a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true)
- end
+ a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true)
end
end
@@ -63,6 +61,5 @@ ruby_version_is "2.7.3" do
a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end
-
end
end
diff --git a/spec/ruby/language/fixtures/defined.rb b/spec/ruby/language/fixtures/defined.rb
index 8b6004c19f..a9552619bf 100644
--- a/spec/ruby/language/fixtures/defined.rb
+++ b/spec/ruby/language/fixtures/defined.rb
@@ -19,6 +19,9 @@ module DefinedSpecs
DefinedSpecs
end
+ def self.any_args(*)
+ end
+
class Basic
A = 42
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb b/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
index a4d655ad02..cccc5969bd 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-p "abc".object_id == "abc".object_id
+p "abc".equal?("abc")
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index 2f8b97199a..c84564d3ea 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -148,18 +148,9 @@ describe "Hash literal" do
{a: 1, **obj, c: 3}.should == {a:1, b: 2, c: 3, d: 4}
end
- ruby_version_is ""..."2.7" do
- it "raises a TypeError if any splatted elements keys are not symbols" do
- h = {1 => 2, b: 3}
- -> { {a: 1, **h} }.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.7" do
- it "allows splatted elements keys that are not symbols" do
- h = {1 => 2, b: 3}
- {a: 1, **h}.should == {a: 1, 1 => 2, b: 3}
- end
+ it "allows splatted elements keys that are not symbols" do
+ h = {1 => 2, b: 3}
+ {a: 1, **h}.should == {a: 1, 1 => 2, b: 3}
end
it "raises a TypeError if #to_hash does not return a Hash" do
diff --git a/spec/ruby/language/heredoc_spec.rb b/spec/ruby/language/heredoc_spec.rb
index 61a27ad8e0..b3b160fd11 100644
--- a/spec/ruby/language/heredoc_spec.rb
+++ b/spec/ruby/language/heredoc_spec.rb
@@ -59,20 +59,10 @@ HERE
s.encoding.should == Encoding::US_ASCII
end
- ruby_version_is "2.7" do
- it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do
- -> {
- eval %{<<"HERE\n"\nraises syntax error\nHERE}
- }.should raise_error(SyntaxError)
- end
- end
-
- ruby_version_is ""..."2.7" do
- it 'prints a warning if quoted HEREDOC identifier is ending not on same line' do
- -> {
- eval %{<<"HERE\n"\nit warns\nHERE}
- }.should complain(/here document identifier ends with a newline/)
- end
+ it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do
+ -> {
+ eval %{<<"HERE\n"\nraises syntax error\nHERE}
+ }.should raise_error(SyntaxError)
end
it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
diff --git a/spec/ruby/language/keyword_arguments_spec.rb b/spec/ruby/language/keyword_arguments_spec.rb
index 66e37915a2..0c72f59d38 100644
--- a/spec/ruby/language/keyword_arguments_spec.rb
+++ b/spec/ruby/language/keyword_arguments_spec.rb
@@ -302,6 +302,63 @@ ruby_version_is "3.0" do
m(a: 1).should == [[{a: 1}], {}]
m({a: 1}).should == [[{a: 1}], {}]
end
+
+ ruby_version_is "3.2" do
+ it "does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" do
+ class << self
+ def n(*args) # Note the missing ruby2_keywords here
+ target(*args)
+ end
+
+ ruby2_keywords def m(*args)
+ n(*args)
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[{a: 1}], {}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+ end
+
+ ruby_version_is ""..."3.2" do
+ # https://bugs.ruby-lang.org/issues/18625
+ it "works with call(*ruby2_keyword_args) with missing ruby2_keywords in between due to CRuby bug #18625" do
+ class << self
+ def n(*args) # Note the missing ruby2_keywords here
+ target(*args)
+ end
+
+ ruby2_keywords def m(*args)
+ n(*args)
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+ m(empty).should == [[{}], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+
+ kw = {a: 1}
+
+ m(**kw).should == [[], {a: 1}]
+ m(**kw)[1].should == kw
+ m(**kw)[1].should_not.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false
+
+ m(kw).should == [[{a: 1}], {}]
+ m(kw)[0][0].should.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ end
+ end
end
end
end
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 6393fb5c47..a3f01ec04b 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -281,38 +281,18 @@ describe "A lambda literal -> () { }" do
end
describe "with circular optional argument reference" do
- ruby_version_is ''...'2.7' do
- it "warns and uses a nil value when there is an existing local variable with same name" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
-
- it "warns and uses a nil value when there is an existing method with same name" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
- end
+ it "raises a SyntaxError if using an existing local with the same name as the argument" do
+ a = 1
+ -> {
+ @proc = eval "-> (a=a) { a }"
+ }.should raise_error(SyntaxError)
end
- ruby_version_is '2.7' do
- it "raises a SyntaxError if using an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should raise_error(SyntaxError)
- end
-
- it "raises a SyntaxError if there is an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should raise_error(SyntaxError)
- end
+ it "raises a SyntaxError if there is an existing method with the same name as the argument" do
+ def a; 1; end
+ -> {
+ @proc = eval "-> (a=a) { a }"
+ }.should raise_error(SyntaxError)
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
@@ -360,26 +340,12 @@ describe "A lambda expression 'lambda { ... }'" do
def meth; lambda; end
end
- ruby_version_is ""..."2.7" do
- it "can be created" do
- implicit_lambda = nil
+ it "raises ArgumentError" do
+ implicit_lambda = nil
+ suppress_warning do
-> {
- implicit_lambda = meth { 1 }
- }.should complain(/tried to create Proc object without a block/)
-
- implicit_lambda.lambda?.should be_true
- implicit_lambda.call.should == 1
- end
- end
-
- ruby_version_is "2.7" do
- it "raises ArgumentError" do
- implicit_lambda = nil
- suppress_warning do
- -> {
- meth { 1 }
- }.should raise_error(ArgumentError, /tried to create Proc object without a block/)
- end
+ meth { 1 }
+ }.should raise_error(ArgumentError, /tried to create Proc object without a block/)
end
end
end
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index 0a5bb99d0b..d464e79403 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -602,13 +602,11 @@ describe "A method" do
-> { m(2) }.should raise_error(ArgumentError)
end
- ruby_version_is "2.7" do
- evaluate <<-ruby do
- def m(**k); k end;
- ruby
+ evaluate <<-ruby do
+ def m(**k); k end;
+ ruby
- m("a" => 1).should == { "a" => 1 }
- end
+ m("a" => 1).should == { "a" => 1 }
end
evaluate <<-ruby do
@@ -962,26 +960,13 @@ describe "A method" do
end
end
- ruby_version_is ""..."2.7" do
- evaluate <<-ruby do
- def m(a=1, **) a end
- ruby
-
- m().should == 1
- m(2, a: 1, b: 0).should == 2
- m("a" => 1, a: 2).should == {"a" => 1}
- end
- end
-
- ruby_version_is "2.7" do
- evaluate <<-ruby do
- def m(a=1, **) a end
- ruby
+ evaluate <<-ruby do
+ def m(a=1, **) a end
+ ruby
- m().should == 1
- m(2, a: 1, b: 0).should == 2
- m("a" => 1, a: 2).should == 1
- end
+ m().should == 1
+ m(2, a: 1, b: 0).should == 2
+ m("a" => 1, a: 2).should == 1
end
evaluate <<-ruby do
@@ -1021,164 +1006,7 @@ describe "A method" do
m(1, 2, 3).should == [[1, 2], 3]
end
- ruby_version_is ""..."2.7" do
- evaluate <<-ruby do
- def m(*, a:) a end
- ruby
-
- m(a: 1).should == 1
- m(1, 2, a: 3).should == 3
- suppress_keyword_warning do
- m("a" => 1, a: 2).should == 2
- end
- end
-
- evaluate <<-ruby do
- def m(*a, b:) [a, b] end
- ruby
-
- m(b: 1).should == [[], 1]
- m(1, 2, b: 3).should == [[1, 2], 3]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
- end
- end
-
- evaluate <<-ruby do
- def m(*, a: 1) a end
- ruby
-
- m().should == 1
- m(1, 2).should == 1
- m(a: 2).should == 2
- m(1, a: 2).should == 2
- suppress_keyword_warning do
- m("a" => 1, a: 2).should == 2
- end
- end
-
- evaluate <<-ruby do
- def m(*a, b: 1) [a, b] end
- ruby
-
- m().should == [[], 1]
- m(1, 2, 3, b: 4).should == [[1, 2, 3], 4]
- suppress_keyword_warning do
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
- end
-
- a = mock("splat")
- a.should_not_receive(:to_ary)
- m(*a).should == [[a], 1]
- end
-
- evaluate <<-ruby do
- def m(*, **) end
- ruby
-
- m().should be_nil
- m(a: 1, b: 2).should be_nil
- m(1, 2, 3, a: 4, b: 5).should be_nil
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- suppress_keyword_warning do
- m(h).should be_nil
- end
-
- h = mock("keyword splat")
- error = RuntimeError.new("error while converting to a hash")
- h.should_receive(:to_hash).and_raise(error)
- -> { m(h) }.should raise_error(error)
- end
-
- evaluate <<-ruby do
- def m(*a, **) a end
- ruby
-
- m().should == []
- m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3]
- m("a" => 1, a: 1).should == [{"a" => 1}]
- m(1, **{a: 2}).should == [1]
-
- h = mock("keyword splat")
- h.should_receive(:to_hash)
- -> { m(**h) }.should raise_error(TypeError)
- end
-
- evaluate <<-ruby do
- def m(*, **k) k end
- ruby
-
- m().should == {}
- m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- m("a" => 1, a: 1).should == {a: 1}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- m(h).should == {a: 1}
- end
-
- evaluate <<-ruby do
- def m(a = nil, **k) [a, k] end
- ruby
-
- m().should == [nil, {}]
- m("a" => 1).should == [{"a" => 1}, {}]
- m(a: 1).should == [nil, {a: 1}]
- m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}]
- m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}]
- m({a: 1}, {}).should == [{a: 1}, {}]
-
- h = {"a" => 1, b: 2}
- m(h).should == [{"a" => 1}, {b: 2}]
- h.should == {"a" => 1, b: 2}
-
- h = {"a" => 1}
- m(h).first.should == h
-
- h = {}
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- hh = {}
- h = mock("keyword splat empty hash")
- h.should_receive(:to_hash).and_return(hh)
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({"a" => 1, a: 2})
- m(h).should == [{"a" => 1}, {a: 2}]
- end
-
- evaluate <<-ruby do
- def m(*a, **k) [a, k] end
- ruby
-
- m().should == [[], {}]
- m(1).should == [[1], {}]
- m(a: 1, b: 2).should == [[], {a: 1, b: 2}]
- m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}]
-
- m("a" => 1).should == [[{"a" => 1}], {}]
- m(a: 1).should == [[], {a: 1}]
- m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({a: 1}, {}).should == [[{a: 1}], {}]
- m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}]
-
- bo = BasicObject.new
- def bo.to_a; [1, 2, 3]; end
- def bo.to_hash; {:b => 2, :c => 3}; end
-
- m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}]
- end
- end
-
- ruby_version_is "2.7"...'3.0' do
+ ruby_version_is ""...'3.0' do
evaluate <<-ruby do
def m(*, a:) a end
ruby
@@ -1503,44 +1331,22 @@ describe "A method" do
end
end
- ruby_version_is ''...'2.7' do
- evaluate <<-ruby do
- def m(a:, **) a end
- ruby
-
- m(a: 1).should == 1
- m(a: 1, b: 2).should == 1
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
-
- evaluate <<-ruby do
- def m(a:, **k) [a, k] end
- ruby
+ evaluate <<-ruby do
+ def m(a:, **) a end
+ ruby
- m(a: 1).should == [1, {}]
- m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
- -> { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
- end
+ m(a: 1).should == 1
+ m(a: 1, b: 2).should == 1
+ m("a" => 1, a: 1, b: 2).should == 1
end
- ruby_version_is '2.7' do
- evaluate <<-ruby do
- def m(a:, **) a end
- ruby
-
- m(a: 1).should == 1
- m(a: 1, b: 2).should == 1
- m("a" => 1, a: 1, b: 2).should == 1
- end
-
- evaluate <<-ruby do
- def m(a:, **k) [a, k] end
- ruby
+ evaluate <<-ruby do
+ def m(a:, **k) [a, k] end
+ ruby
- m(a: 1).should == [1, {}]
- m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
- m("a" => 1, a: 1, b: 2).should == [1, {"a" => 1, b: 2}]
- end
+ m(a: 1).should == [1, {}]
+ m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
+ m("a" => 1, a: 1, b: 2).should == [1, {"a" => 1, b: 2}]
end
evaluate <<-ruby do
@@ -1637,18 +1443,16 @@ describe "A method" do
result.should == [1, 1, [], 2, 3, 2, 4, { h: 5, i: 6 }, l]
end
- ruby_version_is "2.7" do
- evaluate <<-ruby do
- def m(a, **nil); a end;
- ruby
+ evaluate <<-ruby do
+ def m(a, **nil); a end;
+ ruby
- m({a: 1}).should == {a: 1}
- m({"a" => 1}).should == {"a" => 1}
+ m({a: 1}).should == {a: 1}
+ m({"a" => 1}).should == {"a" => 1}
- -> { m(a: 1) }.should raise_error(ArgumentError)
- -> { m(**{a: 1}) }.should raise_error(ArgumentError)
- -> { m("a" => 1) }.should raise_error(ArgumentError)
- end
+ -> { m(a: 1) }.should raise_error(ArgumentError)
+ -> { m(**{a: 1}) }.should raise_error(ArgumentError)
+ -> { m("a" => 1) }.should raise_error(ArgumentError)
end
ruby_version_is ''...'3.0' do
@@ -1690,19 +1494,17 @@ describe "A method" do
end
end
- ruby_version_is '2.7' do
- context 'when passing an empty keyword splat to a method that does not accept keywords' do
- evaluate <<-ruby do
- def m(*a); a; end
- ruby
+ context 'when passing an empty keyword splat to a method that does not accept keywords' do
+ evaluate <<-ruby do
+ def m(*a); a; end
+ ruby
- h = {}
- m(**h).should == []
- end
+ h = {}
+ m(**h).should == []
end
end
- ruby_version_is '2.7'...'3.0' do
+ ruby_version_is ''...'3.0' do
context 'when passing an empty keyword splat to a method that does not accept keywords' do
evaluate <<-ruby do
def m(a); a; end
diff --git a/spec/ruby/language/numbered_parameters_spec.rb b/spec/ruby/language/numbered_parameters_spec.rb
index 838822b2d6..424d7a06e3 100644
--- a/spec/ruby/language/numbered_parameters_spec.rb
+++ b/spec/ruby/language/numbered_parameters_spec.rb
@@ -1,120 +1,118 @@
require_relative '../spec_helper'
-ruby_version_is "2.7" do
- describe "Numbered parameters" do
- it "provides default parameters _1, _2, ... in a block" do
- -> { _1 }.call("a").should == "a"
- proc { _1 }.call("a").should == "a"
- lambda { _1 }.call("a").should == "a"
- ["a"].map { _1 }.should == ["a"]
- end
+describe "Numbered parameters" do
+ it "provides default parameters _1, _2, ... in a block" do
+ -> { _1 }.call("a").should == "a"
+ proc { _1 }.call("a").should == "a"
+ lambda { _1 }.call("a").should == "a"
+ ["a"].map { _1 }.should == ["a"]
+ end
- it "assigns nil to not passed parameters" do
- proc { [_1, _2] }.call("a").should == ["a", nil]
- proc { [_1, _2] }.call("a", "b").should == ["a", "b"]
- end
+ it "assigns nil to not passed parameters" do
+ proc { [_1, _2] }.call("a").should == ["a", nil]
+ proc { [_1, _2] }.call("a", "b").should == ["a", "b"]
+ end
- it "supports variables _1-_9 only for the first 9 passed parameters" do
- block = proc { [_1, _2, _3, _4, _5, _6, _7, _8, _9] }
- result = block.call(1, 2, 3, 4, 5, 6, 7, 8, 9)
- result.should == [1, 2, 3, 4, 5, 6, 7, 8, 9]
- end
+ it "supports variables _1-_9 only for the first 9 passed parameters" do
+ block = proc { [_1, _2, _3, _4, _5, _6, _7, _8, _9] }
+ result = block.call(1, 2, 3, 4, 5, 6, 7, 8, 9)
+ result.should == [1, 2, 3, 4, 5, 6, 7, 8, 9]
+ end
- it "does not support more than 9 parameters" do
- -> {
- proc { [_10] }.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
- }.should raise_error(NameError, /undefined local variable or method `_10'/)
- end
+ it "does not support more than 9 parameters" do
+ -> {
+ proc { [_10] }.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ }.should raise_error(NameError, /undefined local variable or method `_10'/)
+ end
- it "can not be used in both outer and nested blocks at the same time" do
- -> {
- eval("-> { _1; -> { _2 } }")
- }.should raise_error(SyntaxError, /numbered parameter is already used in/m)
- end
+ it "can not be used in both outer and nested blocks at the same time" do
+ -> {
+ eval("-> { _1; -> { _2 } }")
+ }.should raise_error(SyntaxError, /numbered parameter is already used in/m)
+ end
- ruby_version_is '2.7'...'3.0' do
- it "can be overwritten with local variable" do
- suppress_warning do
- eval <<~CODE
- _1 = 0
- proc { _1 }.call("a").should == 0
- CODE
- end
+ ruby_version_is ''...'3.0' do
+ it "can be overwritten with local variable" do
+ suppress_warning do
+ eval <<~CODE
+ _1 = 0
+ proc { _1 }.call("a").should == 0
+ CODE
end
+ end
- it "warns when numbered parameter is overwritten with local variable" do
- -> {
- eval("_1 = 0")
- }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/)
- end
+ it "warns when numbered parameter is overwritten with local variable" do
+ -> {
+ eval("_1 = 0")
+ }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/)
end
+ end
- ruby_version_is '3.0' do
- it "cannot be overwritten with local variable" do
- -> {
- eval <<~CODE
- _1 = 0
- proc { _1 }.call("a").should == 0
- CODE
- }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
- end
+ ruby_version_is '3.0' do
+ it "cannot be overwritten with local variable" do
+ -> {
+ eval <<~CODE
+ _1 = 0
+ proc { _1 }.call("a").should == 0
+ CODE
+ }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
+ end
- it "errors when numbered parameter is overwritten with local variable" do
- -> {
- eval("_1 = 0")
- }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
- end
+ it "errors when numbered parameter is overwritten with local variable" do
+ -> {
+ eval("_1 = 0")
+ }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
end
+ end
- it "raises SyntaxError when block parameters are specified explicitly" do
- -> { eval("-> () { _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("-> (x) { _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ it "raises SyntaxError when block parameters are specified explicitly" do
+ -> { eval("-> () { _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("-> (x) { _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("proc { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("proc { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("proc { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("proc { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("lambda { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("lambda { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("lambda { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("lambda { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("['a'].map { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- -> { eval("['a'].map { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
- end
+ -> { eval("['a'].map { || _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("['a'].map { |x| _1 }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ end
- describe "assigning to a numbered parameter" do
- ruby_version_is '2.7'...'3.0' do
- it "warns" do
- -> { eval("proc { _1 = 0 }") }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/)
- end
+ describe "assigning to a numbered parameter" do
+ ruby_version_is ''...'3.0' do
+ it "warns" do
+ -> { eval("proc { _1 = 0 }") }.should complain(/warning: `_1' is reserved for numbered parameter; consider another name/)
end
+ end
- ruby_version_is '3.0' do
- it "raises SyntaxError" do
- -> { eval("proc { _1 = 0 }") }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
- end
+ ruby_version_is '3.0' do
+ it "raises SyntaxError" do
+ -> { eval("proc { _1 = 0 }") }.should raise_error(SyntaxError, /_1 is reserved for numbered parameter/)
end
end
+ end
- it "affects block arity" do
- -> { _1 }.arity.should == 1
- -> { _2 }.arity.should == 2
- -> { _3 }.arity.should == 3
- -> { _4 }.arity.should == 4
- -> { _5 }.arity.should == 5
- -> { _6 }.arity.should == 6
- -> { _7 }.arity.should == 7
- -> { _8 }.arity.should == 8
- -> { _9 }.arity.should == 9
-
- -> { _9 }.arity.should == 9
- proc { _9 }.arity.should == 9
- lambda { _9 }.arity.should == 9
- end
+ it "affects block arity" do
+ -> { _1 }.arity.should == 1
+ -> { _2 }.arity.should == 2
+ -> { _3 }.arity.should == 3
+ -> { _4 }.arity.should == 4
+ -> { _5 }.arity.should == 5
+ -> { _6 }.arity.should == 6
+ -> { _7 }.arity.should == 7
+ -> { _8 }.arity.should == 8
+ -> { _9 }.arity.should == 9
+
+ -> { _9 }.arity.should == 9
+ proc { _9 }.arity.should == 9
+ lambda { _9 }.arity.should == 9
+ end
- it "does not work in methods" do
- obj = Object.new
- def obj.foo; _1 end
+ it "does not work in methods" do
+ obj = Object.new
+ def obj.foo; _1 end
- -> { obj.foo("a") }.should raise_error(ArgumentError, /wrong number of arguments/)
- end
+ -> { obj.foo("a") }.should raise_error(ArgumentError, /wrong number of arguments/)
end
end
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb
index c68b6caa34..f3cc86fa0b 100644
--- a/spec/ruby/language/pattern_matching_spec.rb
+++ b/spec/ruby/language/pattern_matching_spec.rb
@@ -1,240 +1,356 @@
require_relative '../spec_helper'
-ruby_version_is "2.7" do
- describe "Pattern matching" do
- # TODO: Remove excessive eval calls when support of previous version
- # Ruby 2.6 will be dropped
+describe "Pattern matching" do
+ # TODO: Remove excessive eval calls when Ruby 3 is the minimum version.
+ # It is best to keep the eval's longer if other Ruby impls cannot parse pattern matching yet.
- before :each do
- ScratchPad.record []
+ before :each do
+ ScratchPad.record []
+ end
+
+ ruby_version_is "3.0" do
+ it "can be standalone assoc operator that deconstructs value" do
+ suppress_warning do
+ eval(<<-RUBY).should == [0, 1]
+ [0, 1] => [a, b]
+ [a, b]
+ RUBY
+ end
end
- ruby_version_is "3.0" do
- it "can be standalone assoc operator that deconstructs value" do
- suppress_warning do
- eval(<<-RUBY).should == [0, 1]
- [0, 1] => [a, b]
- [a, b]
- RUBY
- end
+ describe "find pattern" do
+ it "captures preceding elements to the pattern" do
+ eval(<<~RUBY).should == [0, 1]
+ case [0, 1, 2, 3]
+ in [*pre, 2, 3]
+ pre
+ else
+ false
+ end
+ RUBY
end
- describe "find pattern" do
- it "captures preceding elements to the pattern" do
- eval(<<~RUBY).should == [0, 1]
- case [0, 1, 2, 3]
- in [*pre, 2, 3]
- pre
- else
- false
- end
- RUBY
- end
-
- it "captures following elements to the pattern" do
- eval(<<~RUBY).should == [2, 3]
- case [0, 1, 2, 3]
- in [0, 1, *post]
- post
- else
- false
- end
- RUBY
- end
-
- it "captures both preceding and following elements to the pattern" do
- eval(<<~RUBY).should == [[0, 1], [3, 4]]
- case [0, 1, 2, 3, 4]
- in [*pre, 2, *post]
- [pre, post]
- else
- false
- end
- RUBY
- end
-
- it "can capture the entirety of the pattern" do
- eval(<<~RUBY).should == [0, 1, 2, 3, 4]
- case [0, 1, 2, 3, 4]
- in [*everything]
- everything
- else
- false
- end
- RUBY
- end
-
- it "will match an empty Array-like structure" do
- eval(<<~RUBY).should == []
- case []
- in [*everything]
- everything
- else
- false
- end
- RUBY
- end
-
- it "can be nested" do
- eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27]
- case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
- in [*pre, [*, 9, a], *post]
- [pre, post, a]
- else
- false
- end
- RUBY
- end
-
- it "can be nested with an array pattern" do
- eval(<<~RUBY).should == [[4, 16, 64]]
- case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
- in [_, _, [*, 9, *], *post]
- post
- else
- false
- end
- RUBY
- end
-
- it "can be nested within a hash pattern" do
- eval(<<~RUBY).should == [27]
- case {a: [3, 9, 27]}
- in {a: [*, 9, *post]}
- post
- else
- false
- end
- RUBY
- end
-
- it "can nest hash and array patterns" do
- eval(<<~RUBY).should == [42, 2]
- case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}]
- in [*, {a:, b: [1, c]}, *]
- [a, c]
- else
- false
- end
- RUBY
- end
+ it "captures following elements to the pattern" do
+ eval(<<~RUBY).should == [2, 3]
+ case [0, 1, 2, 3]
+ in [0, 1, *post]
+ post
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "captures both preceding and following elements to the pattern" do
+ eval(<<~RUBY).should == [[0, 1], [3, 4]]
+ case [0, 1, 2, 3, 4]
+ in [*pre, 2, *post]
+ [pre, post]
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can capture the entirety of the pattern" do
+ eval(<<~RUBY).should == [0, 1, 2, 3, 4]
+ case [0, 1, 2, 3, 4]
+ in [*everything]
+ everything
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "will match an empty Array-like structure" do
+ eval(<<~RUBY).should == []
+ case []
+ in [*everything]
+ everything
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can be nested" do
+ eval(<<~RUBY).should == [[0, [2, 4, 6]], [[4, 16, 64]], 27]
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [*pre, [*, 9, a], *post]
+ [pre, post, a]
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can be nested with an array pattern" do
+ eval(<<~RUBY).should == [[4, 16, 64]]
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [_, _, [*, 9, *], *post]
+ post
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can be nested within a hash pattern" do
+ eval(<<~RUBY).should == [27]
+ case {a: [3, 9, 27]}
+ in {a: [*, 9, *post]}
+ post
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "can nest hash and array patterns" do
+ eval(<<~RUBY).should == [42, 2]
+ case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}]
+ in [*, {a:, b: [1, c]}, *]
+ [a, c]
+ else
+ false
+ end
+ RUBY
end
end
+ end
- it "extends case expression with case/in construction" do
- eval(<<~RUBY).should == :bar
- case [0, 1]
- in [0]
- :foo
- in [0, 1]
- :bar
- end
- RUBY
+ it "extends case expression with case/in construction" do
+ eval(<<~RUBY).should == :bar
+ case [0, 1]
+ in [0]
+ :foo
+ in [0, 1]
+ :bar
+ end
+ RUBY
+ end
+
+ it "allows using then operator" do
+ eval(<<~RUBY).should == :bar
+ case [0, 1]
+ in [0] then :foo
+ in [0, 1] then :bar
+ end
+ RUBY
+ end
+
+ describe "warning" do
+ before :each do
+ @experimental, Warning[:experimental] = Warning[:experimental], true
end
- it "allows using then operator" do
- eval(<<~RUBY).should == :bar
- case [0, 1]
- in [0] then :foo
- in [0, 1] then :bar
- end
- RUBY
+ after :each do
+ Warning[:experimental] = @experimental
end
- describe "warning" do
+ context 'when regular form' do
before :each do
- @experimental, Warning[:experimental] = Warning[:experimental], true
+ @src = 'case [0, 1]; in [a, b]; end'
+ end
+
+ ruby_version_is ""..."3.0" do
+ it "warns about pattern matching is experimental feature" do
+ -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i)
+ end
end
- after :each do
- Warning[:experimental] = @experimental
+ ruby_version_is "3.0" do
+ it "does not warn about pattern matching is experimental feature" do
+ -> { eval @src }.should_not complain
+ end
end
+ end
- context 'when regular form' do
+ context 'when one-line form' do
+ ruby_version_is '3.0' do
before :each do
- @src = 'case [0, 1]; in [a, b]; end'
+ @src = '[0, 1] => [a, b]'
end
- ruby_version_is ""..."3.0" do
+ ruby_version_is ""..."3.1" do
it "warns about pattern matching is experimental feature" do
-> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i)
end
end
- ruby_version_is "3.0" do
+ ruby_version_is "3.1" do
it "does not warn about pattern matching is experimental feature" do
-> { eval @src }.should_not complain
end
end
end
+ end
+ end
- context 'when one-line form' do
- ruby_version_is '3.0' do
- before :each do
- @src = '[0, 1] => [a, b]'
- end
+ it "binds variables" do
+ eval(<<~RUBY).should == 1
+ case [0, 1]
+ in [0, a]
+ a
+ end
+ RUBY
+ end
- ruby_version_is ""..."3.1" do
- it "warns about pattern matching is experimental feature" do
- -> { eval @src }.should complain(/pattern matching is experimental, and the behavior may change in future versions of Ruby!/i)
- end
- end
+ it "cannot mix in and when operators" do
+ -> {
+ eval <<~RUBY
+ case []
+ when 1 == 1
+ in []
+ end
+ RUBY
+ }.should raise_error(SyntaxError, /syntax error, unexpected `in'/)
- ruby_version_is "3.1" do
- it "does not warn about pattern matching is experimental feature" do
- -> { eval @src }.should_not complain
- end
- end
+ -> {
+ eval <<~RUBY
+ case []
+ in []
+ when 1 == 1
end
+ RUBY
+ }.should raise_error(SyntaxError, /syntax error, unexpected `when'/)
+ end
+
+ it "checks patterns until the first matching" do
+ eval(<<~RUBY).should == :bar
+ case [0, 1]
+ in [0]
+ :foo
+ in [0, 1]
+ :bar
+ in [0, 1]
+ :baz
+ end
+ RUBY
+ end
+
+ it "executes else clause if no pattern matches" do
+ eval(<<~RUBY).should == false
+ case [0, 1]
+ in [0]
+ true
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "raises NoMatchingPatternError if no pattern matches and no else clause" do
+ -> {
+ eval <<~RUBY
+ case [0, 1]
+ in [0]
+ end
+ RUBY
+ }.should raise_error(NoMatchingPatternError, /\[0, 1\]/)
+ end
+
+ it "does not allow calculation or method calls in a pattern" do
+ -> {
+ eval <<~RUBY
+ case 0
+ in 1 + 1
+ true
+ end
+ RUBY
+ }.should raise_error(SyntaxError, /unexpected/)
+ end
+
+ it "evaluates the case expression once for multiple patterns, caching the result" do
+ eval(<<~RUBY).should == true
+ case (ScratchPad << :foo; 1)
+ in 0
+ false
+ in 1
+ true
end
+ RUBY
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ describe "guards" do
+ it "supports if guard" do
+ eval(<<~RUBY).should == false
+ case 0
+ in 0 if false
+ true
+ else
+ false
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case 0
+ in 0 if true
+ true
+ else
+ false
+ end
+ RUBY
end
- it "binds variables" do
- eval(<<~RUBY).should == 1
+ it "supports unless guard" do
+ eval(<<~RUBY).should == false
+ case 0
+ in 0 unless true
+ true
+ else
+ false
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case 0
+ in 0 unless false
+ true
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "makes bound variables visible in guard" do
+ eval(<<~RUBY).should == true
case [0, 1]
- in [0, a]
- a
+ in [a, 1] if a >= 0
+ true
end
RUBY
end
- it "cannot mix in and when operators" do
- -> {
- eval <<~RUBY
- case []
- when 1 == 1
- in []
- end
- RUBY
- }.should raise_error(SyntaxError, /syntax error, unexpected `in'/)
+ it "does not evaluate guard if pattern does not match" do
+ eval <<~RUBY
+ case 0
+ in 1 if (ScratchPad << :foo) || true
+ else
+ end
+ RUBY
- -> {
- eval <<~RUBY
- case []
- in []
- when 1 == 1
- end
- RUBY
- }.should raise_error(SyntaxError, /syntax error, unexpected `when'/)
+ ScratchPad.recorded.should == []
end
- it "checks patterns until the first matching" do
+ it "takes guards into account when there are several matching patterns" do
eval(<<~RUBY).should == :bar
- case [0, 1]
- in [0]
+ case 0
+ in 0 if false
:foo
- in [0, 1]
+ in 0 if true
:bar
- in [0, 1]
- :baz
end
RUBY
end
- it "executes else clause if no pattern matches" do
+ it "executes else clause if no guarded pattern matches" do
eval(<<~RUBY).should == false
- case [0, 1]
- in [0]
+ case 0
+ in 0 if false
true
else
false
@@ -242,1164 +358,1046 @@ ruby_version_is "2.7" do
RUBY
end
- it "raises NoMatchingPatternError if no pattern matches and no else clause" do
+ it "raises NoMatchingPatternError if no guarded pattern matches and no else clause" do
-> {
eval <<~RUBY
case [0, 1]
- in [0]
+ in [0, 1] if false
end
RUBY
}.should raise_error(NoMatchingPatternError, /\[0, 1\]/)
end
+ end
- it "does not allow calculation or method calls in a pattern" do
- -> {
- eval <<~RUBY
- case 0
- in 1 + 1
- true
- end
- RUBY
- }.should raise_error(SyntaxError, /unexpected/)
- end
-
- it "evaluates the case expression once for multiple patterns, caching the result" do
+ describe "value pattern" do
+ it "matches an object such that pattern === object" do
eval(<<~RUBY).should == true
- case (ScratchPad << :foo; 1)
+ case 0
in 0
- false
- in 1
true
end
RUBY
- ScratchPad.recorded.should == [:foo]
- end
-
- describe "guards" do
- it "supports if guard" do
- eval(<<~RUBY).should == false
- case 0
- in 0 if false
- true
- else
- false
- end
- RUBY
-
- eval(<<~RUBY).should == true
- case 0
- in 0 if true
- true
- else
- false
- end
- RUBY
- end
-
- it "supports unless guard" do
- eval(<<~RUBY).should == false
- case 0
- in 0 unless true
- true
- else
- false
- end
- RUBY
-
- eval(<<~RUBY).should == true
- case 0
- in 0 unless false
- true
- else
- false
- end
- RUBY
- end
-
- it "makes bound variables visible in guard" do
- eval(<<~RUBY).should == true
- case [0, 1]
- in [a, 1] if a >= 0
- true
- end
- RUBY
- end
-
- it "does not evaluate guard if pattern does not match" do
- eval <<~RUBY
- case 0
- in 1 if (ScratchPad << :foo) || true
- else
- end
- RUBY
-
- ScratchPad.recorded.should == []
- end
+ eval(<<~RUBY).should == true
+ case 0
+ in (-1..1)
+ true
+ end
+ RUBY
- it "takes guards into account when there are several matching patterns" do
- eval(<<~RUBY).should == :bar
- case 0
- in 0 if false
- :foo
- in 0 if true
- :bar
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case 0
+ in Integer
+ true
+ end
+ RUBY
- it "executes else clause if no guarded pattern matches" do
- eval(<<~RUBY).should == false
- case 0
- in 0 if false
- true
- else
- false
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case "0"
+ in /0/
+ true
+ end
+ RUBY
- it "raises NoMatchingPatternError if no guarded pattern matches and no else clause" do
- -> {
- eval <<~RUBY
- case [0, 1]
- in [0, 1] if false
- end
- RUBY
- }.should raise_error(NoMatchingPatternError, /\[0, 1\]/)
- end
+ eval(<<~RUBY).should == true
+ case "0"
+ in ->(s) { s == "0" }
+ true
+ end
+ RUBY
end
- describe "value pattern" do
- it "matches an object such that pattern === object" do
- eval(<<~RUBY).should == true
- case 0
- in 0
- true
- end
- RUBY
+ it "allows string literal with interpolation" do
+ x = "x"
- eval(<<~RUBY).should == true
- case 0
- in (-1..1)
- true
- end
- RUBY
-
- eval(<<~RUBY).should == true
- case 0
- in Integer
- true
- end
- RUBY
-
- eval(<<~RUBY).should == true
- case "0"
- in /0/
- true
- end
- RUBY
+ eval(<<~RUBY).should == true
+ case "x"
+ in "#{x + ""}"
+ true
+ end
+ RUBY
+ end
+ end
- eval(<<~RUBY).should == true
- case "0"
- in ->(s) { s == "0" }
- true
- end
- RUBY
- end
+ describe "variable pattern" do
+ it "matches a value and binds variable name to this value" do
+ eval(<<~RUBY).should == 0
+ case 0
+ in a
+ a
+ end
+ RUBY
+ end
- it "allows string literal with interpolation" do
- x = "x"
+ it "makes bounded variable visible outside a case statement scope" do
+ eval(<<~RUBY).should == 0
+ case 0
+ in a
+ end
- eval(<<~RUBY).should == true
- case "x"
- in "#{x + ""}"
- true
- end
- RUBY
- end
+ a
+ RUBY
end
- describe "variable pattern" do
- it "matches a value and binds variable name to this value" do
- eval(<<~RUBY).should == 0
- case 0
- in a
- a
- end
- RUBY
- end
+ it "create local variables even if a pattern doesn't match" do
+ eval(<<~RUBY).should == [0, nil, nil]
+ case 0
+ in a
+ in b
+ in c
+ end
- it "makes bounded variable visible outside a case statement scope" do
- eval(<<~RUBY).should == 0
- case 0
- in a
- end
+ [a, b, c]
+ RUBY
+ end
+ it "allow using _ name to drop values" do
+ eval(<<~RUBY).should == 0
+ case [0, 1]
+ in [a, _]
a
- RUBY
- end
-
- it "create local variables even if a pattern doesn't match" do
- eval(<<~RUBY).should == [0, nil, nil]
- case 0
- in a
- in b
- in c
- end
-
- [a, b, c]
- RUBY
- end
+ end
+ RUBY
+ end
- it "allow using _ name to drop values" do
- eval(<<~RUBY).should == 0
- case [0, 1]
- in [a, _]
- a
- end
- RUBY
- end
+ it "supports using _ in a pattern several times" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in [0, _, _]
+ true
+ end
+ RUBY
+ end
- it "supports using _ in a pattern several times" do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in [0, _, _]
- true
- end
- RUBY
- end
+ it "supports using any name with _ at the beginning in a pattern several times" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in [0, _x, _x]
+ true
+ end
+ RUBY
- it "supports using any name with _ at the beginning in a pattern several times" do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in [0, _x, _x]
- true
- end
- RUBY
+ eval(<<~RUBY).should == true
+ case {a: 0, b: 1, c: 2}
+ in {a: 0, b: _x, c: _x}
+ true
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case {a: 0, b: 1, c: 2}
- in {a: 0, b: _x, c: _x}
- true
+ it "does not support using variable name (except _) several times" do
+ -> {
+ eval <<~RUBY
+ case [0]
+ in [a, a]
end
RUBY
- end
+ }.should raise_error(SyntaxError, /duplicated variable name/)
+ end
- it "does not support using variable name (except _) several times" do
- -> {
- eval <<~RUBY
- case [0]
- in [a, a]
- end
- RUBY
- }.should raise_error(SyntaxError, /duplicated variable name/)
- end
+ it "supports existing variables in a pattern specified with ^ operator" do
+ a = 0
- it "supports existing variables in a pattern specified with ^ operator" do
- a = 0
+ eval(<<~RUBY).should == true
+ case 0
+ in ^a
+ true
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case 0
- in ^a
- true
- end
- RUBY
- end
+ it "allows applying ^ operator to bound variables" do
+ eval(<<~RUBY).should == 1
+ case [1, 1]
+ in [n, ^n]
+ n
+ end
+ RUBY
- it "allows applying ^ operator to bound variables" do
- eval(<<~RUBY).should == 1
- case [1, 1]
- in [n, ^n]
- n
- end
- RUBY
+ eval(<<~RUBY).should == false
+ case [1, 2]
+ in [n, ^n]
+ true
+ else
+ false
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == false
+ it "requires bound variable to be specified in a pattern before ^ operator when it relies on a bound variable" do
+ -> {
+ eval <<~RUBY
case [1, 2]
- in [n, ^n]
+ in [^n, n]
true
else
false
end
RUBY
- end
-
- it "requires bound variable to be specified in a pattern before ^ operator when it relies on a bound variable" do
- -> {
- eval <<~RUBY
- case [1, 2]
- in [^n, n]
- true
- else
- false
- end
- RUBY
- }.should raise_error(SyntaxError, /n: no such local variable/)
- end
+ }.should raise_error(SyntaxError, /n: no such local variable/)
end
+ end
- describe "alternative pattern" do
- it "matches if any of patterns matches" do
- eval(<<~RUBY).should == true
- case 0
- in 0 | 1 | 2
- true
- end
- RUBY
- end
-
- it "does not support variable binding" do
- -> {
- eval <<~RUBY
- case [0, 1]
- in [0, 0] | [0, a]
- end
- RUBY
- }.should raise_error(SyntaxError, /illegal variable in alternative pattern/)
- end
+ describe "alternative pattern" do
+ it "matches if any of patterns matches" do
+ eval(<<~RUBY).should == true
+ case 0
+ in 0 | 1 | 2
+ true
+ end
+ RUBY
+ end
- it "support underscore prefixed variables in alternation" do
- eval(<<~RUBY).should == true
+ it "does not support variable binding" do
+ -> {
+ eval <<~RUBY
case [0, 1]
- in [1, _]
- false
- in [0, 0] | [0, _a]
- true
+ in [0, 0] | [0, a]
end
RUBY
- end
-
- it "can be used as a nested pattern" do
- eval(<<~RUBY).should == true
- case [[1], ["2"]]
- in [[0] | nil, _]
- false
- in [[1], [1]]
- false
- in [[1], [2 | "2"]]
- true
- end
- RUBY
-
- eval(<<~RUBY).should == true
- case [1, 2]
- in [0, _] | {a: 0}
- false
- in {a: 1, b: 2} | [1, 2]
- true
- end
- RUBY
- end
+ }.should raise_error(SyntaxError, /illegal variable in alternative pattern/)
end
- describe "AS pattern" do
- it "binds a variable to a value if pattern matches" do
- eval(<<~RUBY).should == 0
- case 0
- in Integer => n
- n
- end
- RUBY
- end
-
- it "can be used as a nested pattern" do
- eval(<<~RUBY).should == [2, 3]
- case [1, [2, 3]]
- in [1, Array => ary]
- ary
- end
- RUBY
- end
+ it "support underscore prefixed variables in alternation" do
+ eval(<<~RUBY).should == true
+ case [0, 1]
+ in [1, _]
+ false
+ in [0, 0] | [0, _a]
+ true
+ end
+ RUBY
end
- describe "Array pattern" do
- it "supports form Constant(pat, pat, ...)" do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in Array(0, 1, 2)
+ it "can be used as a nested pattern" do
+ eval(<<~RUBY).should == true
+ case [[1], ["2"]]
+ in [[0] | nil, _]
+ false
+ in [[1], [1]]
+ false
+ in [[1], [2 | "2"]]
true
- end
- RUBY
- end
+ end
+ RUBY
- it "supports form Constant[pat, pat, ...]" do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in Array[0, 1, 2]
+ eval(<<~RUBY).should == true
+ case [1, 2]
+ in [0, _] | {a: 0}
+ false
+ in {a: 1, b: 2} | [1, 2]
true
- end
- RUBY
- end
+ end
+ RUBY
+ end
+ end
- it "supports form [pat, pat, ...]" do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in [0, 1, 2]
- true
- end
- RUBY
- end
+ describe "AS pattern" do
+ it "binds a variable to a value if pattern matches" do
+ eval(<<~RUBY).should == 0
+ case 0
+ in Integer => n
+ n
+ end
+ RUBY
+ end
- it "supports form pat, pat, ..." do
- eval(<<~RUBY).should == true
- case [0, 1, 2]
- in 0, 1, 2
- true
- end
- RUBY
+ it "can be used as a nested pattern" do
+ eval(<<~RUBY).should == [2, 3]
+ case [1, [2, 3]]
+ in [1, Array => ary]
+ ary
+ end
+ RUBY
+ end
+ end
- eval(<<~RUBY).should == 1
- case [0, 1, 2]
- in 0, a, 2
- a
- end
- RUBY
+ describe "Array pattern" do
+ it "supports form Constant(pat, pat, ...)" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in Array(0, 1, 2)
+ true
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == [1, 2]
- case [0, 1, 2]
- in 0, *rest
- rest
- end
- RUBY
- end
+ it "supports form Constant[pat, pat, ...]" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in Array[0, 1, 2]
+ true
+ end
+ RUBY
+ end
- it "matches an object with #deconstruct method which returns an array and each element in array matches element in pattern" do
- obj = Object.new
- def obj.deconstruct; [0, 1] end
+ it "supports form [pat, pat, ...]" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in [0, 1, 2]
+ true
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case obj
- in [Integer, Integer]
- true
- end
- RUBY
- end
+ it "supports form pat, pat, ..." do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2]
+ in 0, 1, 2
+ true
+ end
+ RUBY
- ruby_version_is "3.0" do
- it "calls #deconstruct once for multiple patterns, caching the result" do
- obj = Object.new
+ eval(<<~RUBY).should == 1
+ case [0, 1, 2]
+ in 0, a, 2
+ a
+ end
+ RUBY
- def obj.deconstruct
- ScratchPad << :deconstruct
- [0, 1]
- end
+ eval(<<~RUBY).should == [1, 2]
+ case [0, 1, 2]
+ in 0, *rest
+ rest
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case obj
- in [1, 2]
- false
- in [0, 1]
- true
- end
- RUBY
+ it "matches an object with #deconstruct method which returns an array and each element in array matches element in pattern" do
+ obj = Object.new
+ def obj.deconstruct; [0, 1] end
- ScratchPad.recorded.should == [:deconstruct]
+ eval(<<~RUBY).should == true
+ case obj
+ in [Integer, Integer]
+ true
end
- end
+ RUBY
+ end
+
+ ruby_version_is "3.0" do
+ it "calls #deconstruct once for multiple patterns, caching the result" do
+ obj = Object.new
- it "calls #deconstruct even on objects that are already an array" do
- obj = [1, 2]
def obj.deconstruct
ScratchPad << :deconstruct
- [3, 4]
+ [0, 1]
end
eval(<<~RUBY).should == true
case obj
- in [3, 4]
- true
- else
+ in [1, 2]
false
+ in [0, 1]
+ true
end
RUBY
ScratchPad.recorded.should == [:deconstruct]
end
+ end
- it "does not match object if Constant === object returns false" do
- eval(<<~RUBY).should == false
- case [0, 1, 2]
- in String[0, 1, 2]
- true
- else
- false
- end
- RUBY
+ it "calls #deconstruct even on objects that are already an array" do
+ obj = [1, 2]
+ def obj.deconstruct
+ ScratchPad << :deconstruct
+ [3, 4]
end
- it "does not match object without #deconstruct method" do
- obj = Object.new
- obj.should_receive(:respond_to?).with(:deconstruct)
-
- eval(<<~RUBY).should == false
- case obj
- in Object[]
- true
- else
- false
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case obj
+ in [3, 4]
+ true
+ else
+ false
+ end
+ RUBY
- it "raises TypeError if #deconstruct method does not return array" do
- obj = Object.new
- def obj.deconstruct; "" end
-
- -> {
- eval <<~RUBY
- case obj
- in Object[]
- else
- end
- RUBY
- }.should raise_error(TypeError, /deconstruct must return Array/)
- end
+ ScratchPad.recorded.should == [:deconstruct]
+ end
- it "accepts a subclass of Array from #deconstruct" do
- obj = Object.new
- def obj.deconstruct
- subarray = Class.new(Array).new(2)
- def subarray.[](n)
- n
- end
- subarray
+ it "does not match object if Constant === object returns false" do
+ eval(<<~RUBY).should == false
+ case [0, 1, 2]
+ in String[0, 1, 2]
+ true
+ else
+ false
end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case obj
- in [1, 2]
- false
- in [0, 1]
- true
- end
- RUBY
- end
+ it "does not match object without #deconstruct method" do
+ obj = Object.new
+ obj.should_receive(:respond_to?).with(:deconstruct)
- it "does not match object if elements of array returned by #deconstruct method does not match elements in pattern" do
- obj = Object.new
- def obj.deconstruct; [1] end
+ eval(<<~RUBY).should == false
+ case obj
+ in Object[]
+ true
+ else
+ false
+ end
+ RUBY
+ end
+
+ it "raises TypeError if #deconstruct method does not return array" do
+ obj = Object.new
+ def obj.deconstruct; "" end
- eval(<<~RUBY).should == false
+ -> {
+ eval <<~RUBY
case obj
- in Object[0]
- true
+ in Object[]
else
- false
end
RUBY
- end
+ }.should raise_error(TypeError, /deconstruct must return Array/)
+ end
- it "binds variables" do
- eval(<<~RUBY).should == [0, 1, 2]
- case [0, 1, 2]
- in [a, b, c]
- [a, b, c]
- end
- RUBY
+ it "accepts a subclass of Array from #deconstruct" do
+ obj = Object.new
+ def obj.deconstruct
+ subarray = Class.new(Array).new(2)
+ def subarray.[](n)
+ n
+ end
+ subarray
end
- it "supports splat operator *rest" do
- eval(<<~RUBY).should == [1, 2]
- case [0, 1, 2]
- in [0, *rest]
- rest
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case obj
+ in [1, 2]
+ false
+ in [0, 1]
+ true
+ end
+ RUBY
+ end
- it "does not match partially by default" do
- eval(<<~RUBY).should == false
- case [0, 1, 2, 3]
- in [1, 2]
- true
- else
- false
- end
- RUBY
- end
+ it "does not match object if elements of array returned by #deconstruct method does not match elements in pattern" do
+ obj = Object.new
+ def obj.deconstruct; [1] end
- it "does match partially from the array beginning if list + , syntax used" do
- eval(<<~RUBY).should == true
- case [0, 1, 2, 3]
- in [0, 1,]
- true
- end
- RUBY
+ eval(<<~RUBY).should == false
+ case obj
+ in Object[0]
+ true
+ else
+ false
+ end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case [0, 1, 2, 3]
- in 0, 1,;
- true
- end
- RUBY
- end
+ it "binds variables" do
+ eval(<<~RUBY).should == [0, 1, 2]
+ case [0, 1, 2]
+ in [a, b, c]
+ [a, b, c]
+ end
+ RUBY
+ end
- it "matches [] with []" do
- eval(<<~RUBY).should == true
- case []
- in []
- true
- end
- RUBY
- end
+ it "supports splat operator *rest" do
+ eval(<<~RUBY).should == [1, 2]
+ case [0, 1, 2]
+ in [0, *rest]
+ rest
+ end
+ RUBY
+ end
- it "matches anything with *" do
- eval(<<~RUBY).should == true
- case [0, 1]
- in *;
- true
- end
- RUBY
- end
+ it "does not match partially by default" do
+ eval(<<~RUBY).should == false
+ case [0, 1, 2, 3]
+ in [1, 2]
+ true
+ else
+ false
+ end
+ RUBY
+ end
- it "can be used as a nested pattern" do
- eval(<<~RUBY).should == true
- case [[1], ["2"]]
- in [[0] | nil, _]
- false
- in [[1], [1]]
- false
- in [[1], [2 | "2"]]
- true
- end
- RUBY
+ it "does match partially from the array beginning if list + , syntax used" do
+ eval(<<~RUBY).should == true
+ case [0, 1, 2, 3]
+ in [0, 1,]
+ true
+ end
+ RUBY
- eval(<<~RUBY).should == true
- case [1, 2]
- in [0, _] | {a: 0}
- false
- in {a: 1, b: 2} | [1, 2]
- true
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case [0, 1, 2, 3]
+ in 0, 1,;
+ true
+ end
+ RUBY
end
- describe "Hash pattern" do
- it "supports form Constant(id: pat, id: pat, ...)" do
- eval(<<~RUBY).should == true
- case {a: 0, b: 1}
- in Hash(a: 0, b: 1)
- true
- end
- RUBY
- end
+ it "matches [] with []" do
+ eval(<<~RUBY).should == true
+ case []
+ in []
+ true
+ end
+ RUBY
+ end
- it "supports form Constant[id: pat, id: pat, ...]" do
- eval(<<~RUBY).should == true
- case {a: 0, b: 1}
- in Hash[a: 0, b: 1]
- true
- end
- RUBY
- end
+ it "matches anything with *" do
+ eval(<<~RUBY).should == true
+ case [0, 1]
+ in *;
+ true
+ end
+ RUBY
+ end
- it "supports form {id: pat, id: pat, ...}" do
- eval(<<~RUBY).should == true
- case {a: 0, b: 1}
- in {a: 0, b: 1}
+ it "can be used as a nested pattern" do
+ eval(<<~RUBY).should == true
+ case [[1], ["2"]]
+ in [[0] | nil, _]
+ false
+ in [[1], [1]]
+ false
+ in [[1], [2 | "2"]]
true
- end
- RUBY
- end
+ end
+ RUBY
- it "supports form id: pat, id: pat, ..." do
- eval(<<~RUBY).should == true
- case {a: 0, b: 1}
- in a: 0, b: 1
+ eval(<<~RUBY).should == true
+ case [1, 2]
+ in [0, _] | {a: 0}
+ false
+ in {a: 1, b: 2} | [1, 2]
true
- end
- RUBY
-
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in a: a, b: b
- [a, b]
- end
- RUBY
-
- eval(<<~RUBY).should == { b: 1, c: 2 }
- case {a: 0, b: 1, c: 2}
- in a: 0, **rest
- rest
- end
- RUBY
- end
-
- it "supports a: which means a: a" do
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in Hash(a:, b:)
- [a, b]
- end
- RUBY
-
- a = b = nil
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in Hash[a:, b:]
- [a, b]
- end
- RUBY
+ end
+ RUBY
+ end
+ end
- a = b = nil
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in {a:, b:}
- [a, b]
- end
- RUBY
+ describe "Hash pattern" do
+ it "supports form Constant(id: pat, id: pat, ...)" do
+ eval(<<~RUBY).should == true
+ case {a: 0, b: 1}
+ in Hash(a: 0, b: 1)
+ true
+ end
+ RUBY
+ end
- a = nil
- eval(<<~RUBY).should == [0, {b: 1, c: 2}]
- case {a: 0, b: 1, c: 2}
- in {a:, **rest}
- [a, rest]
- end
- RUBY
+ it "supports form Constant[id: pat, id: pat, ...]" do
+ eval(<<~RUBY).should == true
+ case {a: 0, b: 1}
+ in Hash[a: 0, b: 1]
+ true
+ end
+ RUBY
+ end
- a = b = nil
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in a:, b:
- [a, b]
- end
- RUBY
- end
+ it "supports form {id: pat, id: pat, ...}" do
+ eval(<<~RUBY).should == true
+ case {a: 0, b: 1}
+ in {a: 0, b: 1}
+ true
+ end
+ RUBY
+ end
- it "can mix key (a:) and key-value (a: b) declarations" do
- eval(<<~RUBY).should == [0, 1]
- case {a: 0, b: 1}
- in Hash(a:, b: x)
- [a, x]
- end
- RUBY
- end
+ it "supports form id: pat, id: pat, ..." do
+ eval(<<~RUBY).should == true
+ case {a: 0, b: 1}
+ in a: 0, b: 1
+ true
+ end
+ RUBY
- it "supports 'string': key literal" do
- eval(<<~RUBY).should == true
- case {a: 0}
- in {"a": 0}
- true
- end
- RUBY
- end
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in a: a, b: b
+ [a, b]
+ end
+ RUBY
- it "does not support non-symbol keys" do
- -> {
- eval <<~RUBY
- case {a: 1}
- in {"a" => 1}
- end
- RUBY
- }.should raise_error(SyntaxError, /unexpected/)
- end
+ eval(<<~RUBY).should == { b: 1, c: 2 }
+ case {a: 0, b: 1, c: 2}
+ in a: 0, **rest
+ rest
+ end
+ RUBY
+ end
- it "does not support string interpolation in keys" do
- x = "a"
+ it "supports a: which means a: a" do
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in Hash(a:, b:)
+ [a, b]
+ end
+ RUBY
- -> {
- eval <<~'RUBY'
- case {a: 1}
- in {"#{x}": 1}
- end
- RUBY
- }.should raise_error(SyntaxError, /symbol literal with interpolation is not allowed/)
- end
+ a = b = nil
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in Hash[a:, b:]
+ [a, b]
+ end
+ RUBY
- it "raise SyntaxError when keys duplicate in pattern" do
- -> {
- eval <<~RUBY
- case {a: 1}
- in {a: 1, b: 2, a: 3}
- end
- RUBY
- }.should raise_error(SyntaxError, /duplicated key name/)
- end
+ a = b = nil
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in {a:, b:}
+ [a, b]
+ end
+ RUBY
- it "matches an object with #deconstruct_keys method which returns a Hash with equal keys and each value in Hash matches value in pattern" do
- obj = Object.new
- def obj.deconstruct_keys(*); {a: 1} end
+ a = nil
+ eval(<<~RUBY).should == [0, {b: 1, c: 2}]
+ case {a: 0, b: 1, c: 2}
+ in {a:, **rest}
+ [a, rest]
+ end
+ RUBY
- eval(<<~RUBY).should == true
- case obj
- in {a: 1}
- true
- end
- RUBY
- end
+ a = b = nil
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in a:, b:
+ [a, b]
+ end
+ RUBY
+ end
- it "calls #deconstruct_keys per pattern" do
- obj = Object.new
+ it "can mix key (a:) and key-value (a: b) declarations" do
+ eval(<<~RUBY).should == [0, 1]
+ case {a: 0, b: 1}
+ in Hash(a:, b: x)
+ [a, x]
+ end
+ RUBY
+ end
- def obj.deconstruct_keys(*)
- ScratchPad << :deconstruct_keys
- {a: 1}
+ it "supports 'string': key literal" do
+ eval(<<~RUBY).should == true
+ case {a: 0}
+ in {"a": 0}
+ true
end
+ RUBY
+ end
- eval(<<~RUBY).should == true
- case obj
- in {b: 1}
- false
- in {a: 1}
- true
+ it "does not support non-symbol keys" do
+ -> {
+ eval <<~RUBY
+ case {a: 1}
+ in {"a" => 1}
end
RUBY
+ }.should raise_error(SyntaxError, /unexpected/)
+ end
- ScratchPad.recorded.should == [:deconstruct_keys, :deconstruct_keys]
- end
+ it "does not support string interpolation in keys" do
+ x = "a"
- it "does not match object if Constant === object returns false" do
- eval(<<~RUBY).should == false
+ -> {
+ eval <<~'RUBY'
case {a: 1}
- in String[a: 1]
- true
- else
- false
+ in {"#{x}": 1}
end
RUBY
- end
-
- it "does not match object without #deconstruct_keys method" do
- obj = Object.new
- obj.should_receive(:respond_to?).with(:deconstruct_keys)
+ }.should raise_error(SyntaxError, /symbol literal with interpolation is not allowed/)
+ end
- eval(<<~RUBY).should == false
- case obj
- in Object[a: 1]
- true
- else
- false
+ it "raise SyntaxError when keys duplicate in pattern" do
+ -> {
+ eval <<~RUBY
+ case {a: 1}
+ in {a: 1, b: 2, a: 3}
end
RUBY
- end
-
- it "does not match object if #deconstruct_keys method does not return Hash" do
- obj = Object.new
- def obj.deconstruct_keys(*); "" end
-
- -> {
- eval <<~RUBY
- case obj
- in Object[a: 1]
- end
- RUBY
- }.should raise_error(TypeError, /deconstruct_keys must return Hash/)
- end
+ }.should raise_error(SyntaxError, /duplicated key name/)
+ end
- it "does not match object if #deconstruct_keys method returns Hash with non-symbol keys" do
- obj = Object.new
- def obj.deconstruct_keys(*); {"a" => 1} end
+ it "matches an object with #deconstruct_keys method which returns a Hash with equal keys and each value in Hash matches value in pattern" do
+ obj = Object.new
+ def obj.deconstruct_keys(*); {a: 1} end
- eval(<<~RUBY).should == false
- case obj
- in Object[a: 1]
- true
- else
- false
- end
- RUBY
- end
+ eval(<<~RUBY).should == true
+ case obj
+ in {a: 1}
+ true
+ end
+ RUBY
+ end
- it "does not match object if elements of Hash returned by #deconstruct_keys method does not match values in pattern" do
- obj = Object.new
- def obj.deconstruct_keys(*); {a: 1} end
+ it "calls #deconstruct_keys per pattern" do
+ obj = Object.new
- eval(<<~RUBY).should == false
- case obj
- in Object[a: 2]
- true
- else
- false
- end
- RUBY
+ def obj.deconstruct_keys(*)
+ ScratchPad << :deconstruct_keys
+ {a: 1}
end
- it "passes keys specified in pattern as arguments to #deconstruct_keys method" do
- obj = Object.new
-
- def obj.deconstruct_keys(*args)
- ScratchPad << args
- {a: 1, b: 2, c: 3}
+ eval(<<~RUBY).should == true
+ case obj
+ in {b: 1}
+ false
+ in {a: 1}
+ true
end
+ RUBY
- eval <<~RUBY
- case obj
- in Object[a: 1, b: 2, c: 3]
- end
- RUBY
+ ScratchPad.recorded.should == [:deconstruct_keys, :deconstruct_keys]
+ end
- ScratchPad.recorded.sort.should == [[[:a, :b, :c]]]
- end
+ it "does not match object if Constant === object returns false" do
+ eval(<<~RUBY).should == false
+ case {a: 1}
+ in String[a: 1]
+ true
+ else
+ false
+ end
+ RUBY
+ end
- it "passes keys specified in pattern to #deconstruct_keys method if pattern contains double splat operator **" do
- obj = Object.new
+ it "does not match object without #deconstruct_keys method" do
+ obj = Object.new
+ obj.should_receive(:respond_to?).with(:deconstruct_keys)
- def obj.deconstruct_keys(*args)
- ScratchPad << args
- {a: 1, b: 2, c: 3}
+ eval(<<~RUBY).should == false
+ case obj
+ in Object[a: 1]
+ true
+ else
+ false
end
+ RUBY
+ end
+ it "does not match object if #deconstruct_keys method does not return Hash" do
+ obj = Object.new
+ def obj.deconstruct_keys(*); "" end
+
+ -> {
eval <<~RUBY
case obj
- in Object[a: 1, b: 2, **]
+ in Object[a: 1]
end
RUBY
+ }.should raise_error(TypeError, /deconstruct_keys must return Hash/)
+ end
- ScratchPad.recorded.sort.should == [[[:a, :b]]]
- end
-
- it "passes nil to #deconstruct_keys method if pattern contains double splat operator **rest" do
- obj = Object.new
+ it "does not match object if #deconstruct_keys method returns Hash with non-symbol keys" do
+ obj = Object.new
+ def obj.deconstruct_keys(*); {"a" => 1} end
- def obj.deconstruct_keys(*args)
- ScratchPad << args
- {a: 1, b: 2}
+ eval(<<~RUBY).should == false
+ case obj
+ in Object[a: 1]
+ true
+ else
+ false
end
+ RUBY
+ end
- eval <<~RUBY
- case obj
- in Object[a: 1, **rest]
- end
- RUBY
+ it "does not match object if elements of Hash returned by #deconstruct_keys method does not match values in pattern" do
+ obj = Object.new
+ def obj.deconstruct_keys(*); {a: 1} end
- ScratchPad.recorded.should == [[nil]]
- end
+ eval(<<~RUBY).should == false
+ case obj
+ in Object[a: 2]
+ true
+ else
+ false
+ end
+ RUBY
+ end
- it "binds variables" do
- eval(<<~RUBY).should == [0, 1, 2]
- case {a: 0, b: 1, c: 2}
- in {a: x, b: y, c: z}
- [x, y, z]
- end
- RUBY
- end
+ it "passes keys specified in pattern as arguments to #deconstruct_keys method" do
+ obj = Object.new
- it "supports double splat operator **rest" do
- eval(<<~RUBY).should == {b: 1, c: 2}
- case {a: 0, b: 1, c: 2}
- in {a: 0, **rest}
- rest
- end
- RUBY
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2, c: 3}
end
- it "treats **nil like there should not be any other keys in a matched Hash" do
- eval(<<~RUBY).should == true
- case {a: 1, b: 2}
- in {a: 1, b: 2, **nil}
- true
- end
- RUBY
+ eval <<~RUBY
+ case obj
+ in Object[a: 1, b: 2, c: 3]
+ end
+ RUBY
- eval(<<~RUBY).should == false
- case {a: 1, b: 2}
- in {a: 1, **nil}
- true
- else
- false
- end
- RUBY
- end
+ ScratchPad.recorded.sort.should == [[[:a, :b, :c]]]
+ end
- it "can match partially" do
- eval(<<~RUBY).should == true
- case {a: 1, b: 2}
- in {a: 1}
- true
- end
- RUBY
- end
+ it "passes keys specified in pattern to #deconstruct_keys method if pattern contains double splat operator **" do
+ obj = Object.new
- it "matches {} with {}" do
- eval(<<~RUBY).should == true
- case {}
- in {}
- true
- end
- RUBY
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2, c: 3}
end
- it "matches anything with **" do
- eval(<<~RUBY).should == true
- case {a: 1}
- in **;
- true
- end
- RUBY
- end
+ eval <<~RUBY
+ case obj
+ in Object[a: 1, b: 2, **]
+ end
+ RUBY
- it "can be used as a nested pattern" do
- eval(<<~RUBY).should == true
- case {a: {a: 1, b: 1}, b: {a: 1, b: 2}}
- in {a: {a: 0}}
- false
- in {a: {a: 1}, b: {b: 1}}
- false
- in {a: {a: 1}, b: {b: 2}}
- true
- end
- RUBY
+ ScratchPad.recorded.sort.should == [[[:a, :b]]]
+ end
- eval(<<~RUBY).should == true
- case [{a: 1, b: [1]}, {a: 1, c: ["2"]}]
- in [{a:, c:},]
- false
- in [{a: 1, b:}, {a: 1, c: [Integer]}]
- false
- in [_, {a: 1, c: [String]}]
- true
- end
- RUBY
+ it "passes nil to #deconstruct_keys method if pattern contains double splat operator **rest" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2}
end
- end
- describe "refinements" do
- it "are used for #deconstruct" do
- refinery = Module.new do
- refine Array do
- def deconstruct
- [0]
- end
- end
+ eval <<~RUBY
+ case obj
+ in Object[a: 1, **rest]
end
+ RUBY
- result = nil
- Module.new do
- using refinery
+ ScratchPad.recorded.should == [[nil]]
+ end
- result = eval(<<~RUBY)
- case []
- in [0]
- true
- end
- RUBY
+ it "binds variables" do
+ eval(<<~RUBY).should == [0, 1, 2]
+ case {a: 0, b: 1, c: 2}
+ in {a: x, b: y, c: z}
+ [x, y, z]
end
+ RUBY
+ end
- result.should == true
- end
-
- it "are used for #deconstruct_keys" do
- refinery = Module.new do
- refine Hash do
- def deconstruct_keys(_)
- {a: 0}
- end
- end
+ it "supports double splat operator **rest" do
+ eval(<<~RUBY).should == {b: 1, c: 2}
+ case {a: 0, b: 1, c: 2}
+ in {a: 0, **rest}
+ rest
end
+ RUBY
+ end
- result = nil
- Module.new do
- using refinery
+ it "treats **nil like there should not be any other keys in a matched Hash" do
+ eval(<<~RUBY).should == true
+ case {a: 1, b: 2}
+ in {a: 1, b: 2, **nil}
+ true
+ end
+ RUBY
- result = eval(<<~RUBY)
- case {}
- in a: 0
- true
- end
- RUBY
+ eval(<<~RUBY).should == false
+ case {a: 1, b: 2}
+ in {a: 1, **nil}
+ true
+ else
+ false
end
+ RUBY
+ end
- result.should == true
- end
+ it "can match partially" do
+ eval(<<~RUBY).should == true
+ case {a: 1, b: 2}
+ in {a: 1}
+ true
+ end
+ RUBY
+ end
- it "are used for #=== in constant pattern" do
- refinery = Module.new do
- refine Array.singleton_class do
- def ===(obj)
- obj.is_a?(Hash)
- end
- end
+ it "matches {} with {}" do
+ eval(<<~RUBY).should == true
+ case {}
+ in {}
+ true
end
+ RUBY
+ end
- result = nil
- Module.new do
- using refinery
+ it "matches anything with **" do
+ eval(<<~RUBY).should == true
+ case {a: 1}
+ in **;
+ true
+ end
+ RUBY
+ end
- result = eval(<<~RUBY)
- case {}
- in Array
- true
- end
- RUBY
+ it "can be used as a nested pattern" do
+ eval(<<~RUBY).should == true
+ case {a: {a: 1, b: 1}, b: {a: 1, b: 2}}
+ in {a: {a: 0}}
+ false
+ in {a: {a: 1}, b: {b: 1}}
+ false
+ in {a: {a: 1}, b: {b: 2}}
+ true
end
+ RUBY
- result.should == true
- end
+ eval(<<~RUBY).should == true
+ case [{a: 1, b: [1]}, {a: 1, c: ["2"]}]
+ in [{a:, c:},]
+ false
+ in [{a: 1, b:}, {a: 1, c: [Integer]}]
+ false
+ in [_, {a: 1, c: [String]}]
+ true
+ end
+ RUBY
end
+ end
- ruby_version_is "3.1" do
- it "can omit parentheses in one line pattern matching" do
- eval(<<~RUBY).should == [1, 2]
- [1, 2] => a, b
- [a, b]
- RUBY
-
- eval(<<~RUBY).should == 1
- {a: 1} => a:
- a
- RUBY
+ describe "refinements" do
+ it "are used for #deconstruct" do
+ refinery = Module.new do
+ refine Array do
+ def deconstruct
+ [0]
+ end
+ end
end
- it "supports pinning instance variables" do
- eval(<<~RUBY).should == true
- @a = /a/
- case 'abc'
- in ^@a
+ result = nil
+ Module.new do
+ using refinery
+
+ result = eval(<<~RUBY)
+ case []
+ in [0]
true
end
RUBY
end
- it "supports pinning class variables" do
- result = nil
- Module.new do
- result = module_eval(<<~RUBY)
- @@a = 0..10
+ result.should == true
+ end
- case 2
- in ^@@a
- true
- end
- RUBY
+ it "are used for #deconstruct_keys" do
+ refinery = Module.new do
+ refine Hash do
+ def deconstruct_keys(_)
+ {a: 0}
+ end
end
-
- result.should == true
end
- it "supports pinning global variables" do
- eval(<<~RUBY).should == true
- $a = /a/
- case 'abc'
- in ^$a
+ result = nil
+ Module.new do
+ using refinery
+
+ result = eval(<<~RUBY)
+ case {}
+ in a: 0
true
end
RUBY
end
- it "supports pinning expressions" do
- eval(<<~RUBY).should == true
- case 'abc'
- in ^(/a/)
- true
+ result.should == true
+ end
+
+ it "are used for #=== in constant pattern" do
+ refinery = Module.new do
+ refine Array.singleton_class do
+ def ===(obj)
+ obj.is_a?(Hash)
end
- RUBY
+ end
+ end
- eval(<<~RUBY).should == true
- case {name: '2.6', released_at: Time.new(2018, 12, 25)}
- in {released_at: ^(Time.new(2010)..Time.new(2020))}
+ result = nil
+ Module.new do
+ using refinery
+
+ result = eval(<<~RUBY)
+ case {}
+ in Array
true
end
RUBY
+ end
- eval(<<~RUBY).should == true
- case 0
- in ^(0+0)
+ result.should == true
+ end
+ end
+
+ ruby_version_is "3.1" do
+ it "can omit parentheses in one line pattern matching" do
+ eval(<<~RUBY).should == [1, 2]
+ [1, 2] => a, b
+ [a, b]
+ RUBY
+
+ eval(<<~RUBY).should == 1
+ {a: 1} => a:
+ a
+ RUBY
+ end
+
+ it "supports pinning instance variables" do
+ eval(<<~RUBY).should == true
+ @a = /a/
+ case 'abc'
+ in ^@a
+ true
+ end
+ RUBY
+ end
+
+ it "supports pinning class variables" do
+ result = nil
+ Module.new do
+ result = module_eval(<<~RUBY)
+ @@a = 0..10
+
+ case 2
+ in ^@@a
true
end
RUBY
end
+
+ result.should == true
+ end
+
+ it "supports pinning global variables" do
+ eval(<<~RUBY).should == true
+ $a = /a/
+ case 'abc'
+ in ^$a
+ true
+ end
+ RUBY
+ end
+
+ it "supports pinning expressions" do
+ eval(<<~RUBY).should == true
+ case 'abc'
+ in ^(/a/)
+ true
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case {name: '2.6', released_at: Time.new(2018, 12, 25)}
+ in {released_at: ^(Time.new(2010)..Time.new(2020))}
+ true
+ end
+ RUBY
+
+ eval(<<~RUBY).should == true
+ case 0
+ in ^(0+0)
+ true
+ end
+ RUBY
end
end
end
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index d04dfcf251..b5eda7f789 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -654,10 +654,8 @@ describe "Predefined global $," do
-> { $, = Object.new }.should raise_error(TypeError)
end
- ruby_version_is "2.7" do
- it "warns if assigned non-nil" do
- -> { $, = "_" }.should complain(/warning: `\$,' is deprecated/)
- end
+ it "warns if assigned non-nil" do
+ -> { $, = "_" }.should complain(/warning: `\$,' is deprecated/)
end
end
@@ -693,10 +691,8 @@ describe "Predefined global $;" do
$; = nil
end
- ruby_version_is "2.7" do
- it "warns if assigned non-nil" do
- -> { $; = "_" }.should complain(/warning: `\$;' is deprecated/)
- end
+ it "warns if assigned non-nil" do
+ -> { $; = "_" }.should complain(/warning: `\$;' is deprecated/)
end
end
@@ -1316,33 +1312,31 @@ describe "The predefined global constant" do
end
end
-ruby_version_is "2.7" do
- describe "$LOAD_PATH.resolve_feature_path" do
- it "returns what will be loaded without actual loading, .rb file" do
- extension, path = $LOAD_PATH.resolve_feature_path('set')
- extension.should == :rb
- path.should.end_with?('/set.rb')
- end
+describe "$LOAD_PATH.resolve_feature_path" do
+ it "returns what will be loaded without actual loading, .rb file" do
+ extension, path = $LOAD_PATH.resolve_feature_path('set')
+ extension.should == :rb
+ path.should.end_with?('/set.rb')
+ end
- it "returns what will be loaded without actual loading, .so file" do
- require 'rbconfig'
- skip "no dynamically loadable standard extension" if RbConfig::CONFIG["EXTSTATIC"] == "static"
+ it "returns what will be loaded without actual loading, .so file" do
+ require 'rbconfig'
+ skip "no dynamically loadable standard extension" if RbConfig::CONFIG["EXTSTATIC"] == "static"
- extension, path = $LOAD_PATH.resolve_feature_path('etc')
- extension.should == :so
- path.should.end_with?("/etc.#{RbConfig::CONFIG['DLEXT']}")
- end
+ extension, path = $LOAD_PATH.resolve_feature_path('etc')
+ extension.should == :so
+ path.should.end_with?("/etc.#{RbConfig::CONFIG['DLEXT']}")
+ end
- ruby_version_is "2.7"..."3.1" do
- it "raises LoadError if feature cannot be found" do
- -> { $LOAD_PATH.resolve_feature_path('noop') }.should raise_error(LoadError)
- end
+ ruby_version_is ""..."3.1" do
+ it "raises LoadError if feature cannot be found" do
+ -> { $LOAD_PATH.resolve_feature_path('noop') }.should raise_error(LoadError)
end
+ end
- ruby_version_is "3.1" do
- it "return nil if feature cannot be found" do
- $LOAD_PATH.resolve_feature_path('noop').should be_nil
- end
+ ruby_version_is "3.1" do
+ it "return nil if feature cannot be found" do
+ $LOAD_PATH.resolve_feature_path('noop').should be_nil
end
end
end
diff --git a/spec/ruby/language/proc_spec.rb b/spec/ruby/language/proc_spec.rb
index ef4a43bed6..8360967ec8 100644
--- a/spec/ruby/language/proc_spec.rb
+++ b/spec/ruby/language/proc_spec.rb
@@ -223,13 +223,7 @@ describe "A Proc" do
@p = proc { |*a, **kw| [a, kw] }
end
- ruby_version_is ""..."2.7" do
- it 'autosplats keyword arguments' do
- @p.call([1, {a: 1}]).should == [[1], {a: 1}]
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it 'autosplats keyword arguments and warns' do
-> {
@p.call([1, {a: 1}]).should == [[1], {a: 1}]
diff --git a/spec/ruby/language/range_spec.rb b/spec/ruby/language/range_spec.rb
index 79500c6b33..55dc65882a 100644
--- a/spec/ruby/language/range_spec.rb
+++ b/spec/ruby/language/range_spec.rb
@@ -15,10 +15,8 @@ describe "Literal Ranges" do
(1...).should == Range.new(1, nil, true)
end
- ruby_version_is "2.7" do
- it "creates beginless ranges" do
- eval("(..1)").should == Range.new(nil, 1)
- eval("(...1)").should == Range.new(nil, 1, true)
- end
+ it "creates beginless ranges" do
+ (..1).should == Range.new(nil, 1)
+ (...1).should == Range.new(nil, 1, true)
end
end
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index fcd9ae0de9..b91b52fa0f 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -504,14 +504,12 @@ describe "The rescue keyword" do
}.should raise_error(Exception)
end
- ruby_version_is "2.7" do
- it "rescues with multiple assignment" do
+ it "rescues with multiple assignment" do
- a, b = raise rescue [1, 2]
+ a, b = raise rescue [1, 2]
- a.should == 1
- b.should == 2
- end
+ a.should == 1
+ b.should == 2
end
end
end
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index d8506834c8..94c15b697e 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -422,18 +422,16 @@ describe "The return keyword" do
end
describe "within a block within a class" do
- ruby_version_is "2.7" do
- it "is not allowed" do
- File.write(@filename, <<-END_OF_CODE)
- class ReturnSpecs::A
- ScratchPad << "before return"
- 1.times { return }
- ScratchPad << "after return"
- end
- END_OF_CODE
-
- -> { load @filename }.should raise_error(LocalJumpError)
- end
+ it "is not allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ class ReturnSpecs::A
+ ScratchPad << "before return"
+ 1.times { return }
+ ScratchPad << "after return"
+ end
+ END_OF_CODE
+
+ -> { load @filename }.should raise_error(LocalJumpError)
end
end
@@ -464,25 +462,13 @@ describe "The return keyword" do
end
describe "return with argument" do
- ruby_version_is ""..."2.7" do
- it "does not affect exit status" do
- ruby_exe(<<-END_OF_CODE).should == ""
- return 10
- END_OF_CODE
-
- $?.exitstatus.should == 0
- end
- end
-
- ruby_version_is "2.7" do
- it "warns but does not affect exit status" do
- err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
- return 10
- END_OF_CODE
- $?.exitstatus.should == 0
+ it "warns but does not affect exit status" do
+ err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
+ return 10
+ END_OF_CODE
+ $?.exitstatus.should == 0
- err.should =~ /warning: argument of top-level return is ignored/
- end
+ err.should =~ /warning: argument of top-level return is ignored/
end
end
end
diff --git a/spec/ruby/language/safe_spec.rb b/spec/ruby/language/safe_spec.rb
index 89830a2069..ee5c1b3ccc 100644
--- a/spec/ruby/language/safe_spec.rb
+++ b/spec/ruby/language/safe_spec.rb
@@ -1,99 +1,7 @@
require_relative '../spec_helper'
describe "The $SAFE variable" do
- ruby_version_is ""..."2.7" do
- after :each do
- $SAFE = 0
- end
-
- it "is 0 by default" do
- $SAFE.should == 0
- proc {
- $SAFE.should == 0
- }.call
- end
-
- it "can be set to 0" do
- proc {
- $SAFE = 0
- $SAFE.should == 0
- }.call
- end
-
- it "can be set to 1" do
- proc {
- $SAFE = 1
- $SAFE.should == 1
- }.call
- end
-
- [2, 3, 4].each do |n|
- it "cannot be set to #{n}" do
- -> {
- proc {
- $SAFE = n
- }.call
- }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
- end
- end
-
- it "raises ArgumentError when set to values below 0" do
- -> {
- proc {
- $SAFE = -100
- }.call
- }.should raise_error(ArgumentError, "$SAFE should be >= 0")
- end
-
- it "cannot be set to values above 4" do
- -> {
- proc {
- $SAFE = 100
- }.call
- }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
- end
-
- it "can be manually lowered" do
- $SAFE = 1
- $SAFE = 0
- $SAFE.should == 0
- end
-
- it "is not Proc local" do
- $SAFE.should == 0
- proc {
- $SAFE = 1
- }.call
- $SAFE.should == 1
- end
-
- it "is not lambda local" do
- $SAFE.should == 0
- -> {
- $SAFE = 1
- }.call
- $SAFE.should == 1
- end
-
- it "is global like regular global variables" do
- Thread.new { $SAFE }.value.should == 0
- $SAFE = 1
- Thread.new { $SAFE }.value.should == 1
- end
-
- it "can be read when default from Thread#safe_level" do
- Thread.current.safe_level.should == 0
- end
-
- it "can be read when modified from Thread#safe_level" do
- proc {
- $SAFE = 1
- Thread.current.safe_level.should == 1
- }.call
- end
- end
-
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it "warn when access" do
-> {
$SAFE
diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb
index e57e2c65dc..5999079d58 100644
--- a/spec/ruby/language/send_spec.rb
+++ b/spec/ruby/language/send_spec.rb
@@ -258,20 +258,10 @@ describe "Invoking a private setter method" do
end
describe "Invoking a private getter method" do
- ruby_version_is ""..."2.7" do
- it "does not permit self as a receiver" do
- receiver = LangSendSpecs::PrivateGetter.new
- -> { receiver.call_self_foo }.should raise_error(NoMethodError)
- -> { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError)
- end
- end
-
- ruby_version_is "2.7" do
- it "permits self as a receiver" do
- receiver = LangSendSpecs::PrivateGetter.new
- receiver.call_self_foo_or_equals(6)
- receiver.call_self_foo.should == 6
- end
+ it "permits self as a receiver" do
+ receiver = LangSendSpecs::PrivateGetter.new
+ receiver.call_self_foo_or_equals(6)
+ receiver.call_self_foo.should == 6
end
end
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index ce4941569e..02e3488a1f 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -56,28 +56,6 @@ describe "Ruby character strings" do
"#\$".should == '#$'
end
- ruby_version_is ''...'2.7' do
- it "taints the result of interpolation when an interpolated value is tainted" do
- "#{"".taint}".tainted?.should be_true
-
- @ip.taint
- "#@ip".tainted?.should be_true
-
- $ip.taint
- "#$ip".tainted?.should be_true
- end
-
- it "untrusts the result of interpolation when an interpolated value is untrusted" do
- "#{"".untrust}".untrusted?.should be_true
-
- @ip.untrust
- "#@ip".untrusted?.should be_true
-
- $ip.untrust
- "#$ip".untrusted?.should be_true
- end
- end
-
it "allows using non-alnum characters as string delimiters" do
%(hey #{@ip}).should == "hey xxx"
%[hey #{@ip}].should == "hey xxx"
diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb
index 3db6d353a9..85bd5af25b 100644
--- a/spec/ruby/language/yield_spec.rb
+++ b/spec/ruby/language/yield_spec.rb
@@ -186,7 +186,7 @@ describe "The yield call" do
end
describe "Using yield in a singleton class literal" do
- ruby_version_is "2.7"..."3.0" do
+ ruby_version_is ""..."3.0" do
it 'emits a deprecation warning' do
code = <<~RUBY
def m
diff --git a/spec/ruby/library/cmath/math/acos_spec.rb b/spec/ruby/library/cmath/math/acos_spec.rb
index 2e9104f835..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/acos_spec.rb
+++ b/spec/ruby/library/cmath/math/acos_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/acos'
-
- describe "Math#acos" do
- it_behaves_like :complex_math_acos, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:acos)
- end
- end
-
- describe "Math.acos" do
- it_behaves_like :complex_math_acos, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/acosh_spec.rb b/spec/ruby/library/cmath/math/acosh_spec.rb
index 809112f6c0..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/acosh_spec.rb
+++ b/spec/ruby/library/cmath/math/acosh_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/acosh'
-
- describe "Math#acosh" do
- it_behaves_like :complex_math_acosh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:acosh)
- end
- end
-
- describe "Math.acosh" do
- it_behaves_like :complex_math_acosh, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/asin_spec.rb b/spec/ruby/library/cmath/math/asin_spec.rb
index 4ac588ebd2..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/asin_spec.rb
+++ b/spec/ruby/library/cmath/math/asin_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/asin'
-
- describe "Math#asin" do
- it_behaves_like :complex_math_asin, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:asin)
- end
- end
-
- describe "Math.asin" do
- it_behaves_like :complex_math_asin, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/asinh_spec.rb b/spec/ruby/library/cmath/math/asinh_spec.rb
index 7d8b397a04..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/asinh_spec.rb
+++ b/spec/ruby/library/cmath/math/asinh_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/asinh'
-
- describe "Math#asinh" do
- it_behaves_like :complex_math_asinh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:asinh)
- end
- end
-
- describe "Math.asinh" do
- it_behaves_like :complex_math_asinh, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/atan2_spec.rb b/spec/ruby/library/cmath/math/atan2_spec.rb
index 1a9b7d7607..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/atan2_spec.rb
+++ b/spec/ruby/library/cmath/math/atan2_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/atan2'
-
- describe "Math#atan2" do
- it_behaves_like :complex_math_atan2, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:atan2)
- end
- end
-
- describe "Math.atan2" do
- it_behaves_like :complex_math_atan2, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/atan_spec.rb b/spec/ruby/library/cmath/math/atan_spec.rb
index b0171081a6..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/atan_spec.rb
+++ b/spec/ruby/library/cmath/math/atan_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/atan'
-
- describe "Math#atan" do
- it_behaves_like :complex_math_atan, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:atan)
- end
- end
-
- describe "Math.atan" do
- it_behaves_like :complex_math_atan, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/atanh_spec.rb b/spec/ruby/library/cmath/math/atanh_spec.rb
index 6b22c6c9e4..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/atanh_spec.rb
+++ b/spec/ruby/library/cmath/math/atanh_spec.rb
@@ -1,20 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative '../../../fixtures/math/common'
- require_relative '../../../shared/math/atanh'
- require_relative 'shared/atanh'
-
- describe "Math#atanh" do
- it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
- it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
-
- it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
- end
-
- describe "Math.atanh" do
- it_behaves_like :math_atanh_base, :atanh, CMath
- it_behaves_like :complex_math_atanh_complex, :atanh, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/cos_spec.rb b/spec/ruby/library/cmath/math/cos_spec.rb
index 3f097bcb3b..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/cos_spec.rb
+++ b/spec/ruby/library/cmath/math/cos_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/cos'
-
- describe "Math#cos" do
- it_behaves_like :complex_math_cos, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:cos)
- end
- end
-
- describe "Math.cos" do
- it_behaves_like :complex_math_cos, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/cosh_spec.rb b/spec/ruby/library/cmath/math/cosh_spec.rb
index 197f899981..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/cosh_spec.rb
+++ b/spec/ruby/library/cmath/math/cosh_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/cosh'
-
- describe "Math#cosh" do
- it_behaves_like :complex_math_cosh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:cosh)
- end
- end
-
- describe "Math.cosh" do
- it_behaves_like :complex_math_cosh, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/exp_spec.rb b/spec/ruby/library/cmath/math/exp_spec.rb
index eef2ec3129..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/exp_spec.rb
+++ b/spec/ruby/library/cmath/math/exp_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/exp'
-
- describe "Math#exp" do
- it_behaves_like :complex_math_exp, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:exp)
- end
- end
-
- describe "Math.exp" do
- it_behaves_like :complex_math_exp, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/log10_spec.rb b/spec/ruby/library/cmath/math/log10_spec.rb
index 603bbb1457..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/log10_spec.rb
+++ b/spec/ruby/library/cmath/math/log10_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/log10'
-
- describe "Math#log10" do
- it_behaves_like :complex_math_log10, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:log10)
- end
- end
-
- describe "Math.log10" do
- it_behaves_like :complex_math_log10, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/log_spec.rb b/spec/ruby/library/cmath/math/log_spec.rb
index b4da781323..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/log_spec.rb
+++ b/spec/ruby/library/cmath/math/log_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/log'
-
- describe "Math#log" do
- it_behaves_like :complex_math_log, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:log)
- end
- end
-
- describe "Math.log" do
- it_behaves_like :complex_math_log, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/sin_spec.rb b/spec/ruby/library/cmath/math/sin_spec.rb
index b7a219fbbd..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/sin_spec.rb
+++ b/spec/ruby/library/cmath/math/sin_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/sin'
-
- describe "Math#sin" do
- it_behaves_like :complex_math_sin, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sin)
- end
- end
-
- describe "Math.sin" do
- it_behaves_like :complex_math_sin, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/sinh_spec.rb b/spec/ruby/library/cmath/math/sinh_spec.rb
index c6e6a3baf4..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/sinh_spec.rb
+++ b/spec/ruby/library/cmath/math/sinh_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/sinh'
-
- describe "Math#sinh" do
- it_behaves_like :complex_math_sinh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sinh)
- end
- end
-
- describe "Math.sinh" do
- it_behaves_like :complex_math_sinh, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/sqrt_spec.rb b/spec/ruby/library/cmath/math/sqrt_spec.rb
index 421824f99c..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/sqrt_spec.rb
+++ b/spec/ruby/library/cmath/math/sqrt_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/sqrt'
-
- describe "Math#sqrt" do
- it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sqrt)
- end
- end
-
- describe "Math.sqrt" do
- it_behaves_like :complex_math_sqrt, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/tan_spec.rb b/spec/ruby/library/cmath/math/tan_spec.rb
index e2acdd8091..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/tan_spec.rb
+++ b/spec/ruby/library/cmath/math/tan_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/tan'
-
- describe "Math#tan" do
- it_behaves_like :complex_math_tan, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:tan)
- end
- end
-
- describe "Math.tan" do
- it_behaves_like :complex_math_tan, :_, CMath
- end
-end
diff --git a/spec/ruby/library/cmath/math/tanh_spec.rb b/spec/ruby/library/cmath/math/tanh_spec.rb
index 94da20cd51..e15f14f95f 100644
--- a/spec/ruby/library/cmath/math/tanh_spec.rb
+++ b/spec/ruby/library/cmath/math/tanh_spec.rb
@@ -1,18 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require 'complex'
- require_relative 'shared/tanh'
-
- describe "Math#tanh" do
- it_behaves_like :complex_math_tanh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:tanh)
- end
- end
-
- describe "Math.tanh" do
- it_behaves_like :complex_math_tanh, :_, CMath
- end
-end
diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb
index f6ca3f579d..e474dfb450 100644
--- a/spec/ruby/library/date/shared/valid_jd.rb
+++ b/spec/ruby/library/date/shared/valid_jd.rb
@@ -10,23 +10,11 @@ describe :date_valid_jd?, shared: true do
Date.send(@method, nil).should be_false
end
- ruby_version_is ''...'2.7' do
- it "returns true if passed symbol" do
- Date.send(@method, :number).should be_true
- end
-
- it "returns true if passed false" do
- Date.send(@method, false).should be_true
- end
+ it "returns false if passed symbol" do
+ Date.send(@method, :number).should be_false
end
- ruby_version_is '2.7' do
- it "returns false if passed symbol" do
- Date.send(@method, :number).should be_false
- end
-
- it "returns false if passed false" do
- Date.send(@method, false).should be_false
- end
+ it "returns false if passed false" do
+ Date.send(@method, false).should be_false
end
end
diff --git a/spec/ruby/library/delegate/delegator/taint_spec.rb b/spec/ruby/library/delegate/delegator/taint_spec.rb
index b875b5a6b8..6bf13bb73d 100644
--- a/spec/ruby/library/delegate/delegator/taint_spec.rb
+++ b/spec/ruby/library/delegate/delegator/taint_spec.rb
@@ -5,21 +5,4 @@ describe "Delegator#taint" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
-
- ruby_version_is ''...'2.7' do
- it "returns self" do
- @delegate.taint.equal?(@delegate).should be_true
- end
-
- it "taints the delegator" do
- @delegate.__setobj__(nil)
- @delegate.taint
- @delegate.tainted?.should be_true
- end
-
- it "taints the delegated object" do
- @delegate.taint
- @delegate.__getobj__.tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/library/delegate/delegator/trust_spec.rb b/spec/ruby/library/delegate/delegator/trust_spec.rb
index 492f02e27f..f1b81814c5 100644
--- a/spec/ruby/library/delegate/delegator/trust_spec.rb
+++ b/spec/ruby/library/delegate/delegator/trust_spec.rb
@@ -5,20 +5,4 @@ describe "Delegator#trust" do
before :each do
@delegate = DelegateSpecs::Delegator.new([])
end
-
- ruby_version_is ''...'2.7' do
- it "returns self" do
- @delegate.trust.equal?(@delegate).should be_true
- end
-
- it "trusts the delegator" do
- @delegate.trust
- @delegate.untrusted?.should be_false
- end
-
- it "trusts the delegated object" do
- @delegate.trust
- @delegate.__getobj__.untrusted?.should be_false
- end
- end
end
diff --git a/spec/ruby/library/delegate/delegator/untaint_spec.rb b/spec/ruby/library/delegate/delegator/untaint_spec.rb
index 3f8f7721a9..4051fd2629 100644
--- a/spec/ruby/library/delegate/delegator/untaint_spec.rb
+++ b/spec/ruby/library/delegate/delegator/untaint_spec.rb
@@ -5,22 +5,4 @@ describe "Delegator#untaint" do
before :each do
@delegate = -> { DelegateSpecs::Delegator.new("") }.call
end
-
- ruby_version_is ''...'2.7' do
- it "returns self" do
- @delegate.untaint.equal?(@delegate).should be_true
- end
-
- it "untaints the delegator" do
- @delegate.untaint
- @delegate.tainted?.should be_false
- # No additional meaningful test; that it does or not taint
- # "for real" the delegator has no consequence
- end
-
- it "untaints the delegated object" do
- @delegate.untaint
- @delegate.__getobj__.tainted?.should be_false
- end
- end
end
diff --git a/spec/ruby/library/delegate/delegator/untrust_spec.rb b/spec/ruby/library/delegate/delegator/untrust_spec.rb
index acc91b099a..4f7fa1e582 100644
--- a/spec/ruby/library/delegate/delegator/untrust_spec.rb
+++ b/spec/ruby/library/delegate/delegator/untrust_spec.rb
@@ -5,21 +5,4 @@ describe "Delegator#untrust" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
-
- ruby_version_is ''...'2.7' do
- it "returns self" do
- @delegate.untrust.equal?(@delegate).should be_true
- end
-
- it "untrusts the delegator" do
- @delegate.__setobj__(nil)
- @delegate.untrust
- @delegate.untrusted?.should be_true
- end
-
- it "untrusts the delegated object" do
- @delegate.untrust
- @delegate.__getobj__.untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/library/openstruct/method_missing_spec.rb b/spec/ruby/library/openstruct/method_missing_spec.rb
index 212db015a9..89f83d07b3 100644
--- a/spec/ruby/library/openstruct/method_missing_spec.rb
+++ b/spec/ruby/library/openstruct/method_missing_spec.rb
@@ -17,10 +17,8 @@ describe "OpenStruct#method_missing when passed additional arguments" do
-> { os.test(1, 2, 3) }.should raise_error(NoMethodError)
end
- ruby_version_is "2.7" do
- it "raises an ArgumentError when the key exists" do
- os = OpenStruct.new(test: 20)
- -> { os.test(1, 2, 3) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when the key exists" do
+ os = OpenStruct.new(test: 20)
+ -> { os.test(1, 2, 3) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/library/pathname/glob_spec.rb b/spec/ruby/library/pathname/glob_spec.rb
index e2186d14d6..ced810fa90 100644
--- a/spec/ruby/library/pathname/glob_spec.rb
+++ b/spec/ruby/library/pathname/glob_spec.rb
@@ -40,19 +40,9 @@ describe 'Pathname.glob' do
}.should raise_error(ArgumentError, /unknown keyword: :?foo/)
end
- ruby_version_is ''...'2.7' do
- it 'raises an ArgumentError when supplied a flag and :base keyword argument' do
- -> {
- Pathname.glob(@dir + 'lib/*i*.rb', File::FNM_DOTMATCH, base: 'lib')
- }.should raise_error(ArgumentError, 'wrong number of arguments (given 3, expected 1..2)')
- end
- end
-
- ruby_version_is "2.7" do
- it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do
- expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort
- Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected
- end
+ it "does not raise an ArgumentError when supplied a flag and :base keyword argument" do
+ expected = [Pathname.new('ipaddr.rb'), Pathname.new('irb.rb'), Pathname.new('.hidden.rb')].sort
+ Pathname.glob('*i*.rb', File::FNM_DOTMATCH, base: @dir + 'lib').sort.should == expected
end
end
diff --git a/spec/ruby/library/pathname/new_spec.rb b/spec/ruby/library/pathname/new_spec.rb
index 760fd8638f..36226ed515 100644
--- a/spec/ruby/library/pathname/new_spec.rb
+++ b/spec/ruby/library/pathname/new_spec.rb
@@ -10,13 +10,6 @@ describe "Pathname.new" do
-> { Pathname.new("\0")}.should raise_error(ArgumentError)
end
- ruby_version_is ''...'2.7' do
- it "is tainted if path is tainted" do
- path = '/usr/local/bin'.taint
- Pathname.new(path).should.tainted?
- end
- end
-
it "raises a TypeError if not passed a String type" do
-> { Pathname.new(nil) }.should raise_error(TypeError)
-> { Pathname.new(0) }.should raise_error(TypeError)
diff --git a/spec/ruby/library/pathname/pathname_spec.rb b/spec/ruby/library/pathname/pathname_spec.rb
index 7d63fe86e3..0fb2881468 100644
--- a/spec/ruby/library/pathname/pathname_spec.rb
+++ b/spec/ruby/library/pathname/pathname_spec.rb
@@ -10,21 +10,10 @@ describe "Kernel#Pathname" do
Kernel.should have_method(:Pathname)
end
- ruby_version_is ''...'2.7' do
- it "returns a new pathname when called with a pathname argument" do
- path = Pathname('foo')
- new_path = Pathname(path)
+ it "returns same argument when called with a pathname argument" do
+ path = Pathname('foo')
+ new_path = Pathname(path)
- path.should_not.equal?(new_path)
- end
- end
-
- ruby_version_is '2.7' do
- it "returns same argument when called with a pathname argument" do
- path = Pathname('foo')
- new_path = Pathname(path)
-
- path.should.equal?(new_path)
- end
+ path.should.equal?(new_path)
end
end
diff --git a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
index 9b64ea6de2..a4a24c535d 100644
--- a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
+++ b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
@@ -2,33 +2,21 @@ require_relative '../../spec_helper'
require 'rbconfig'
describe "RbConfig::CONFIG['UNICODE_EMOJI_VERSION']" do
- ruby_version_is "2.6"..."2.6.2" do
- it "is 11.0 for Ruby 2.6.0 and 2.6.1" do
- RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "11.0"
- end
- end
-
- ruby_version_is "2.6.2"..."2.7" do
- it "is 12.0 for Ruby 2.6.2+" do
- RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "12.0"
- end
- end
-
- ruby_version_is "2.7"..."3.1" do
- it "is 12.1 for Ruby 2.7 and 3.0" do
+ ruby_version_is ""..."3.1" do
+ it "is 12.1" do
RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "12.1"
end
end
ruby_version_is "3.1"..."3.2" do
- it "is 13.1 for Ruby 3.1" do
+ it "is 13.1" do
RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "13.1"
end
end
# Caution: ruby_version_is means is_or_later
ruby_version_is "3.2" do
- it "is 14.0 for Ruby 3.2 or later" do
+ it "is 14.0" do
RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "14.0"
end
end
diff --git a/spec/ruby/library/rbconfig/unicode_version_spec.rb b/spec/ruby/library/rbconfig/unicode_version_spec.rb
index 312d3c92d4..d0ff856764 100644
--- a/spec/ruby/library/rbconfig/unicode_version_spec.rb
+++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb
@@ -2,33 +2,21 @@ require_relative '../../spec_helper'
require 'rbconfig'
describe "RbConfig::CONFIG['UNICODE_VERSION']" do
- ruby_version_is "2.6"..."2.6.2" do
- it "is 11.0.0 for Ruby 2.6.0 and 2.6.1" do
- RbConfig::CONFIG['UNICODE_VERSION'].should == "11.0.0"
- end
- end
-
- ruby_version_is "2.6.2"..."2.6.3" do
- it "is 12.0.0 for Ruby 2.6.2" do
- RbConfig::CONFIG['UNICODE_VERSION'].should == "12.0.0"
- end
- end
-
- ruby_version_is "2.6.3"..."3.1" do
- it "is 12.1.0 for Ruby 2.6.3+, Ruby 2.7, and Ruby 3.0" do
+ ruby_version_is ""..."3.1" do
+ it "is 12.1.0" do
RbConfig::CONFIG['UNICODE_VERSION'].should == "12.1.0"
end
end
ruby_version_is "3.1"..."3.2" do
- it "is 13.0.0 for Ruby 3.1" do
+ it "is 13.0.0" do
RbConfig::CONFIG['UNICODE_VERSION'].should == "13.0.0"
end
end
# Caution: ruby_version_is means is_or_later
ruby_version_is "3.2" do
- it "is 14.0.0 for Ruby 3.2 or later" do
+ it "is 14.0.0" do
RbConfig::CONFIG['UNICODE_VERSION'].should == "14.0.0"
end
end
diff --git a/spec/ruby/library/readline/history/delete_at_spec.rb b/spec/ruby/library/readline/history/delete_at_spec.rb
index c95a6a865e..3bd577e75c 100644
--- a/spec/ruby/library/readline/history/delete_at_spec.rb
+++ b/spec/ruby/library/readline/history/delete_at_spec.rb
@@ -34,14 +34,5 @@ with_feature :readline do
-> { Readline::HISTORY.delete_at(10) }.should raise_error(IndexError)
-> { Readline::HISTORY.delete_at(-10) }.should raise_error(IndexError)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned strings" do
- Readline::HISTORY.push("1", "2", "3")
- Readline::HISTORY.delete_at(0).tainted?.should be_true
- Readline::HISTORY.delete_at(0).tainted?.should be_true
- Readline::HISTORY.delete_at(0).tainted?.should be_true
- end
- end
end
end
diff --git a/spec/ruby/library/readline/history/each_spec.rb b/spec/ruby/library/readline/history/each_spec.rb
index 23387bfc98..aa48dd46df 100644
--- a/spec/ruby/library/readline/history/each_spec.rb
+++ b/spec/ruby/library/readline/history/each_spec.rb
@@ -19,13 +19,5 @@ with_feature :readline do
end
result.should == ["1", "2", "3"]
end
-
- ruby_version_is ''...'2.7' do
- it "yields tainted Objects" do
- Readline::HISTORY.each do |x|
- x.tainted?.should be_true
- end
- end
- end
end
end
diff --git a/spec/ruby/library/readline/history/element_reference_spec.rb b/spec/ruby/library/readline/history/element_reference_spec.rb
index dfa5367cad..0a74f3d62d 100644
--- a/spec/ruby/library/readline/history/element_reference_spec.rb
+++ b/spec/ruby/library/readline/history/element_reference_spec.rb
@@ -12,13 +12,6 @@ with_feature :readline do
Readline::HISTORY.pop
end
- ruby_version_is ''...'2.7' do
- it "returns tainted objects" do
- Readline::HISTORY[0].tainted?.should be_true
- Readline::HISTORY[1].tainted?.should be_true
- end
- end
-
it "returns the history item at the passed index" do
Readline::HISTORY[0].should == "1"
Readline::HISTORY[1].should == "2"
diff --git a/spec/ruby/library/readline/history/pop_spec.rb b/spec/ruby/library/readline/history/pop_spec.rb
index e17be666d8..156a8a06f8 100644
--- a/spec/ruby/library/readline/history/pop_spec.rb
+++ b/spec/ruby/library/readline/history/pop_spec.rb
@@ -19,14 +19,5 @@ with_feature :readline do
Readline::HISTORY.pop.should == "1"
Readline::HISTORY.size.should == 0
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned strings" do
- Readline::HISTORY.push("1", "2", "3")
- Readline::HISTORY.pop.tainted?.should be_true
- Readline::HISTORY.pop.tainted?.should be_true
- Readline::HISTORY.pop.tainted?.should be_true
- end
- end
end
end
diff --git a/spec/ruby/library/readline/history/shift_spec.rb b/spec/ruby/library/readline/history/shift_spec.rb
index ccd90193fd..9aad7d5399 100644
--- a/spec/ruby/library/readline/history/shift_spec.rb
+++ b/spec/ruby/library/readline/history/shift_spec.rb
@@ -19,14 +19,5 @@ with_feature :readline do
Readline::HISTORY.shift.should == "3"
Readline::HISTORY.size.should == 0
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned strings" do
- Readline::HISTORY.push("1", "2", "3")
- Readline::HISTORY.shift.tainted?.should be_true
- Readline::HISTORY.shift.tainted?.should be_true
- Readline::HISTORY.shift.tainted?.should be_true
- end
- end
end
end
diff --git a/spec/ruby/library/readline/readline_spec.rb b/spec/ruby/library/readline/readline_spec.rb
index 24d2cbbe86..6e349ad543 100644
--- a/spec/ruby/library/readline/readline_spec.rb
+++ b/spec/ruby/library/readline/readline_spec.rb
@@ -21,13 +21,6 @@ with_feature :readline do
ruby_exe('File.write ARGV[0], Readline.readline', @options)
File.read(@out).should == "test"
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned strings" do
- ruby_exe('File.write ARGV[0], Readline.readline.tainted?', @options)
- File.read(@out).should == "true"
- end
- end
end
end
end
diff --git a/spec/ruby/library/scanf/io/block_scanf_spec.rb b/spec/ruby/library/scanf/io/block_scanf_spec.rb
index b9cc1b507e..e15f14f95f 100644
--- a/spec/ruby/library/scanf/io/block_scanf_spec.rb
+++ b/spec/ruby/library/scanf/io/block_scanf_spec.rb
@@ -1,10 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require_relative 'shared/block_scanf'
- require 'scanf'
-
- describe "IO#block_scanf" do
- it_behaves_like :scanf_io_block_scanf, :block_scanf
- end
-end
diff --git a/spec/ruby/library/scanf/io/scanf_spec.rb b/spec/ruby/library/scanf/io/scanf_spec.rb
index 6a3e6d0d1a..e15f14f95f 100644
--- a/spec/ruby/library/scanf/io/scanf_spec.rb
+++ b/spec/ruby/library/scanf/io/scanf_spec.rb
@@ -1,38 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require_relative 'shared/block_scanf'
- require 'scanf'
-
- describe "IO#scanf" do
- before :each do
- @hw = File.open(fixture(__FILE__, 'helloworld.txt'), 'rb')
- @data = File.open(fixture(__FILE__, 'date.txt'), 'rb')
- end
-
- after :each do
- @hw.close unless @hw.closed?
- @data.close unless @data.closed?
- end
-
- it "returns an array containing the input converted in the specified type" do
- @hw.scanf("%s%s").should == ["hello", "world"]
- @data.scanf("%s%d").should == ["Beethoven", 1770]
- end
-
- it "returns an array containing the input converted in the specified type with given maximum field width" do
- @hw.scanf("%2s").should == ["he"]
- @data.scanf("%2c").should == ["Be"]
- end
-
- it "returns an empty array when a wrong specifier is passed" do
- @hw.scanf("%a").should == []
- @hw.scanf("%1").should == []
- @data.scanf("abc").should == []
- end
- end
-
- describe "IO#scanf with block" do
- it_behaves_like :scanf_io_block_scanf, :scanf
- end
-end
diff --git a/spec/ruby/library/scanf/string/block_scanf_spec.rb b/spec/ruby/library/scanf/string/block_scanf_spec.rb
index 277e1fa1d7..e15f14f95f 100644
--- a/spec/ruby/library/scanf/string/block_scanf_spec.rb
+++ b/spec/ruby/library/scanf/string/block_scanf_spec.rb
@@ -1,10 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require_relative 'shared/block_scanf'
- require 'scanf'
-
- describe "String#block_scanf" do
- it_behaves_like :scanf_string_block_scanf, :block_scanf
- end
-end
diff --git a/spec/ruby/library/scanf/string/scanf_spec.rb b/spec/ruby/library/scanf/string/scanf_spec.rb
index c8897db675..e15f14f95f 100644
--- a/spec/ruby/library/scanf/string/scanf_spec.rb
+++ b/spec/ruby/library/scanf/string/scanf_spec.rb
@@ -1,56 +1 @@
require_relative '../../../spec_helper'
-
-ruby_version_is ''...'2.7' do
- require_relative 'shared/block_scanf'
- require 'scanf'
-
- describe "String#scanf" do
- it "returns an array containing the input converted in the specified type" do
- "hello world".scanf("%s").should == ["hello"]
- "hello world".scanf("%s%d").should == ["hello"]
- "hello world".scanf("%s%c").should == ["hello", " "]
- "hello world".scanf("%c%s").should == ["h", "ello"]
- "hello world".scanf("%s%s").should == ["hello", "world"]
- "hello world".scanf("%c").should == ["h"]
- "123".scanf("%s").should == ["123"]
- "123".scanf("%c").should == ["1"]
- "123".scanf("%d").should == [123]
- "123".scanf("%u").should == [123]
- "123".scanf("%o").should == [83]
- "123".scanf("%x").should == [291]
- "123".scanf("%i").should == [123]
- "0123".scanf("%i").should == [83]
- "123".scanf("%f").should == [123.0]
- "0X123".scanf("%i").should == [291]
- "0x123".scanf("%i").should == [291]
- end
-
- it "returns an array containing the input converted in the specified type with given maximum field width" do
- "hello world".scanf("%2s").should == ["he"]
- "hello world".scanf("%2c").should == ["he"]
- "123".scanf("%2s").should == ["12"]
- "123".scanf("%2c").should == ["12"]
- "123".scanf("%2d").should == [12]
- "123".scanf("%2u").should == [12]
- "123".scanf("%2o").should == [10]
- "123".scanf("%2x").should == [18]
- "123".scanf("%2i").should == [12]
- "0123".scanf("%2i").should == [1]
- "123".scanf("%2f").should == [12.0]
- "0X123".scanf("%2i").should == [0]
- "0X123".scanf("%3i").should == [1]
- "0X123".scanf("%4i").should == [18]
- end
-
- it "returns an empty array when a wrong specifier is passed" do
- "hello world".scanf("%a").should == []
- "123".scanf("%1").should == []
- "123".scanf("abc").should == []
- "123".scanf(:d).should == []
- end
- end
-
- describe "String#scanf with block" do
- it_behaves_like :scanf_string_block_scanf, :scanf
- end
-end
diff --git a/spec/ruby/library/stringio/append_spec.rb b/spec/ruby/library/stringio/append_spec.rb
index d0cf5550cd..981229fc10 100644
--- a/spec/ruby/library/stringio/append_spec.rb
+++ b/spec/ruby/library/stringio/append_spec.rb
@@ -29,13 +29,6 @@ describe "StringIO#<< when passed [Object]" do
@io.string.should == "example\000\000\000\000\000\000\000\000just testing"
end
- ruby_version_is ""..."2.7" do
- it "taints self's String when the passed argument is tainted" do
- (@io << "test".taint)
- @io.string.tainted?.should be_true
- end
- end
-
ruby_version_is ""..."3.0" do
it "does not taint self when the passed argument is tainted" do
(@io << "test".taint)
diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb
index 6752cf9970..4863a5332b 100644
--- a/spec/ruby/library/stringio/reopen_spec.rb
+++ b/spec/ruby/library/stringio/reopen_spec.rb
@@ -206,14 +206,6 @@ describe "StringIO#reopen when passed [Object]" do
@io.reopen(obj)
@io.string.should == "to_strio"
end
-
- # NOTE: WEIRD!
- ruby_version_is ""..."2.7" do
- it "taints self when the passed Object was tainted" do
- @io.reopen(StringIO.new("reopened").taint)
- @io.tainted?.should be_true
- end
- end
end
describe "StringIO#reopen when passed no arguments" do
@@ -278,15 +270,6 @@ describe "StringIO#reopen" do
str.should == ''
end
- ruby_version_is ""..."2.7" do
- it "taints self if the provided StringIO argument is tainted" do
- new_io = StringIO.new("tainted")
- new_io.taint
- @io.reopen(new_io)
- @io.should.tainted?
- end
- end
-
it "does not truncate the content even when the StringIO argument is in the truncate mode" do
orig_io = StringIO.new("Original StringIO", IO::RDWR|IO::TRUNC)
orig_io.write("BLAH") # make sure the content is not empty
diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb
index 080729217b..0eb71466e3 100644
--- a/spec/ruby/library/stringio/shared/write.rb
+++ b/spec/ruby/library/stringio/shared/write.rb
@@ -45,13 +45,6 @@ describe :stringio_write_string, shared: true do
@io.pos.should eql(4)
end
- ruby_version_is ""..."2.7" do
- it "taints self's String when the passed argument is tainted" do
- @io.send(@method, "test".taint)
- @io.string.tainted?.should be_true
- end
- end
-
ruby_version_is ""..."3.0" do
it "does not taint self when the passed argument is tainted" do
@io.send(@method, "test".taint)
diff --git a/spec/ruby/library/stringscanner/check_spec.rb b/spec/ruby/library/stringscanner/check_spec.rb
index 21da785515..a97c26af83 100644
--- a/spec/ruby/library/stringscanner/check_spec.rb
+++ b/spec/ruby/library/stringscanner/check_spec.rb
@@ -14,14 +14,12 @@ describe "StringScanner#check" do
@s.matched.should == nil
end
- ruby_version_is "2.7" do
- it "treats String as the pattern itself" do
- @s.check("This").should == "This"
- @s.matched.should == "This"
- @s.pos.should == 0
- @s.check(/is/).should == nil
- @s.matched.should == nil
- end
+ it "treats String as the pattern itself" do
+ @s.check("This").should == "This"
+ @s.matched.should == "This"
+ @s.pos.should == 0
+ @s.check(/is/).should == nil
+ @s.matched.should == nil
end
end
diff --git a/spec/ruby/library/stringscanner/scan_spec.rb b/spec/ruby/library/stringscanner/scan_spec.rb
index 2269abd6b3..ea711767b9 100644
--- a/spec/ruby/library/stringscanner/scan_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_spec.rb
@@ -50,17 +50,9 @@ describe "StringScanner#scan" do
@s.scan(/./).should be_nil
end
- ruby_version_is ""..."2.7" do
- it "raises a TypeError if pattern is a String" do
- -> { @s.scan("aoeu") }.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.7" do
- it "treats String as the pattern itself" do
- @s.scan("this").should be_nil
- @s.scan("This").should == "This"
- end
+ it "treats String as the pattern itself" do
+ @s.scan("this").should be_nil
+ @s.scan("This").should == "This"
end
it "raises a TypeError if pattern isn't a Regexp nor String" do
@@ -75,23 +67,21 @@ describe "StringScanner#scan with fixed_anchor: true" do
@s = StringScanner.new("This\nis\na\ntest", fixed_anchor: true)
end
- ruby_version_is "2.7" do
- it "returns the matched string" do
- @s.scan(/\w+/).should == "This"
- @s.scan(/.../m).should == "\nis"
- @s.scan(//).should == ""
- @s.scan(/\s+/).should == "\n"
- end
+ it "returns the matched string" do
+ @s.scan(/\w+/).should == "This"
+ @s.scan(/.../m).should == "\nis"
+ @s.scan(//).should == ""
+ @s.scan(/\s+/).should == "\n"
+ end
- it "treats ^ as matching from the beginning of line" do
- @s.scan(/\w+\n/).should == "This\n"
- @s.scan(/^\w/).should == "i"
- @s.scan(/^\w/).should be_nil
- end
+ it "treats ^ as matching from the beginning of line" do
+ @s.scan(/\w+\n/).should == "This\n"
+ @s.scan(/^\w/).should == "i"
+ @s.scan(/^\w/).should be_nil
+ end
- it "treats \\A as matching from the beginning of string" do
- @s.scan(/\A\w/).should == "T"
- @s.scan(/\A\w/).should be_nil
- end
+ it "treats \\A as matching from the beginning of string" do
+ @s.scan(/\A\w/).should == "T"
+ @s.scan(/\A\w/).should be_nil
end
end
diff --git a/spec/ruby/library/stringscanner/shared/extract_range.rb b/spec/ruby/library/stringscanner/shared/extract_range.rb
index 1c14f716c9..e7404fd0cb 100644
--- a/spec/ruby/library/stringscanner/shared/extract_range.rb
+++ b/spec/ruby/library/stringscanner/shared/extract_range.rb
@@ -8,17 +8,4 @@ describe :extract_range, shared: true do
ch.should_not be_kind_of(cls)
ch.should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned String if the input was tainted" do
- str = 'abc'
- str.taint
-
- s = StringScanner.new(str)
-
- s.send(@method).tainted?.should be_true
- s.send(@method).tainted?.should be_true
- s.send(@method).tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb
index 5c536f5c01..070a132812 100644
--- a/spec/ruby/library/stringscanner/shared/extract_range_matched.rb
+++ b/spec/ruby/library/stringscanner/shared/extract_range_matched.rb
@@ -10,15 +10,4 @@ describe :extract_range_matched, shared: true do
ch.should_not be_kind_of(cls)
ch.should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned String if the input was tainted" do
- str = 'abc'
- str.taint
-
- s = StringScanner.new(str)
- s.scan(/\w{1}/)
- s.send(@method).tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/library/stringscanner/shared/peek.rb b/spec/ruby/library/stringscanner/shared/peek.rb
index 4e2e643353..4c757866c1 100644
--- a/spec/ruby/library/stringscanner/shared/peek.rb
+++ b/spec/ruby/library/stringscanner/shared/peek.rb
@@ -36,14 +36,4 @@ describe :strscan_peek, shared: true do
ch.should_not be_kind_of(cls)
ch.should be_an_instance_of(String)
end
-
- ruby_version_is ''...'2.7' do
- it "taints the returned String if the input was tainted" do
- str = 'abc'
- str.taint
-
- s = StringScanner.new(str)
- s.send(@method, 1).tainted?.should be_true
- end
- end
end
diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb
index 03ec4f6916..8e80b02cb4 100644
--- a/spec/ruby/library/yaml/to_yaml_spec.rb
+++ b/spec/ruby/library/yaml/to_yaml_spec.rb
@@ -72,16 +72,8 @@ describe "Object#to_yaml" do
true_klass.to_yaml.should match_yaml("--- true\n")
end
- ruby_version_is ""..."2.7" do
- it "returns the YAML representation of a Error object" do
- StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\n")
- end
- end
-
- ruby_version_is "2.7" do
- it "returns the YAML representation of a Error object" do
- StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\nbacktrace: \n")
- end
+ it "returns the YAML representation of a Error object" do
+ StandardError.new("foobar").to_yaml.should match_yaml("--- !ruby/exception:StandardError\nmessage: foobar\nbacktrace: \n")
end
it "returns the YAML representation for Range objects" do
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb
index 88545265d0..d1e3e03582 100644
--- a/spec/ruby/optional/capi/kernel_spec.rb
+++ b/spec/ruby/optional/capi/kernel_spec.rb
@@ -412,12 +412,10 @@ describe "C-API Kernel function" do
}.should raise_error(Exception, 'custom error')
end
- ruby_bug "#17305", ""..."2.7" do
- it "raises TypeError if one of the passed exceptions is not a Module" do
- -> {
- @s.rb_rescue2(-> *_ { raise RuntimeError, "foo" }, :no_exc, -> x { x }, :exc, Object.new, 42)
- }.should raise_error(TypeError, /class or module required/)
- end
+ it "raises TypeError if one of the passed exceptions is not a Module" do
+ -> {
+ @s.rb_rescue2(-> *_ { raise RuntimeError, "foo" }, :no_exc, -> x { x }, :exc, Object.new, 42)
+ }.should raise_error(TypeError, /class or module required/)
end
end
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index 8791a4bc76..294247910b 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -438,15 +438,6 @@ describe "CApiObject" do
end
describe "FL_TEST" do
- ruby_version_is ''...'2.7' do
- it "returns correct status for FL_TAINT" do
- obj = Object.new
- @o.FL_TEST(obj, "FL_TAINT").should == 0
- obj.taint
- @o.FL_TEST(obj, "FL_TAINT").should_not == 0
- end
- end
-
it "returns correct status for FL_FREEZE" do
obj = Object.new
@o.FL_TEST(obj, "FL_FREEZE").should == 0
@@ -636,68 +627,12 @@ describe "CApiObject" do
end
describe "OBJ_TAINT" do
- ruby_version_is ''...'2.7' do
- it "taints the object" do
- obj = mock("tainted")
- @o.OBJ_TAINT(obj)
- obj.tainted?.should be_true
- end
- end
end
describe "OBJ_TAINTED" do
- ruby_version_is ''...'2.7' do
- it "returns C true if the object is tainted" do
- obj = mock("tainted")
- obj.taint
- @o.OBJ_TAINTED(obj).should be_true
- end
-
- it "returns C false if the object is not tainted" do
- obj = mock("untainted")
- @o.OBJ_TAINTED(obj).should be_false
- end
- end
end
describe "OBJ_INFECT" do
- ruby_version_is ''...'2.7' do
- it "does not taint the first argument if the second argument is not tainted" do
- host = mock("host")
- source = mock("source")
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_false
- end
-
- it "taints the first argument if the second argument is tainted" do
- host = mock("host")
- source = mock("source").taint
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_true
- end
-
- it "does not untrust the first argument if the second argument is trusted" do
- host = mock("host")
- source = mock("source")
- @o.OBJ_INFECT(host, source)
- host.untrusted?.should be_false
- end
-
- it "untrusts the first argument if the second argument is untrusted" do
- host = mock("host")
- source = mock("source").untrust
- @o.OBJ_INFECT(host, source)
- host.untrusted?.should be_true
- end
-
- it "propagates both taint and distrust" do
- host = mock("host")
- source = mock("source").taint.untrust
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_true
- host.untrusted?.should be_true
- end
- end
end
describe "rb_obj_freeze" do
@@ -731,18 +666,6 @@ describe "CApiObject" do
end
describe "rb_obj_taint" do
- ruby_version_is ''...'2.7' do
- it "marks the object passed as tainted" do
- obj = ""
- obj.should_not.tainted?
- @o.rb_obj_taint(obj)
- obj.should.tainted?
- end
-
- it "raises a FrozenError if the object passed is frozen" do
- -> { @o.rb_obj_taint("".freeze) }.should raise_error(FrozenError)
- end
- end
end
describe "rb_check_frozen" do
diff --git a/spec/ruby/optional/capi/proc_spec.rb b/spec/ruby/optional/capi/proc_spec.rb
index dab143fbe7..c839665ae9 100644
--- a/spec/ruby/optional/capi/proc_spec.rb
+++ b/spec/ruby/optional/capi/proc_spec.rb
@@ -115,20 +115,6 @@ describe "C-API when calling Proc.new from a C function" do
# For example: C -> Ruby <- C -> Ruby means a C function called into Ruby
# code which returned to C, then C called into Ruby code again.
- ruby_version_is ""..."2.7" do
- # Ruby -> C -> rb_funcall(Proc.new)
- it "returns the Proc passed by the Ruby code calling the C function" do
- prc = @p.rb_Proc_new(0) { :called }
- prc.call.should == :called
- end
-
- # Ruby -> C -> Ruby <- C -> rb_funcall(Proc.new)
- it "returns the Proc passed to the Ruby method when the C function calls other Ruby methods before calling Proc.new" do
- prc = @p.rb_Proc_new(1) { :called }
- prc.call.should == :called
- end
- end
-
# Ruby -> C -> Ruby -> Proc.new
it "raises an ArgumentError when the C function calls a Ruby method that calls Proc.new" do
-> {
@@ -142,20 +128,6 @@ describe "C-API when calling Proc.new from a C function" do
-> { @p.rb_Proc_new(3) { :called } }.should raise_error(ArgumentError)
end
- ruby_version_is ""..."2.7" do
- # Ruby -> C -> Ruby -> C (with new block) -> rb_funcall(Proc.new)
- it "returns the most recent Proc passed when the Ruby method called the C function" do
- prc = @p.rb_Proc_new(4) { :called }
- prc.call.should == :calling_with_block
- end
-
- # Ruby -> C -> Ruby -> C (with new block) <- Ruby <- C -> # rb_funcall(Proc.new)
- it "returns the Proc passed from the original Ruby call to the C function" do
- prc = @p.rb_Proc_new(5) { :called }
- prc.call.should == :called
- end
- end
-
# Ruby -> C -> Ruby -> block_given?
it "returns false from block_given? in a Ruby method called by the C function" do
@p.rb_Proc_new(6).should be_false
diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb
index 5ef63e81e3..99c2044bd7 100644
--- a/spec/ruby/optional/capi/shared/rbasic.rb
+++ b/spec/ruby/optional/capi/shared/rbasic.rb
@@ -20,40 +20,6 @@ describe :rbasic, shared: true do
obj.should.frozen?
end
- ruby_version_is ""..."2.7" do
- it "reports the appropriate FREEZE and TAINT flags for the object when reading" do
- obj, _ = @data.call
- initial = @specs.get_flags(obj)
- obj.taint
- @specs.get_flags(obj).should == @taint | initial
- obj.untaint
- @specs.get_flags(obj).should == initial
- obj.freeze
- @specs.get_flags(obj).should == @freeze | initial
-
- obj, _ = @data.call
- obj.taint
- obj.freeze
- @specs.get_flags(obj).should == @freeze | @taint | initial
- end
-
- it "supports setting the FREEZE and TAINT flags" do
- obj, _ = @data.call
- initial = @specs.get_flags(obj)
- @specs.set_flags(obj, @taint | initial).should == @taint | initial
- obj.should.tainted?
- @specs.set_flags(obj, initial).should == initial
- obj.should_not.tainted?
- @specs.set_flags(obj, @freeze | initial).should == @freeze | initial
- obj.should.frozen?
-
- obj, _ = @data.call
- @specs.set_flags(obj, @freeze | @taint | initial).should == @freeze | @taint | initial
- obj.should.tainted?
- obj.should.frozen?
- end
- end
-
it "supports retrieving the (meta)class" do
obj, _ = @data.call
@specs.get_klass(obj).should == obj.class
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 9291630ace..7ad4d10ee4 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -181,12 +181,6 @@ describe "C-API String function" do
@s.rb_str_new("hello", 3).should == "hel"
end
- ruby_version_is ''...'2.7' do
- it "returns a non-tainted string" do
- @s.rb_str_new("hello", 5).should_not.tainted?
- end
- end
-
it "returns an empty string if len is 0" do
@s.rb_str_new("hello", 0).should == ""
end
@@ -335,24 +329,6 @@ describe "C-API String function" do
end
end
- ruby_version_is ''...'2.7' do
- describe "rb_tainted_str_new" do
- it "creates a new tainted String" do
- newstring = @s.rb_tainted_str_new("test", 4)
- newstring.should == "test"
- newstring.tainted?.should be_true
- end
- end
-
- describe "rb_tainted_str_new2" do
- it "creates a new tainted String" do
- newstring = @s.rb_tainted_str_new2("test")
- newstring.should == "test"
- newstring.tainted?.should be_true
- end
- end
- end
-
describe "rb_str_append" do
it "appends a string to another string" do
@s.rb_str_append("Hello", " Goodbye").should == "Hello Goodbye"
@@ -665,22 +641,6 @@ describe "C-API String function" do
end
describe "SafeStringValue" do
- ruby_version_is ''...'2.7' do
- it "raises for tained string when $SAFE is 1" do
- begin
- Thread.new {
- $SAFE = 1
- -> {
- @s.SafeStringValue("str".taint)
- }.should raise_error(SecurityError)
- }.join
- ensure
- $SAFE = 0
- end
- end
-
- it_behaves_like :string_value_macro, :SafeStringValue
- end
end
describe "rb_str_modify" do
@@ -810,12 +770,6 @@ describe :rb_external_str_new, shared: true do
x80 = [0x80].pack('C')
@s.send(@method, "#{x80}abc").encoding.should == Encoding::BINARY
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted String" do
- @s.send(@method, "abc").tainted?.should be_true
- end
- end
end
describe "C-API String function" do
@@ -895,13 +849,6 @@ describe "C-API String function" do
s.should == x
s.encoding.should equal(Encoding::EUC_JP)
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted String" do
- s = @s.rb_external_str_new_with_enc("abc", 3, Encoding::US_ASCII)
- s.tainted?.should be_true
- end
- end
end
describe "rb_locale_str_new" do
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb
index a90c28a78e..64b0894087 100644
--- a/spec/ruby/optional/capi/util_spec.rb
+++ b/spec/ruby/optional/capi/util_spec.rb
@@ -11,7 +11,6 @@ describe "C-API Util function" do
before :each do
@prc = -> { 1 }
@acc = []
- @keyword_prefix = 'k' if RUBY_VERSION >= '2.7'
ScratchPad.record @acc
end
@@ -100,13 +99,13 @@ describe "C-API Util function" do
it "assigns Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0
+ @o.rb_scan_args([h], "k0:", 1, @acc).should == 0
ScratchPad.recorded.should == [h]
end
it "assigns required and Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1
+ @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1
ScratchPad.recorded.should == [1, h]
end
@@ -140,7 +139,7 @@ describe "C-API Util function" do
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], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5
ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc]
end
@@ -150,7 +149,7 @@ describe "C-API Util function" do
h = {1 => 2, 3 => 4}
-> {
suppress_warning do
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc)
+ @o.rb_scan_args([h], "k0:", 1, @acc)
end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
@@ -160,7 +159,7 @@ describe "C-API Util function" do
h = {1 => 2, 3 => 4}
-> {
suppress_warning do
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc)
+ @o.rb_scan_args([1, h], "k1:", 2, @acc)
end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
@@ -169,7 +168,7 @@ describe "C-API Util function" do
it "considers the hash as a post argument when there is a splat" do
h = {1 => 2, 3 => 4}
suppress_warning do
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 6
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 6
end
ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc]
end
@@ -178,19 +177,19 @@ describe "C-API Util function" do
ruby_version_is '3.0' do
it "does not reject non-symbol keys in keyword arguments" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0
+ @o.rb_scan_args([h], "k0:", 1, @acc).should == 0
ScratchPad.recorded.should == [h]
end
it "does not reject non-symbol keys in keyword arguments with required argument" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1
+ @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1
ScratchPad.recorded.should == [1, h]
end
it "considers keyword arguments with non-symbol keys as keywords when using splat and post arguments" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5
ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc]
end
end
diff --git a/spec/ruby/security/cve_2018_16396_spec.rb b/spec/ruby/security/cve_2018_16396_spec.rb
index c9624e9c63..6f8a5d2f5d 100644
--- a/spec/ruby/security/cve_2018_16396_spec.rb
+++ b/spec/ruby/security/cve_2018_16396_spec.rb
@@ -1,21 +1,7 @@
require_relative '../spec_helper'
describe "Array#pack" do
- ruby_version_is ''...'2.7' do
- it "resists CVE-2018-16396 by tainting output based on input" do
- "aAZBbHhuMmPp".each_char do |f|
- ["123456".taint].pack(f).tainted?.should be_true
- end
- end
- end
end
describe "String#unpack" do
- ruby_version_is ''...'2.7' do
- it "resists CVE-2018-16396 by tainting output based on input" do
- "aAZBbHhuMm".each_char do |f|
- "123456".taint.unpack(f).first.tainted?.should be_true
- end
- end
- end
end
diff --git a/spec/ruby/security/cve_2019_8321_spec.rb b/spec/ruby/security/cve_2019_8321_spec.rb
index 84cd10ced1..a8a86e7d97 100644
--- a/spec/ruby/security/cve_2019_8321_spec.rb
+++ b/spec/ruby/security/cve_2019_8321_spec.rb
@@ -1,22 +1,20 @@
require_relative '../spec_helper'
-guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
- require 'rubygems'
- require 'rubygems/user_interaction'
+require 'rubygems'
+require 'rubygems/user_interaction'
- describe "CVE-2019-8321 is resisted by" do
- it "sanitising verbose messages" do
- ui = Class.new {
- include Gem::UserInteraction
- }.new
- ui.should_receive(:say).with(".]2;nyan.")
- verbose_before = Gem.configuration.verbose
- begin
- Gem.configuration.verbose = :really_verbose
- ui.verbose("\e]2;nyan\a")
- ensure
- Gem.configuration.verbose = verbose_before
- end
+describe "CVE-2019-8321 is resisted by" do
+ it "sanitising verbose messages" do
+ ui = Class.new {
+ include Gem::UserInteraction
+ }.new
+ ui.should_receive(:say).with(".]2;nyan.")
+ verbose_before = Gem.configuration.verbose
+ begin
+ Gem.configuration.verbose = :really_verbose
+ ui.verbose("\e]2;nyan\a")
+ ensure
+ Gem.configuration.verbose = verbose_before
end
end
end
diff --git a/spec/ruby/security/cve_2019_8322_spec.rb b/spec/ruby/security/cve_2019_8322_spec.rb
index 6f996572c5..b70d78c033 100644
--- a/spec/ruby/security/cve_2019_8322_spec.rb
+++ b/spec/ruby/security/cve_2019_8322_spec.rb
@@ -1,23 +1,21 @@
require_relative '../spec_helper'
-guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
- require 'yaml'
- require 'rubygems'
- require 'rubygems/safe_yaml'
- require 'rubygems/commands/owner_command'
+require 'yaml'
+require 'rubygems'
+require 'rubygems/safe_yaml'
+require 'rubygems/commands/owner_command'
- describe "CVE-2019-8322 is resisted by" do
- it "sanitising owner names" do
- command = Gem::Commands::OwnerCommand.new
- def command.rubygems_api_request(*args)
- Struct.new(:body).new("---\n- email: \"\e]2;nyan\a\"\n handle: handle\n id: id\n")
- end
- def command.with_response(response)
- yield response
- end
- command.should_receive(:say).with("Owners for gem: name")
- command.should_receive(:say).with("- .]2;nyan.")
- command.show_owners "name"
+describe "CVE-2019-8322 is resisted by" do
+ it "sanitising owner names" do
+ command = Gem::Commands::OwnerCommand.new
+ def command.rubygems_api_request(*args)
+ Struct.new(:body).new("---\n- email: \"\e]2;nyan\a\"\n handle: handle\n id: id\n")
end
+ def command.with_response(response)
+ yield response
+ end
+ command.should_receive(:say).with("Owners for gem: name")
+ command.should_receive(:say).with("- .]2;nyan.")
+ command.show_owners "name"
end
end
diff --git a/spec/ruby/security/cve_2019_8323_spec.rb b/spec/ruby/security/cve_2019_8323_spec.rb
index c98aae9021..d4606de054 100644
--- a/spec/ruby/security/cve_2019_8323_spec.rb
+++ b/spec/ruby/security/cve_2019_8323_spec.rb
@@ -1,38 +1,36 @@
require_relative '../spec_helper'
-guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
- require 'optparse'
+require 'optparse'
- require 'rubygems'
- require 'rubygems/gemcutter_utilities'
+require 'rubygems'
+require 'rubygems/gemcutter_utilities'
- describe "CVE-2019-8323 is resisted by" do
- describe "sanitising the body" do
- it "for success codes" do
- cutter = Class.new {
- include Gem::GemcutterUtilities
- }.new
- response = Net::HTTPSuccess.new(nil, nil, nil)
- def response.body
- "\e]2;nyan\a"
- end
- cutter.should_receive(:say).with(".]2;nyan.")
- cutter.with_response response
+describe "CVE-2019-8323 is resisted by" do
+ describe "sanitising the body" do
+ it "for success codes" do
+ cutter = Class.new {
+ include Gem::GemcutterUtilities
+ }.new
+ response = Net::HTTPSuccess.new(nil, nil, nil)
+ def response.body
+ "\e]2;nyan\a"
end
+ cutter.should_receive(:say).with(".]2;nyan.")
+ cutter.with_response response
+ end
- it "for error codes" do
- cutter = Class.new {
- include Gem::GemcutterUtilities
- }.new
- def cutter.terminate_interaction(n)
- end
- response = Net::HTTPNotFound.new(nil, nil, nil)
- def response.body
- "\e]2;nyan\a"
- end
- cutter.should_receive(:say).with(".]2;nyan.")
- cutter.with_response response
+ it "for error codes" do
+ cutter = Class.new {
+ include Gem::GemcutterUtilities
+ }.new
+ def cutter.terminate_interaction(n)
+ end
+ response = Net::HTTPNotFound.new(nil, nil, nil)
+ def response.body
+ "\e]2;nyan\a"
end
+ cutter.should_receive(:say).with(".]2;nyan.")
+ cutter.with_response response
end
end
end
diff --git a/spec/ruby/security/cve_2019_8325_spec.rb b/spec/ruby/security/cve_2019_8325_spec.rb
index c8978e00e5..04692e01fe 100644
--- a/spec/ruby/security/cve_2019_8325_spec.rb
+++ b/spec/ruby/security/cve_2019_8325_spec.rb
@@ -1,38 +1,36 @@
require_relative '../spec_helper'
-guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
- require 'rubygems'
- require 'rubygems/command_manager'
+require 'rubygems'
+require 'rubygems/command_manager'
- describe "CVE-2019-8325 is resisted by" do
- describe "sanitising error message components" do
- it "for the 'while executing' message" do
- manager = Gem::CommandManager.new
- def manager.process_args(args, build_args)
- raise StandardError, "\e]2;nyan\a"
- end
- def manager.terminate_interaction(n)
- end
- manager.should_receive(:alert_error).with("While executing gem ... (StandardError)\n .]2;nyan.")
- manager.run nil, nil
+describe "CVE-2019-8325 is resisted by" do
+ describe "sanitising error message components" do
+ it "for the 'while executing' message" do
+ manager = Gem::CommandManager.new
+ def manager.process_args(args, build_args)
+ raise StandardError, "\e]2;nyan\a"
end
+ def manager.terminate_interaction(n)
+ end
+ manager.should_receive(:alert_error).with("While executing gem ... (StandardError)\n .]2;nyan.")
+ manager.run nil, nil
+ end
- it "for the 'invalid option' message" do
- manager = Gem::CommandManager.new
- def manager.terminate_interaction(n)
- end
- manager.should_receive(:alert_error).with("Invalid option: --.]2;nyan.. See 'gem --help'.")
- manager.process_args ["--\e]2;nyan\a"], nil
+ it "for the 'invalid option' message" do
+ manager = Gem::CommandManager.new
+ def manager.terminate_interaction(n)
end
+ manager.should_receive(:alert_error).with("Invalid option: --.]2;nyan.. See 'gem --help'.")
+ manager.process_args ["--\e]2;nyan\a"], nil
+ end
- it "for the 'loading command' message" do
- manager = Gem::CommandManager.new
- def manager.require(x)
- raise 'foo'
- end
- manager.should_receive(:alert_error).with("Loading command: .]2;nyan. (RuntimeError)\n\tfoo")
- manager.send :load_and_instantiate, "\e]2;nyan\a"
+ it "for the 'loading command' message" do
+ manager = Gem::CommandManager.new
+ def manager.require(x)
+ raise 'foo'
end
+ manager.should_receive(:alert_error).with("Loading command: .]2;nyan. (RuntimeError)\n\tfoo")
+ manager.send :load_and_instantiate, "\e]2;nyan\a"
end
end
end
diff --git a/spec/ruby/security/cve_2020_10663_spec.rb b/spec/ruby/security/cve_2020_10663_spec.rb
index 159fdc0cb4..cce1beb012 100644
--- a/spec/ruby/security/cve_2020_10663_spec.rb
+++ b/spec/ruby/security/cve_2020_10663_spec.rb
@@ -18,25 +18,22 @@ module JSONSpecs
end
guard -> {
- ruby_version_is "2.6.6" or
JSON.const_defined?(:Pure) or
version_is(JSON::VERSION, '2.3.0')
} do
- guard_not -> { platform_is :darwin and ENV['GITHUB_ACTIONS'] } do # frequent timeout/hang on macOS in GitHub Actions
- describe "CVE-2020-10663 is resisted by" do
- it "only creating custom objects if passed create_additions: true or using JSON.load" do
- obj = JSONSpecs::MyClass.new("bar")
- JSONSpecs::MyClass.should.json_creatable?
- json = JSON.dump(obj)
+ describe "CVE-2020-10663 is resisted by" do
+ it "only creating custom objects if passed create_additions: true or using JSON.load" do
+ obj = JSONSpecs::MyClass.new("bar")
+ JSONSpecs::MyClass.should.json_creatable?
+ json = JSON.dump(obj)
- JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass
- JSON(json, create_additions: true).class.should == JSONSpecs::MyClass
- JSON.load(json).class.should == JSONSpecs::MyClass
+ JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass
+ JSON(json, create_additions: true).class.should == JSONSpecs::MyClass
+ JSON.load(json).class.should == JSONSpecs::MyClass
- JSON.parse(json).class.should == Hash
- JSON.parse(json, nil).class.should == Hash
- JSON(json).class.should == Hash
- end
+ JSON.parse(json).class.should == Hash
+ JSON.parse(json, nil).class.should == Hash
+ JSON(json).class.should == Hash
end
end
end
diff --git a/spec/ruby/shared/rational/to_f.rb b/spec/ruby/shared/rational/to_f.rb
index 56e0b61d68..472a585daa 100644
--- a/spec/ruby/shared/rational/to_f.rb
+++ b/spec/ruby/shared/rational/to_f.rb
@@ -7,4 +7,10 @@ describe :rational_to_f, shared: true do
Rational(-1, 4).to_f.should eql(-0.25)
Rational(-1, -4).to_f.should eql(0.25)
end
+
+ it "converts to a Float for large numerator and denominator" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ Rational(num, den).to_f.should == 500.0
+ end
end
diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb
index cd4edf5340..8ca9507570 100644
--- a/spec/ruby/shared/string/times.rb
+++ b/spec/ruby/shared/string/times.rb
@@ -48,18 +48,6 @@ describe :string_times, shared: true do
end
end
- ruby_version_is ''...'2.7' do
- it "always taints the result when self is tainted" do
- ["", "OK", MyString.new(""), MyString.new("OK")].each do |str|
- str.taint
-
- [0, 1, 2].each do |arg|
- @object.call(str, arg).should.tainted?
- end
- end
- end
- end
-
it "returns a String in the same encoding as self" do
str = "\xE3\x81\x82".force_encoding Encoding::UTF_8
result = @object.call(str, 2)