summaryrefslogtreecommitdiff
path: root/spec/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby')
-rw-r--r--spec/ruby/.rubocop.yml3
-rw-r--r--spec/ruby/.rubocop_todo.yml1
-rw-r--r--spec/ruby/README.md7
-rwxr-xr-xspec/ruby/command_line/dash_0_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_v_spec.rb2
-rw-r--r--spec/ruby/command_line/feature_spec.rb2
-rw-r--r--spec/ruby/command_line/frozen_strings_spec.rb24
-rw-r--r--spec/ruby/command_line/rubyopt_spec.rb4
-rw-r--r--spec/ruby/core/array/fetch_values_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/a_spec.rb6
-rw-r--r--spec/ruby/core/array/pack/at_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/b_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/c_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/comment_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/h_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/m_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/basic.rb21
-rw-r--r--spec/ruby/core/array/pack/shared/float.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/integer.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/string.rb2
-rw-r--r--spec/ruby/core/array/pack/u_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/w_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/x_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/z_spec.rb4
-rw-r--r--spec/ruby/core/array/shared/slice.rb184
-rw-r--r--spec/ruby/core/array/shared/unshift.rb2
-rw-r--r--spec/ruby/core/builtin_constants/builtin_constants_spec.rb74
-rw-r--r--spec/ruby/core/class/attached_object_spec.rb40
-rw-r--r--spec/ruby/core/class/inherited_spec.rb17
-rw-r--r--spec/ruby/core/comparable/clamp_spec.rb149
-rw-r--r--spec/ruby/core/comparable/fixtures/classes.rb1
-rw-r--r--spec/ruby/core/complex/polar_spec.rb24
-rw-r--r--spec/ruby/core/data/constants_spec.rb20
-rw-r--r--spec/ruby/core/data/deconstruct_keys_spec.rb227
-rw-r--r--spec/ruby/core/data/deconstruct_spec.rb8
-rw-r--r--spec/ruby/core/data/define_spec.rb48
-rw-r--r--spec/ruby/core/data/eql_spec.rb92
-rw-r--r--spec/ruby/core/data/equal_value_spec.rb92
-rw-r--r--spec/ruby/core/data/fixtures/classes.rb23
-rw-r--r--spec/ruby/core/data/hash_spec.rb36
-rw-r--r--spec/ruby/core/data/initialize_spec.rb145
-rw-r--r--spec/ruby/core/data/inspect_spec.rb6
-rw-r--r--spec/ruby/core/data/members_spec.rb26
-rw-r--r--spec/ruby/core/data/shared/inspect.rb8
-rw-r--r--spec/ruby/core/data/to_h_spec.rb94
-rw-r--r--spec/ruby/core/data/to_s_spec.rb6
-rw-r--r--spec/ruby/core/data/with_spec.rb66
-rw-r--r--spec/ruby/core/dir/chdir_spec.rb2
-rw-r--r--spec/ruby/core/dir/close_spec.rb6
-rw-r--r--spec/ruby/core/dir/exist_spec.rb8
-rw-r--r--spec/ruby/core/dir/fchdir_spec.rb4
-rw-r--r--spec/ruby/core/dir/fixtures/common.rb10
-rw-r--r--spec/ruby/core/dir/for_fd_spec.rb4
-rw-r--r--spec/ruby/core/dir/home_spec.rb38
-rw-r--r--spec/ruby/core/encoding/compatible_spec.rb4
-rw-r--r--spec/ruby/core/encoding/converter/convert_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/last_error_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/new_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/primitive_convert_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/putback_spec.rb2
-rw-r--r--spec/ruby/core/encoding/find_spec.rb2
-rw-r--r--spec/ruby/core/encoding/fixtures/classes.rb2
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb2
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb2
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb2
-rw-r--r--spec/ruby/core/encoding/replicate_spec.rb4
-rw-r--r--spec/ruby/core/enumerable/filter_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/fixtures/classes.rb7
-rw-r--r--spec/ruby/core/enumerable/shared/inject.rb10
-rw-r--r--spec/ruby/core/enumerable/to_set_spec.rb33
-rw-r--r--spec/ruby/core/enumerator/product/each_spec.rb108
-rw-r--r--spec/ruby/core/enumerator/product/initialize_copy_spec.rb74
-rw-r--r--spec/ruby/core/enumerator/product/initialize_spec.rb44
-rw-r--r--spec/ruby/core/enumerator/product/inspect_spec.rb28
-rw-r--r--spec/ruby/core/enumerator/product/rewind_spec.rb90
-rw-r--r--spec/ruby/core/enumerator/product/size_spec.rb102
-rw-r--r--spec/ruby/core/enumerator/product_spec.rb138
-rw-r--r--spec/ruby/core/env/clone_spec.rb10
-rw-r--r--spec/ruby/core/env/element_reference_spec.rb2
-rw-r--r--spec/ruby/core/env/shared/update.rb10
-rw-r--r--spec/ruby/core/exception/detailed_message_spec.rb70
-rw-r--r--spec/ruby/core/exception/frozen_error_spec.rb16
-rw-r--r--spec/ruby/core/exception/full_message_spec.rb78
-rw-r--r--spec/ruby/core/exception/set_backtrace_spec.rb71
-rw-r--r--spec/ruby/core/exception/shared/set_backtrace.rb64
-rw-r--r--spec/ruby/core/exception/syntax_error_spec.rb36
-rw-r--r--spec/ruby/core/fiber/blocking_spec.rb20
-rw-r--r--spec/ruby/core/fiber/fixtures/classes.rb16
-rw-r--r--spec/ruby/core/fiber/fixtures/scheduler.rb35
-rw-r--r--spec/ruby/core/fiber/raise_spec.rb1
-rw-r--r--spec/ruby/core/fiber/scheduler_spec.rb8
-rw-r--r--spec/ruby/core/fiber/set_scheduler_spec.rb8
-rw-r--r--spec/ruby/core/fiber/shared/scheduler.rb51
-rw-r--r--spec/ruby/core/fiber/storage_spec.rb266
-rw-r--r--spec/ruby/core/file/birthtime_spec.rb62
-rw-r--r--spec/ruby/core/file/exist_spec.rb8
-rw-r--r--spec/ruby/core/file/path_spec.rb41
-rw-r--r--spec/ruby/core/file/socket_spec.rb32
-rw-r--r--spec/ruby/core/file/stat/birthtime_spec.rb34
-rw-r--r--spec/ruby/core/filetest/exist_spec.rb8
-rw-r--r--spec/ruby/core/filetest/socket_spec.rb4
-rw-r--r--spec/ruby/core/gc/config_spec.rb83
-rw-r--r--spec/ruby/core/hash/compact_spec.rb2
-rw-r--r--spec/ruby/core/hash/constructor_spec.rb11
-rw-r--r--spec/ruby/core/hash/except_spec.rb28
-rw-r--r--spec/ruby/core/hash/invert_spec.rb21
-rw-r--r--spec/ruby/core/hash/merge_spec.rb23
-rw-r--r--spec/ruby/core/hash/reject_spec.rb21
-rw-r--r--spec/ruby/core/hash/replace_spec.rb53
-rw-r--r--spec/ruby/core/hash/shared/select.rb21
-rw-r--r--spec/ruby/core/hash/shared/to_s.rb6
-rw-r--r--spec/ruby/core/hash/shift_spec.rb41
-rw-r--r--spec/ruby/core/hash/slice_spec.rb21
-rw-r--r--spec/ruby/core/hash/to_h_spec.rb28
-rw-r--r--spec/ruby/core/hash/transform_keys_spec.rb21
-rw-r--r--spec/ruby/core/hash/transform_values_spec.rb21
-rw-r--r--spec/ruby/core/integer/ceildiv_spec.rb26
-rw-r--r--spec/ruby/core/integer/constants_spec.rb36
-rw-r--r--spec/ruby/core/integer/divide_spec.rb17
-rw-r--r--spec/ruby/core/integer/left_shift_spec.rb6
-rw-r--r--spec/ruby/core/integer/minus_spec.rb17
-rw-r--r--spec/ruby/core/integer/plus_spec.rb17
-rw-r--r--spec/ruby/core/integer/right_shift_spec.rb6
-rw-r--r--spec/ruby/core/integer/shared/modulo.rb46
-rw-r--r--spec/ruby/core/io/binread_spec.rb2
-rw-r--r--spec/ruby/core/io/buffer/empty_spec.rb29
-rw-r--r--spec/ruby/core/io/buffer/external_spec.rb108
-rw-r--r--spec/ruby/core/io/buffer/free_spec.rb104
-rw-r--r--spec/ruby/core/io/buffer/initialize_spec.rb103
-rw-r--r--spec/ruby/core/io/buffer/internal_spec.rb108
-rw-r--r--spec/ruby/core/io/buffer/locked_spec.rb75
-rw-r--r--spec/ruby/core/io/buffer/mapped_spec.rb108
-rw-r--r--spec/ruby/core/io/buffer/null_spec.rb29
-rw-r--r--spec/ruby/core/io/buffer/private_spec.rb111
-rw-r--r--spec/ruby/core/io/buffer/readonly_spec.rb143
-rw-r--r--spec/ruby/core/io/buffer/resize_spec.rb155
-rw-r--r--spec/ruby/core/io/buffer/shared/null_and_empty.rb59
-rw-r--r--spec/ruby/core/io/buffer/shared_spec.rb117
-rw-r--r--spec/ruby/core/io/buffer/transfer_spec.rb118
-rw-r--r--spec/ruby/core/io/buffer/valid_spec.rb110
-rw-r--r--spec/ruby/core/io/foreach_spec.rb46
-rw-r--r--spec/ruby/core/io/path_spec.rb14
-rw-r--r--spec/ruby/core/io/popen_spec.rb16
-rw-r--r--spec/ruby/core/io/read_spec.rb110
-rw-r--r--spec/ruby/core/io/readlines_spec.rb62
-rw-r--r--spec/ruby/core/io/readpartial_spec.rb7
-rw-r--r--spec/ruby/core/io/shared/each.rb18
-rw-r--r--spec/ruby/core/io/shared/gets_ascii.rb2
-rw-r--r--spec/ruby/core/io/shared/new.rb23
-rw-r--r--spec/ruby/core/io/sysread_spec.rb6
-rw-r--r--spec/ruby/core/io/write_spec.rb2
-rw-r--r--spec/ruby/core/kernel/Float_spec.rb134
-rw-r--r--spec/ruby/core/kernel/Rational_spec.rb98
-rw-r--r--spec/ruby/core/kernel/autoload_spec.rb5
-rw-r--r--spec/ruby/core/kernel/caller_locations_spec.rb14
-rw-r--r--spec/ruby/core/kernel/caller_spec.rb25
-rw-r--r--spec/ruby/core/kernel/eval_spec.rb69
-rw-r--r--spec/ruby/core/kernel/inspect_spec.rb59
-rw-r--r--spec/ruby/core/kernel/match_spec.rb27
-rw-r--r--spec/ruby/core/kernel/not_match_spec.rb14
-rw-r--r--spec/ruby/core/kernel/open_spec.rb96
-rw-r--r--spec/ruby/core/kernel/raise_spec.rb221
-rw-r--r--spec/ruby/core/kernel/require_spec.rb13
-rw-r--r--spec/ruby/core/kernel/shared/require.rb30
-rw-r--r--spec/ruby/core/kernel/shared/sprintf.rb36
-rw-r--r--spec/ruby/core/kernel/singleton_method_spec.rb46
-rw-r--r--spec/ruby/core/kernel/sleep_spec.rb35
-rw-r--r--spec/ruby/core/kernel/sprintf_spec.rb36
-rw-r--r--spec/ruby/core/kernel/taint_spec.rb23
-rw-r--r--spec/ruby/core/kernel/tainted_spec.rb25
-rw-r--r--spec/ruby/core/kernel/trust_spec.rb24
-rw-r--r--spec/ruby/core/kernel/untaint_spec.rb24
-rw-r--r--spec/ruby/core/kernel/untrust_spec.rb23
-rw-r--r--spec/ruby/core/kernel/untrusted_spec.rb24
-rw-r--r--spec/ruby/core/kernel/warn_spec.rb6
-rw-r--r--spec/ruby/core/main/using_spec.rb10
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb67
-rw-r--r--spec/ruby/core/marshal/fixtures/marshal_data.rb20
-rw-r--r--spec/ruby/core/marshal/shared/load.rb42
-rw-r--r--spec/ruby/core/matchdata/bytebegin_spec.rb132
-rw-r--r--spec/ruby/core/matchdata/byteend_spec.rb104
-rw-r--r--spec/ruby/core/matchdata/byteoffset_spec.rb132
-rw-r--r--spec/ruby/core/matchdata/deconstruct_keys_spec.rb86
-rw-r--r--spec/ruby/core/matchdata/deconstruct_spec.rb4
-rw-r--r--spec/ruby/core/matchdata/offset_spec.rb106
-rw-r--r--spec/ruby/core/math/expm1_spec.rb37
-rw-r--r--spec/ruby/core/math/lgamma_spec.rb11
-rw-r--r--spec/ruby/core/math/log1p_spec.rb49
-rw-r--r--spec/ruby/core/method/owner_spec.rb6
-rw-r--r--spec/ruby/core/method/parameters_spec.rb26
-rw-r--r--spec/ruby/core/method/private_spec.rb25
-rw-r--r--spec/ruby/core/method/protected_spec.rb25
-rw-r--r--spec/ruby/core/method/public_spec.rb25
-rw-r--r--spec/ruby/core/method/source_location_spec.rb4
-rw-r--r--spec/ruby/core/method/unbind_spec.rb12
-rw-r--r--spec/ruby/core/module/ancestors_spec.rb15
-rw-r--r--spec/ruby/core/module/autoload_spec.rb63
-rw-r--r--spec/ruby/core/module/const_added_spec.rb305
-rw-r--r--spec/ruby/core/module/const_source_location_spec.rb10
-rw-r--r--spec/ruby/core/module/fixtures/classes.rb2
-rw-r--r--spec/ruby/core/module/include_spec.rb28
-rw-r--r--spec/ruby/core/module/instance_method_spec.rb5
-rw-r--r--spec/ruby/core/module/name_spec.rb53
-rw-r--r--spec/ruby/core/module/prepend_spec.rb28
-rw-r--r--spec/ruby/core/module/refine_spec.rb26
-rw-r--r--spec/ruby/core/module/refinements_spec.rb56
-rw-r--r--spec/ruby/core/module/ruby2_keywords_spec.rb171
-rw-r--r--spec/ruby/core/module/set_temporary_name_spec.rb3
-rw-r--r--spec/ruby/core/module/undefined_instance_methods_spec.rb32
-rw-r--r--spec/ruby/core/module/used_refinements_spec.rb110
-rw-r--r--spec/ruby/core/objectspace/_id2ref_spec.rb87
-rw-r--r--spec/ruby/core/proc/element_reference_spec.rb2
-rw-r--r--spec/ruby/core/proc/parameters_spec.rb70
-rw-r--r--spec/ruby/core/proc/ruby2_keywords_spec.rb14
-rw-r--r--spec/ruby/core/proc/shared/dup.rb8
-rw-r--r--spec/ruby/core/proc/source_location_spec.rb12
-rw-r--r--spec/ruby/core/process/_fork_spec.rb2
-rw-r--r--spec/ruby/core/process/status/bit_and_spec.rb4
-rw-r--r--spec/ruby/core/process/status/right_shift_spec.rb4
-rw-r--r--spec/ruby/core/queue/deq_spec.rb4
-rw-r--r--spec/ruby/core/queue/pop_spec.rb4
-rw-r--r--spec/ruby/core/queue/shift_spec.rb4
-rw-r--r--spec/ruby/core/random/bytes_spec.rb2
-rw-r--r--spec/ruby/core/random/default_spec.rb32
-rw-r--r--spec/ruby/core/random/new_spec.rb2
-rw-r--r--spec/ruby/core/range/case_compare_spec.rb2
-rw-r--r--spec/ruby/core/range/cover_spec.rb2
-rw-r--r--spec/ruby/core/range/include_spec.rb2
-rw-r--r--spec/ruby/core/range/last_spec.rb6
-rw-r--r--spec/ruby/core/range/max_spec.rb4
-rw-r--r--spec/ruby/core/range/member_spec.rb2
-rw-r--r--spec/ruby/core/range/reverse_each_spec.rb2
-rw-r--r--spec/ruby/core/range/shared/cover.rb2
-rw-r--r--spec/ruby/core/range/shared/cover_and_include.rb2
-rw-r--r--spec/ruby/core/range/shared/include.rb2
-rw-r--r--spec/ruby/core/range/size_spec.rb11
-rw-r--r--spec/ruby/core/range/to_set_spec.rb55
-rw-r--r--spec/ruby/core/refinement/append_features_spec.rb24
-rw-r--r--spec/ruby/core/refinement/extend_object_spec.rb28
-rw-r--r--spec/ruby/core/refinement/include_spec.rb26
-rw-r--r--spec/ruby/core/refinement/prepend_features_spec.rb24
-rw-r--r--spec/ruby/core/refinement/prepend_spec.rb26
-rw-r--r--spec/ruby/core/refinement/refined_class_spec.rb2
-rw-r--r--spec/ruby/core/regexp/compile_spec.rb2
-rw-r--r--spec/ruby/core/regexp/linear_time_spec.rb42
-rw-r--r--spec/ruby/core/regexp/new_spec.rb2
-rw-r--r--spec/ruby/core/regexp/shared/new.rb410
-rw-r--r--spec/ruby/core/regexp/shared/quote.rb2
-rw-r--r--spec/ruby/core/regexp/timeout_spec.rb48
-rw-r--r--spec/ruby/core/set/add_spec.rb (renamed from spec/ruby/library/set/add_spec.rb)9
-rw-r--r--spec/ruby/core/set/append_spec.rb (renamed from spec/ruby/library/set/append_spec.rb)1
-rw-r--r--spec/ruby/core/set/case_compare_spec.rb (renamed from spec/ruby/library/set/case_compare_spec.rb)1
-rw-r--r--spec/ruby/core/set/case_equality_spec.rb (renamed from spec/ruby/library/set/case_equality_spec.rb)1
-rw-r--r--spec/ruby/core/set/classify_spec.rb (renamed from spec/ruby/library/set/classify_spec.rb)1
-rw-r--r--spec/ruby/core/set/clear_spec.rb (renamed from spec/ruby/library/set/clear_spec.rb)1
-rw-r--r--spec/ruby/core/set/collect_spec.rb (renamed from spec/ruby/library/set/collect_spec.rb)1
-rw-r--r--spec/ruby/core/set/compare_by_identity_spec.rb (renamed from spec/ruby/library/set/compare_by_identity_spec.rb)22
-rw-r--r--spec/ruby/core/set/comparison_spec.rb (renamed from spec/ruby/library/set/comparison_spec.rb)1
-rw-r--r--spec/ruby/core/set/constructor_spec.rb (renamed from spec/ruby/library/set/constructor_spec.rb)1
-rw-r--r--spec/ruby/core/set/delete_if_spec.rb (renamed from spec/ruby/library/set/delete_if_spec.rb)1
-rw-r--r--spec/ruby/core/set/delete_spec.rb (renamed from spec/ruby/library/set/delete_spec.rb)1
-rw-r--r--spec/ruby/core/set/difference_spec.rb (renamed from spec/ruby/library/set/difference_spec.rb)1
-rw-r--r--spec/ruby/core/set/disjoint_spec.rb (renamed from spec/ruby/library/set/disjoint_spec.rb)1
-rw-r--r--spec/ruby/core/set/divide_spec.rb (renamed from spec/ruby/library/set/divide_spec.rb)19
-rw-r--r--spec/ruby/core/set/each_spec.rb (renamed from spec/ruby/library/set/each_spec.rb)1
-rw-r--r--spec/ruby/core/set/empty_spec.rb (renamed from spec/ruby/library/set/empty_spec.rb)1
-rw-r--r--spec/ruby/core/set/enumerable/to_set_spec.rb (renamed from spec/ruby/library/set/enumerable/to_set_spec.rb)1
-rw-r--r--spec/ruby/core/set/eql_spec.rb (renamed from spec/ruby/library/set/eql_spec.rb)1
-rw-r--r--spec/ruby/core/set/equal_value_spec.rb (renamed from spec/ruby/library/set/equal_value_spec.rb)9
-rw-r--r--spec/ruby/core/set/exclusion_spec.rb (renamed from spec/ruby/library/set/exclusion_spec.rb)1
-rw-r--r--spec/ruby/core/set/filter_spec.rb (renamed from spec/ruby/library/set/filter_spec.rb)0
-rw-r--r--spec/ruby/core/set/fixtures/set_like.rb (renamed from spec/ruby/library/set/fixtures/set_like.rb)1
-rw-r--r--spec/ruby/core/set/flatten_merge_spec.rb24
-rw-r--r--spec/ruby/core/set/flatten_spec.rb (renamed from spec/ruby/library/set/flatten_spec.rb)17
-rw-r--r--spec/ruby/core/set/hash_spec.rb (renamed from spec/ruby/library/set/hash_spec.rb)9
-rw-r--r--spec/ruby/core/set/include_spec.rb (renamed from spec/ruby/library/set/include_spec.rb)1
-rw-r--r--spec/ruby/core/set/initialize_clone_spec.rb (renamed from spec/ruby/library/set/initialize_clone_spec.rb)1
-rw-r--r--spec/ruby/core/set/initialize_spec.rb (renamed from spec/ruby/library/set/initialize_spec.rb)1
-rw-r--r--spec/ruby/core/set/inspect_spec.rb (renamed from spec/ruby/library/set/inspect_spec.rb)1
-rw-r--r--spec/ruby/core/set/intersect_spec.rb (renamed from spec/ruby/library/set/intersect_spec.rb)1
-rw-r--r--spec/ruby/core/set/intersection_spec.rb (renamed from spec/ruby/library/set/intersection_spec.rb)1
-rw-r--r--spec/ruby/core/set/join_spec.rb (renamed from spec/ruby/library/set/join_spec.rb)11
-rw-r--r--spec/ruby/core/set/keep_if_spec.rb (renamed from spec/ruby/library/set/keep_if_spec.rb)1
-rw-r--r--spec/ruby/core/set/length_spec.rb (renamed from spec/ruby/library/set/length_spec.rb)1
-rw-r--r--spec/ruby/core/set/map_spec.rb (renamed from spec/ruby/library/set/map_spec.rb)1
-rw-r--r--spec/ruby/core/set/member_spec.rb (renamed from spec/ruby/library/set/member_spec.rb)1
-rw-r--r--spec/ruby/core/set/merge_spec.rb (renamed from spec/ruby/library/set/merge_spec.rb)8
-rw-r--r--spec/ruby/core/set/minus_spec.rb (renamed from spec/ruby/library/set/minus_spec.rb)1
-rw-r--r--spec/ruby/core/set/plus_spec.rb (renamed from spec/ruby/library/set/plus_spec.rb)1
-rw-r--r--spec/ruby/core/set/pretty_print_cycle_spec.rb (renamed from spec/ruby/library/set/pretty_print_cycle_spec.rb)8
-rw-r--r--spec/ruby/core/set/proper_subset_spec.rb (renamed from spec/ruby/library/set/proper_subset_spec.rb)9
-rw-r--r--spec/ruby/core/set/proper_superset_spec.rb (renamed from spec/ruby/library/set/proper_superset_spec.rb)9
-rw-r--r--spec/ruby/core/set/reject_spec.rb (renamed from spec/ruby/library/set/reject_spec.rb)1
-rw-r--r--spec/ruby/core/set/replace_spec.rb (renamed from spec/ruby/library/set/replace_spec.rb)9
-rw-r--r--spec/ruby/core/set/select_spec.rb (renamed from spec/ruby/library/set/select_spec.rb)0
-rw-r--r--spec/ruby/core/set/set_spec.rb10
-rw-r--r--spec/ruby/core/set/shared/add.rb (renamed from spec/ruby/library/set/shared/add.rb)0
-rw-r--r--spec/ruby/core/set/shared/collect.rb (renamed from spec/ruby/library/set/shared/collect.rb)0
-rw-r--r--spec/ruby/core/set/shared/difference.rb (renamed from spec/ruby/library/set/shared/difference.rb)0
-rw-r--r--spec/ruby/core/set/shared/include.rb (renamed from spec/ruby/library/set/shared/include.rb)0
-rw-r--r--spec/ruby/core/set/shared/inspect.rb45
-rw-r--r--spec/ruby/core/set/shared/intersection.rb (renamed from spec/ruby/library/set/shared/intersection.rb)0
-rw-r--r--spec/ruby/core/set/shared/length.rb (renamed from spec/ruby/library/set/shared/length.rb)0
-rw-r--r--spec/ruby/core/set/shared/select.rb (renamed from spec/ruby/library/set/shared/select.rb)1
-rw-r--r--spec/ruby/core/set/shared/union.rb (renamed from spec/ruby/library/set/shared/union.rb)0
-rw-r--r--spec/ruby/core/set/size_spec.rb (renamed from spec/ruby/library/set/size_spec.rb)1
-rw-r--r--spec/ruby/core/set/sortedset/sortedset_spec.rb13
-rw-r--r--spec/ruby/core/set/subset_spec.rb (renamed from spec/ruby/library/set/subset_spec.rb)9
-rw-r--r--spec/ruby/core/set/subtract_spec.rb (renamed from spec/ruby/library/set/subtract_spec.rb)1
-rw-r--r--spec/ruby/core/set/superset_spec.rb (renamed from spec/ruby/library/set/superset_spec.rb)9
-rw-r--r--spec/ruby/core/set/to_a_spec.rb (renamed from spec/ruby/library/set/to_a_spec.rb)1
-rw-r--r--spec/ruby/core/set/to_s_spec.rb (renamed from spec/ruby/library/set/to_s_spec.rb)1
-rw-r--r--spec/ruby/core/set/union_spec.rb (renamed from spec/ruby/library/set/union_spec.rb)1
-rw-r--r--spec/ruby/core/sizedqueue/append_spec.rb4
-rw-r--r--spec/ruby/core/sizedqueue/deq_spec.rb4
-rw-r--r--spec/ruby/core/sizedqueue/enq_spec.rb4
-rw-r--r--spec/ruby/core/sizedqueue/pop_spec.rb4
-rw-r--r--spec/ruby/core/sizedqueue/push_spec.rb4
-rw-r--r--spec/ruby/core/sizedqueue/shift_spec.rb4
-rw-r--r--spec/ruby/core/string/byteindex_spec.rb470
-rw-r--r--spec/ruby/core/string/byterindex_spec.rb568
-rw-r--r--spec/ruby/core/string/byteslice_spec.rb2
-rw-r--r--spec/ruby/core/string/bytesplice_spec.rb204
-rw-r--r--spec/ruby/core/string/chilled_string_spec.rb8
-rw-r--r--spec/ruby/core/string/codepoints_spec.rb2
-rw-r--r--spec/ruby/core/string/count_spec.rb2
-rw-r--r--spec/ruby/core/string/dedup_spec.rb4
-rw-r--r--spec/ruby/core/string/modulo_spec.rb12
-rw-r--r--spec/ruby/core/string/rstrip_spec.rb28
-rw-r--r--spec/ruby/core/string/shared/codepoints.rb2
-rw-r--r--spec/ruby/core/string/shared/each_codepoint_without_block.rb2
-rw-r--r--spec/ruby/core/string/shared/eql.rb2
-rw-r--r--spec/ruby/core/string/shared/succ.rb2
-rw-r--r--spec/ruby/core/string/squeeze_spec.rb2
-rw-r--r--spec/ruby/core/string/to_c_spec.rb20
-rw-r--r--spec/ruby/core/string/to_f_spec.rb14
-rw-r--r--spec/ruby/core/string/unpack/a_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/at_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/b_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/c_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/comment_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/h_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/m_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/shared/basic.rb17
-rw-r--r--spec/ruby/core/string/unpack/shared/float.rb2
-rw-r--r--spec/ruby/core/string/unpack/shared/integer.rb2
-rw-r--r--spec/ruby/core/string/unpack/u_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/w_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/x_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack/z_spec.rb2
-rw-r--r--spec/ruby/core/string/unpack1_spec.rb13
-rw-r--r--spec/ruby/core/string/unpack_spec.rb2
-rw-r--r--spec/ruby/core/string/uplus_spec.rb44
-rw-r--r--spec/ruby/core/struct/constants_spec.rb16
-rw-r--r--spec/ruby/core/struct/deconstruct_keys_spec.rb31
-rw-r--r--spec/ruby/core/struct/element_set_spec.rb7
-rw-r--r--spec/ruby/core/struct/initialize_spec.rb20
-rw-r--r--spec/ruby/core/struct/new_spec.rb59
-rw-r--r--spec/ruby/core/struct/struct_spec.rb7
-rw-r--r--spec/ruby/core/symbol/inspect_spec.rb15
-rw-r--r--spec/ruby/core/symbol/shared/id2name.rb14
-rw-r--r--spec/ruby/core/symbol/to_proc_spec.rb44
-rw-r--r--spec/ruby/core/thread/each_caller_location_spec.rb70
-rw-r--r--spec/ruby/core/thread/fixtures/classes.rb25
-rw-r--r--spec/ruby/core/thread/raise_spec.rb3
-rw-r--r--spec/ruby/core/time/_dump_spec.rb2
-rw-r--r--spec/ruby/core/time/_load_spec.rb2
-rw-r--r--spec/ruby/core/time/deconstruct_keys_spec.rb80
-rw-r--r--spec/ruby/core/time/minus_spec.rb2
-rw-r--r--spec/ruby/core/time/new_spec.rb420
-rw-r--r--spec/ruby/core/time/now_spec.rb142
-rw-r--r--spec/ruby/core/time/shared/time_params.rb4
-rw-r--r--spec/ruby/core/time/utc_spec.rb4
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb55
-rw-r--r--spec/ruby/core/unboundmethod/equal_value_spec.rb39
-rw-r--r--spec/ruby/core/unboundmethod/owner_spec.rb6
-rw-r--r--spec/ruby/core/unboundmethod/private_spec.rb25
-rw-r--r--spec/ruby/core/unboundmethod/protected_spec.rb25
-rw-r--r--spec/ruby/core/unboundmethod/public_spec.rb25
-rw-r--r--spec/ruby/core/unboundmethod/shared/to_s.rb15
-rw-r--r--spec/ruby/core/unboundmethod/source_location_spec.rb4
-rw-r--r--spec/ruby/core/warning/categories_spec.rb12
-rw-r--r--spec/ruby/core/warning/warn_spec.rb28
-rw-r--r--spec/ruby/default.mspec5
-rw-r--r--spec/ruby/language/assignments_spec.rb205
-rw-r--r--spec/ruby/language/block_spec.rb140
-rw-r--r--spec/ruby/language/class_spec.rb42
-rw-r--r--spec/ruby/language/constants_spec.rb34
-rw-r--r--spec/ruby/language/def_spec.rb25
-rw-r--r--spec/ruby/language/delegation_spec.rb68
-rw-r--r--spec/ruby/language/fixtures/class_with_class_variable.rb9
-rw-r--r--spec/ruby/language/fixtures/module.rb9
-rw-r--r--spec/ruby/language/fixtures/send.rb10
-rw-r--r--spec/ruby/language/hash_spec.rb20
-rw-r--r--spec/ruby/language/it_parameter_spec.rb66
-rw-r--r--spec/ruby/language/keyword_arguments_spec.rb62
-rw-r--r--spec/ruby/language/magic_comment_spec.rb3
-rw-r--r--spec/ruby/language/method_spec.rb185
-rw-r--r--spec/ruby/language/module_spec.rb43
-rw-r--r--spec/ruby/language/numbered_parameters_spec.rb4
-rw-r--r--spec/ruby/language/pattern_matching_spec.rb2
-rw-r--r--spec/ruby/language/predefined_spec.rb222
-rw-r--r--spec/ruby/language/regexp/character_classes_spec.rb7
-rw-r--r--spec/ruby/language/regexp/encoding_spec.rb8
-rw-r--r--spec/ruby/language/regexp/escapes_spec.rb2
-rw-r--r--spec/ruby/language/regexp_spec.rb2
-rw-r--r--spec/ruby/language/rescue_spec.rb10
-rw-r--r--spec/ruby/language/reserved_keywords.rb149
-rw-r--r--spec/ruby/language/send_spec.rb18
-rw-r--r--spec/ruby/language/string_spec.rb14
-rw-r--r--spec/ruby/language/variables_spec.rb4
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb50
-rw-r--r--spec/ruby/library/bigdecimal/add_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/core_spec.rb7
-rw-r--r--spec/ruby/library/bigdecimal/divmod_spec.rb80
-rw-r--r--spec/ruby/library/bigdecimal/mult_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/precs_spec.rb55
-rw-r--r--spec/ruby/library/bigdecimal/remainder_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/round_spec.rb12
-rw-r--r--spec/ruby/library/bigdecimal/shared/modulo.rb14
-rw-r--r--spec/ruby/library/bigdecimal/shared/power.rb4
-rw-r--r--spec/ruby/library/bigdecimal/shared/quo.rb1
-rw-r--r--spec/ruby/library/bigdecimal/sub_spec.rb8
-rw-r--r--spec/ruby/library/cgi/cookie/domain_spec.rb33
-rw-r--r--spec/ruby/library/cgi/cookie/expires_spec.rb33
-rw-r--r--spec/ruby/library/cgi/cookie/initialize_spec.rb235
-rw-r--r--spec/ruby/library/cgi/cookie/name_spec.rb33
-rw-r--r--spec/ruby/library/cgi/cookie/parse_spec.rb41
-rw-r--r--spec/ruby/library/cgi/cookie/path_spec.rb33
-rw-r--r--spec/ruby/library/cgi/cookie/secure_spec.rb99
-rw-r--r--spec/ruby/library/cgi/cookie/to_s_spec.rb51
-rw-r--r--spec/ruby/library/cgi/cookie/value_spec.rb121
-rw-r--r--spec/ruby/library/cgi/escapeElement_spec.rb8
-rw-r--r--spec/ruby/library/cgi/escapeHTML_spec.rb6
-rw-r--r--spec/ruby/library/cgi/escapeURIComponent_spec.rb105
-rw-r--r--spec/ruby/library/cgi/escape_spec.rb6
-rw-r--r--spec/ruby/library/cgi/htmlextension/a_spec.rb73
-rw-r--r--spec/ruby/library/cgi/htmlextension/base_spec.rb47
-rw-r--r--spec/ruby/library/cgi/htmlextension/blockquote_spec.rb47
-rw-r--r--spec/ruby/library/cgi/htmlextension/br_spec.rb31
-rw-r--r--spec/ruby/library/cgi/htmlextension/caption_spec.rb47
-rw-r--r--spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb121
-rw-r--r--spec/ruby/library/cgi/htmlextension/checkbox_spec.rb113
-rw-r--r--spec/ruby/library/cgi/htmlextension/doctype_spec.rb41
-rw-r--r--spec/ruby/library/cgi/htmlextension/file_field_spec.rb105
-rw-r--r--spec/ruby/library/cgi/htmlextension/form_spec.rb85
-rw-r--r--spec/ruby/library/cgi/htmlextension/frame_spec.rb21
-rw-r--r--spec/ruby/library/cgi/htmlextension/frameset_spec.rb21
-rw-r--r--spec/ruby/library/cgi/htmlextension/hidden_spec.rb87
-rw-r--r--spec/ruby/library/cgi/htmlextension/html_spec.rb99
-rw-r--r--spec/ruby/library/cgi/htmlextension/image_button_spec.rb101
-rw-r--r--spec/ruby/library/cgi/htmlextension/img_spec.rb123
-rw-r--r--spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb93
-rw-r--r--spec/ruby/library/cgi/htmlextension/password_field_spec.rb123
-rw-r--r--spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb13
-rw-r--r--spec/ruby/library/cgi/htmlextension/radio_button_spec.rb113
-rw-r--r--spec/ruby/library/cgi/htmlextension/radio_group_spec.rb123
-rw-r--r--spec/ruby/library/cgi/htmlextension/reset_spec.rb83
-rw-r--r--spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb13
-rw-r--r--spec/ruby/library/cgi/htmlextension/submit_spec.rb83
-rw-r--r--spec/ruby/library/cgi/htmlextension/text_field_spec.rb123
-rw-r--r--spec/ruby/library/cgi/htmlextension/textarea_spec.rb107
-rw-r--r--spec/ruby/library/cgi/http_header_spec.rb11
-rw-r--r--spec/ruby/library/cgi/initialize_spec.rb209
-rw-r--r--spec/ruby/library/cgi/out_spec.rb97
-rw-r--r--spec/ruby/library/cgi/parse_spec.rb37
-rw-r--r--spec/ruby/library/cgi/pretty_spec.rb19
-rw-r--r--spec/ruby/library/cgi/print_spec.rb39
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_charset_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_language_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/auth_type_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/cache_control_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/content_length_spec.rb39
-rw-r--r--spec/ruby/library/cgi/queryextension/content_type_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/cookies_spec.rb15
-rw-r--r--spec/ruby/library/cgi/queryextension/element_reference_spec.rb41
-rw-r--r--spec/ruby/library/cgi/queryextension/from_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/has_key_spec.rb11
-rw-r--r--spec/ruby/library/cgi/queryextension/host_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/include_spec.rb11
-rw-r--r--spec/ruby/library/cgi/queryextension/key_spec.rb11
-rw-r--r--spec/ruby/library/cgi/queryextension/keys_spec.rb29
-rw-r--r--spec/ruby/library/cgi/queryextension/multipart_spec.rb47
-rw-r--r--spec/ruby/library/cgi/queryextension/negotiate_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/params_spec.rb55
-rw-r--r--spec/ruby/library/cgi/queryextension/path_info_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/path_translated_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/pragma_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/query_string_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/referer_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_addr_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_host_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_ident_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_user_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/request_method_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/script_name_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/server_name_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/server_port_spec.rb39
-rw-r--r--spec/ruby/library/cgi/queryextension/server_protocol_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/server_software_spec.rb33
-rw-r--r--spec/ruby/library/cgi/queryextension/user_agent_spec.rb33
-rw-r--r--spec/ruby/library/cgi/rfc1123_date_spec.rb15
-rw-r--r--spec/ruby/library/cgi/unescapeElement_spec.rb8
-rw-r--r--spec/ruby/library/cgi/unescapeHTML_spec.rb6
-rw-r--r--spec/ruby/library/cgi/unescapeURIComponent_spec.rb128
-rw-r--r--spec/ruby/library/cgi/unescape_spec.rb8
-rw-r--r--spec/ruby/library/coverage/result_spec.rb112
-rw-r--r--spec/ruby/library/coverage/start_spec.rb114
-rw-r--r--spec/ruby/library/coverage/supported_spec.rb42
-rw-r--r--spec/ruby/library/date/deconstruct_keys_spec.rb74
-rw-r--r--spec/ruby/library/datetime/deconstruct_keys_spec.rb78
-rw-r--r--spec/ruby/library/datetime/time/to_datetime_spec.rb20
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb20
-rw-r--r--spec/ruby/library/digest/md5/shared/constants.rb2
-rw-r--r--spec/ruby/library/digest/sha1/shared/constants.rb2
-rw-r--r--spec/ruby/library/digest/sha256/shared/constants.rb2
-rw-r--r--spec/ruby/library/digest/sha384/shared/constants.rb2
-rw-r--r--spec/ruby/library/digest/sha512/shared/constants.rb2
-rw-r--r--spec/ruby/library/erb/new_spec.rb24
-rw-r--r--spec/ruby/library/io-wait/wait_readable_spec.rb4
-rw-r--r--spec/ruby/library/io-wait/wait_spec.rb61
-rw-r--r--spec/ruby/library/io-wait/wait_writable_spec.rb4
-rw-r--r--spec/ruby/library/net-http/HTTPServerException_spec.rb4
-rw-r--r--spec/ruby/library/net-http/http/post_spec.rb8
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb54
-rw-r--r--spec/ruby/library/objectspace/trace_object_allocations_spec.rb32
-rw-r--r--spec/ruby/library/openssl/digest/initialize_spec.rb16
-rw-r--r--spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb20
-rw-r--r--spec/ruby/library/openssl/kdf/scrypt_spec.rb3
-rw-r--r--spec/ruby/library/openssl/shared/constants.rb2
-rw-r--r--spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb14
-rw-r--r--spec/ruby/library/rbconfig/unicode_version_spec.rb14
-rw-r--r--spec/ruby/library/set/flatten_merge_spec.rb23
-rw-r--r--spec/ruby/library/set/set_spec.rb12
-rw-r--r--spec/ruby/library/set/shared/inspect.rb25
-rw-r--r--spec/ruby/library/set/sortedset/sortedset_spec.rb12
-rw-r--r--spec/ruby/library/socket/addrinfo/afamily_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb48
-rw-r--r--spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/initialize_spec.rb58
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_spec.rb26
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_port_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb2
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb50
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_load_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/pfamily_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/protocol_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/socktype_spec.rb14
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_path_spec.rb46
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_spec.rb46
-rw-r--r--spec/ruby/library/socket/basicsocket/connect_address_spec.rb80
-rw-r--r--spec/ruby/library/socket/basicsocket/getpeereid_spec.rb2
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_spec.rb2
-rw-r--r--spec/ruby/library/socket/basicsocket/setsockopt_spec.rb26
-rw-r--r--spec/ruby/library/socket/shared/address.rb86
-rw-r--r--spec/ruby/library/socket/shared/pack_sockaddr.rb30
-rw-r--r--spec/ruby/library/socket/socket/getaddrinfo_spec.rb18
-rw-r--r--spec/ruby/library/socket/socket/gethostbyname_spec.rb2
-rw-r--r--spec/ruby/library/socket/socket/getnameinfo_spec.rb18
-rw-r--r--spec/ruby/library/socket/socket/udp_server_loop_spec.rb4
-rw-r--r--spec/ruby/library/socket/socket/unix_server_loop_spec.rb76
-rw-r--r--spec/ruby/library/socket/socket/unix_server_socket_spec.rb56
-rw-r--r--spec/ruby/library/socket/socket/unix_spec.rb56
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb16
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb34
-rw-r--r--spec/ruby/library/socket/spec_helper.rb1
-rw-r--r--spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb4
-rw-r--r--spec/ruby/library/socket/tcpsocket/shared/new.rb48
-rw-r--r--spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb114
-rw-r--r--spec/ruby/library/socket/unixserver/accept_spec.rb166
-rw-r--r--spec/ruby/library/socket/unixserver/for_fd_spec.rb28
-rw-r--r--spec/ruby/library/socket/unixserver/initialize_spec.rb36
-rw-r--r--spec/ruby/library/socket/unixserver/listen_spec.rb24
-rw-r--r--spec/ruby/library/socket/unixserver/new_spec.rb14
-rw-r--r--spec/ruby/library/socket/unixserver/open_spec.rb30
-rw-r--r--spec/ruby/library/socket/unixserver/sysaccept_spec.rb64
-rw-r--r--spec/ruby/library/socket/unixsocket/addr_spec.rb48
-rw-r--r--spec/ruby/library/socket/unixsocket/initialize_spec.rb60
-rw-r--r--spec/ruby/library/socket/unixsocket/inspect_spec.rb20
-rw-r--r--spec/ruby/library/socket/unixsocket/local_address_spec.rb132
-rw-r--r--spec/ruby/library/socket/unixsocket/new_spec.rb14
-rw-r--r--spec/ruby/library/socket/unixsocket/open_spec.rb34
-rw-r--r--spec/ruby/library/socket/unixsocket/pair_spec.rb20
-rw-r--r--spec/ruby/library/socket/unixsocket/partially_closable_spec.rb30
-rw-r--r--spec/ruby/library/socket/unixsocket/path_spec.rb34
-rw-r--r--spec/ruby/library/socket/unixsocket/peeraddr_spec.rb38
-rw-r--r--spec/ruby/library/socket/unixsocket/recv_io_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/recvfrom_spec.rb152
-rw-r--r--spec/ruby/library/socket/unixsocket/remote_address_spec.rb60
-rw-r--r--spec/ruby/library/socket/unixsocket/send_io_spec.rb2
-rw-r--r--spec/ruby/library/socket/unixsocket/shared/pair.rb38
-rw-r--r--spec/ruby/library/socket/unixsocket/socketpair_spec.rb20
-rw-r--r--spec/ruby/library/stringio/each_line_spec.rb4
-rw-r--r--spec/ruby/library/stringio/each_spec.rb4
-rw-r--r--spec/ruby/library/stringio/fileno_spec.rb3
-rw-r--r--spec/ruby/library/stringio/gets_spec.rb263
-rw-r--r--spec/ruby/library/stringio/readline_spec.rb160
-rw-r--r--spec/ruby/library/stringio/readpartial_spec.rb38
-rw-r--r--spec/ruby/library/stringio/shared/each.rb78
-rw-r--r--spec/ruby/library/stringio/shared/gets.rb249
-rw-r--r--spec/ruby/library/stringscanner/check_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/check_until_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/clear_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/empty_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/eos_spec.rb17
-rw-r--r--spec/ruby/library/stringscanner/exist_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/get_byte_spec.rb81
-rw-r--r--spec/ruby/library/stringscanner/getbyte_spec.rb21
-rw-r--r--spec/ruby/library/stringscanner/getch_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/named_captures_spec.rb42
-rw-r--r--spec/ruby/library/stringscanner/peek_spec.rb39
-rw-r--r--spec/ruby/library/stringscanner/peep_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/rest_size_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/restsize_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/scan_byte_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/scan_integer_spec.rb8
-rw-r--r--spec/ruby/library/stringscanner/scan_until_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/search_full_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/shared/eos.rb17
-rw-r--r--spec/ruby/library/stringscanner/shared/get_byte.rb87
-rw-r--r--spec/ruby/library/stringscanner/shared/peek.rb39
-rw-r--r--spec/ruby/library/stringscanner/shared/pos.rb7
-rw-r--r--spec/ruby/library/stringscanner/shared/rest_size.rb18
-rw-r--r--spec/ruby/library/stringscanner/shared/terminate.rb8
-rw-r--r--spec/ruby/library/stringscanner/skip_until_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/terminate_spec.rb8
-rw-r--r--spec/ruby/library/stringscanner/unscan_spec.rb6
-rw-r--r--spec/ruby/library/tempfile/callback_spec.rb6
-rw-r--r--spec/ruby/library/tempfile/create_spec.rb176
-rw-r--r--spec/ruby/library/timeout/timeout_spec.rb8
-rw-r--r--spec/ruby/library/uri/generic/host_spec.rb8
-rw-r--r--spec/ruby/library/uri/generic/to_s_spec.rb8
-rw-r--r--spec/ruby/library/uri/set_component_spec.rb40
-rw-r--r--spec/ruby/library/win32ole/fixtures/classes.rb17
-rw-r--r--spec/ruby/library/win32ole/win32ole/locale_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/new_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole/shared/ole_method.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_event/new_spec.rb14
-rw-r--r--spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb12
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb10
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/event_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb10
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/name_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/new_spec.rb22
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/params_spec.rb14
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/shared/name.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/visible_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/default_spec.rb12
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/input_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/name_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/optional_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/retval_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/shared/name.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/guid_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/name_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/new_spec.rb32
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/progid_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/progids_spec.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/shared/name.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb8
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/variables_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/visible_spec.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/shared/name.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/value_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb2
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb2
-rw-r--r--spec/ruby/library/zlib/inflate/set_dictionary_spec.rb2
-rw-r--r--spec/ruby/optional/capi/array_spec.rb48
-rw-r--r--spec/ruby/optional/capi/binding_spec.rb18
-rw-r--r--spec/ruby/optional/capi/digest_spec.rb103
-rw-r--r--spec/ruby/optional/capi/encoding_spec.rb22
-rw-r--r--spec/ruby/optional/capi/exception_spec.rb20
-rw-r--r--spec/ruby/optional/capi/ext/array_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/class_spec.c4
-rw-r--r--spec/ruby/optional/capi/ext/constants_spec.c6
-rw-r--r--spec/ruby/optional/capi/ext/digest_spec.c168
-rw-r--r--spec/ruby/optional/capi/ext/exception_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/fiber_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/hash_spec.c4
-rw-r--r--spec/ruby/optional/capi/ext/io_spec.c32
-rw-r--r--spec/ruby/optional/capi/ext/kernel_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/object_spec.c49
-rw-r--r--spec/ruby/optional/capi/ext/range_spec.c48
-rw-r--r--spec/ruby/optional/capi/ext/rbasic_spec.c10
-rw-r--r--spec/ruby/optional/capi/ext/rubyspec.h16
-rw-r--r--spec/ruby/optional/capi/ext/set_spec.c65
-rw-r--r--spec/ruby/optional/capi/ext/string_spec.c15
-rw-r--r--spec/ruby/optional/capi/ext/struct_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/thread_spec.c4
-rw-r--r--spec/ruby/optional/capi/globals_spec.rb13
-rw-r--r--spec/ruby/optional/capi/hash_spec.rb20
-rw-r--r--spec/ruby/optional/capi/integer_spec.rb2
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb30
-rw-r--r--spec/ruby/optional/capi/module_spec.rb2
-rw-r--r--spec/ruby/optional/capi/object_spec.rb12
-rw-r--r--spec/ruby/optional/capi/range_spec.rb144
-rw-r--r--spec/ruby/optional/capi/regexp_spec.rb2
-rw-r--r--spec/ruby/optional/capi/set_spec.rb96
-rw-r--r--spec/ruby/optional/capi/shared/rbasic.rb1
-rw-r--r--spec/ruby/optional/capi/spec_helper.rb17
-rw-r--r--spec/ruby/optional/capi/string_spec.rb66
-rw-r--r--spec/ruby/optional/capi/struct_spec.rb74
-rw-r--r--spec/ruby/optional/capi/thread_spec.rb2
-rw-r--r--spec/ruby/optional/thread_safety/fixtures/classes.rb39
-rw-r--r--spec/ruby/optional/thread_safety/hash_spec.rb210
-rw-r--r--spec/ruby/security/cve_2020_10663_spec.rb2
-rw-r--r--spec/ruby/security/cve_2024_49761_spec.rb8
-rw-r--r--spec/ruby/shared/file/socket.rb32
-rw-r--r--spec/ruby/shared/io/putc.rb2
-rw-r--r--spec/ruby/shared/kernel/raise.rb348
-rw-r--r--spec/ruby/shared/queue/deque.rb118
-rw-r--r--spec/ruby/shared/sizedqueue/enque.rb152
764 files changed, 15460 insertions, 10356 deletions
diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml
index a385b5e79c..0b59a11512 100644
--- a/spec/ruby/.rubocop.yml
+++ b/spec/ruby/.rubocop.yml
@@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml
AllCops:
- TargetRubyVersion: 3.1
+ TargetRubyVersion: 3.2
DisplayCopNames: true
Exclude:
- command_line/fixtures/bad_syntax.rb
@@ -197,6 +197,7 @@ Style/Lambda:
- 'language/lambda_spec.rb'
- 'language/proc_spec.rb'
- 'language/numbered_parameters_spec.rb'
+ - 'language/it_parameter_spec.rb'
- 'core/kernel/lambda_spec.rb'
Style/EmptyLambdaParameter:
diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml
index 6b43db9b9a..bd30f3f14a 100644
--- a/spec/ruby/.rubocop_todo.yml
+++ b/spec/ruby/.rubocop_todo.yml
@@ -44,6 +44,7 @@ Lint/FloatOutOfRange:
Lint/ImplicitStringConcatenation:
Exclude:
- 'language/string_spec.rb'
+ - 'core/string/chilled_string_spec.rb'
# Offense count: 4
Lint/IneffectiveAccessModifier:
diff --git a/spec/ruby/README.md b/spec/ruby/README.md
index ee1015c24c..674ada4c9e 100644
--- a/spec/ruby/README.md
+++ b/spec/ruby/README.md
@@ -26,12 +26,12 @@ ruby/spec is known to be tested in these implementations for every commit:
* [MRI](https://rubyci.org/) on 30 platforms and 4 versions
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
-* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
+* [TruffleRuby](https://github.com/truffleruby/truffleruby/tree/master/spec/ruby)
* [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 3.1 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 (3.1.x, 3.2.x, etc), and those are tested in CI.
+ruby/spec describes the behavior of Ruby 3.2 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 (3.2.x, 3.3.x, etc), and those are tested in CI.
### Synchronization with Ruby Implementations
@@ -63,6 +63,7 @@ For older specs try these commits:
* Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661)
* Ruby 2.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd)
* Ruby 3.0.7 - [Suite](https://github.com/ruby/spec/commit/affef93d9940f615e4836f64b011da211f570913) using [MSpec](https://github.com/ruby/mspec/commit/0aabb3e548eb5ea6cad0125f8f46cee34542b6b7)
+* Ruby 3.1.6 - [Suite](https://github.com/ruby/spec/commit/ec960f2389d1c2265d32397fa8afa6d462014efc) using [MSpec](https://github.com/ruby/mspec/commit/484310dbed35b84c74484fd674602f88c42d063a)
### Running the specs
diff --git a/spec/ruby/command_line/dash_0_spec.rb b/spec/ruby/command_line/dash_0_spec.rb
index 73c5e29004..2ce4f49b5e 100755
--- a/spec/ruby/command_line/dash_0_spec.rb
+++ b/spec/ruby/command_line/dash_0_spec.rb
@@ -5,7 +5,7 @@ describe "The -0 command line option" do
ruby_exe("puts $/, $-0", options: "-072").should == ":\n:\n"
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "sets $/ and $-0 as a frozen string" do
ruby_exe("puts $/.frozen?, $-0.frozen?", options: "-072").should == "true\ntrue\n"
end
diff --git a/spec/ruby/command_line/dash_v_spec.rb b/spec/ruby/command_line/dash_v_spec.rb
index d30efa37d6..b13350404c 100644
--- a/spec/ruby/command_line/dash_v_spec.rb
+++ b/spec/ruby/command_line/dash_v_spec.rb
@@ -6,7 +6,7 @@ describe "The -v command line option" do
describe "when used alone" do
it "prints version and ends" do
- ruby_exe(nil, args: '-v').sub("+PRISM ", "").should include(RUBY_DESCRIPTION.sub("+PRISM ", ""))
+ ruby_exe(nil, args: '-v').gsub("+PRISM ", "").should include(RUBY_DESCRIPTION.gsub("+PRISM ", ""))
end unless (defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?) ||
(defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?) ||
(ENV['RUBY_GC_LIBRARY'] && ENV['RUBY_GC_LIBRARY'].length > 0) ||
diff --git a/spec/ruby/command_line/feature_spec.rb b/spec/ruby/command_line/feature_spec.rb
index 4a24cc6795..838581d04a 100644
--- a/spec/ruby/command_line/feature_spec.rb
+++ b/spec/ruby/command_line/feature_spec.rb
@@ -51,7 +51,7 @@ describe "The --enable and --disable flags" do
env = {'RUBYOPT' => '-w'}
# Use a single variant here because it can be quite slow as it might enable jit, etc
ruby_exe(e, options: "--enable-all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
- end
+ end unless defined?(RubyVM::YJIT) && defined?(RubyVM::ZJIT) && RubyVM::ZJIT.enabled? # You're not supposed to enable YJIT with --enable-all when ZJIT options are passed.
end
it "can be used with all for disable" do
diff --git a/spec/ruby/command_line/frozen_strings_spec.rb b/spec/ruby/command_line/frozen_strings_spec.rb
index 014153e0b4..8acab5bc1d 100644
--- a/spec/ruby/command_line/frozen_strings_spec.rb
+++ b/spec/ruby/command_line/frozen_strings_spec.rb
@@ -42,8 +42,28 @@ describe "With neither --enable-frozen-string-literal nor --disable-frozen-strin
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
end
- it "if file has no frozen_string_literal comment produce different mutable strings each time" do
- ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
+ context "if file has no frozen_string_literal comment" do
+ it "produce different mutable strings each time" do
+ ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
+ end
+
+ guard -> { ruby_version_is "3.4" and !"test".frozen? } do
+ it "complain about modification of produced mutable strings" do
+ -> { eval(<<~RUBY) }.should complain(/warning: literal string will be frozen in the future \(run with --debug-frozen-string-literal for more information\)/)
+ "test" << "!"
+ RUBY
+ end
+
+ it "does not complain about modification if Warning[:deprecated] is false" do
+ deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ -> { eval(<<~RUBY) }.should_not complain
+ "test" << "!"
+ RUBY
+ ensure
+ Warning[:deprecated] = deprecated
+ end
+ end
end
it "if file has frozen_string_literal:true comment produce same frozen strings each time" do
diff --git a/spec/ruby/command_line/rubyopt_spec.rb b/spec/ruby/command_line/rubyopt_spec.rb
index e940f912af..eb297cd6fe 100644
--- a/spec/ruby/command_line/rubyopt_spec.rb
+++ b/spec/ruby/command_line/rubyopt_spec.rb
@@ -25,12 +25,12 @@ describe "Processing RUBYOPT" do
guard -> { RbConfig::CONFIG["CROSS_COMPILING"] != "yes" } do
it "prints the version number for '-v'" do
ENV["RUBYOPT"] = '-v'
- ruby_exe("").sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")
+ ruby_exe("")[/\A.*/].gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "").should == RUBY_DESCRIPTION.gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "")
end
it "ignores whitespace around the option" do
ENV["RUBYOPT"] = ' -v '
- ruby_exe("").sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")
+ ruby_exe("")[/\A.*/].gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "").should == RUBY_DESCRIPTION.gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "")
end
end
diff --git a/spec/ruby/core/array/fetch_values_spec.rb b/spec/ruby/core/array/fetch_values_spec.rb
index 075dcc7a52..cf377b3b71 100644
--- a/spec/ruby/core/array/fetch_values_spec.rb
+++ b/spec/ruby/core/array/fetch_values_spec.rb
@@ -21,7 +21,7 @@ describe "Array#fetch_values" do
describe "with unmatched indexes" do
it "raises a index error if no block is provided" do
- -> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError)
+ -> { @array.fetch_values(0, 1, 44) }.should raise_error(IndexError, "index 44 outside of array bounds: -3...3")
end
it "returns the default value from block" do
@@ -42,8 +42,14 @@ describe "Array#fetch_values" do
@array.fetch_values(obj).should == [:c]
end
+ it "does not support a Range object as argument" do
+ -> {
+ @array.fetch_values(1..2)
+ }.should raise_error(TypeError, "no implicit conversion of Range into Integer")
+ end
+
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- -> { [].fetch_values("cat") }.should raise_error(TypeError)
+ -> { [].fetch_values("cat") }.should raise_error(TypeError, "no implicit conversion of String into Integer")
end
end
end
diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb
index f4a40502c2..8245cd5470 100644
--- a/spec/ruby/core/array/pack/a_spec.rb
+++ b/spec/ruby/core/array/pack/a_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
@@ -27,7 +27,7 @@ describe "Array#pack with format 'A'" do
["abc"].pack("A*").should == "abc"
end
- it "padds the output with spaces when the count exceeds the size of the String" do
+ it "pads the output with spaces when the count exceeds the size of the String" do
["abc"].pack("A6").should == "abc "
end
@@ -55,7 +55,7 @@ describe "Array#pack with format 'a'" do
["abc"].pack("a*").should == "abc"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("a6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/pack/at_spec.rb b/spec/ruby/core/array/pack/at_spec.rb
index 3942677913..bb9801440a 100644
--- a/spec/ruby/core/array/pack/at_spec.rb
+++ b/spec/ruby/core/array/pack/at_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb
index ec82b7d1ab..247a9ca023 100644
--- a/spec/ruby/core/array/pack/b_spec.rb
+++ b/spec/ruby/core/array/pack/b_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/c_spec.rb b/spec/ruby/core/array/pack/c_spec.rb
index ac133ff9b6..47b71b663d 100644
--- a/spec/ruby/core/array/pack/c_spec.rb
+++ b/spec/ruby/core/array/pack/c_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/array/pack/comment_spec.rb b/spec/ruby/core/array/pack/comment_spec.rb
index 254c827ccc..daf1cff06a 100644
--- a/spec/ruby/core/array/pack/comment_spec.rb
+++ b/spec/ruby/core/array/pack/comment_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/array/pack/h_spec.rb b/spec/ruby/core/array/pack/h_spec.rb
index 2c1dac8d4a..ba188874ba 100644
--- a/spec/ruby/core/array/pack/h_spec.rb
+++ b/spec/ruby/core/array/pack/h_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb
index c6364af12d..a80f91275c 100644
--- a/spec/ruby/core/array/pack/m_spec.rb
+++ b/spec/ruby/core/array/pack/m_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb
index 4b28de7ed0..a63f64d296 100644
--- a/spec/ruby/core/array/pack/shared/basic.rb
+++ b/spec/ruby/core/array/pack/shared/basic.rb
@@ -32,29 +32,16 @@ describe :array_pack_basic_non_float, shared: true do
[@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should be_an_instance_of(String)
end
- ruby_version_is ""..."3.2" do
- it "warns in verbose mode that a directive is unknown" do
- # additional directive ('a') is required for the X directive
- -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/, verbose: true)
- -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/, verbose: true)
- -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/, verbose: true)
- end
- end
-
- ruby_version_is "3.2"..."3.3" do
- # https://bugs.ruby-lang.org/issues/19150
- # NOTE: it's just a plan of the Ruby core team
+ ruby_version_is ""..."3.3" do
it "warns that a directive is unknown" do
# additional directive ('a') is required for the X directive
- -> { [@obj, @obj].pack("a R" + pack_format) }.should complain(/unknown pack directive 'R'/)
- -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0'/)
- -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':'/)
+ -> { [@obj, @obj].pack("a K" + pack_format) }.should complain(/unknown pack directive 'K' in 'a K#{pack_format}'/)
+ -> { [@obj, @obj].pack("a 0" + pack_format) }.should complain(/unknown pack directive '0' in 'a 0#{pack_format}'/)
+ -> { [@obj, @obj].pack("a :" + pack_format) }.should complain(/unknown pack directive ':' in 'a :#{pack_format}'/)
end
end
ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19150
- # NOTE: Added this case just to not forget about the decision in the ticket
it "raise ArgumentError when a directive is unknown" do
# additional directive ('a') is required for the X directive
-> { [@obj, @obj].pack("a R" + pack_format) }.should raise_error(ArgumentError, /unknown pack directive 'R'/)
diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb
index 1780d7635e..76c800b74d 100644
--- a/spec/ruby/core/array/pack/shared/float.rb
+++ b/spec/ruby/core/array/pack/shared/float.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_float_le, shared: true do
it "encodes a positive Float" do
diff --git a/spec/ruby/core/array/pack/shared/integer.rb b/spec/ruby/core/array/pack/shared/integer.rb
index a89b5b733b..61f7cca184 100644
--- a/spec/ruby/core/array/pack/shared/integer.rb
+++ b/spec/ruby/core/array/pack/shared/integer.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_16bit_le, shared: true do
it "encodes the least significant 16 bits of a positive number" do
diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb
index 2f70dc3951..805f78b53b 100644
--- a/spec/ruby/core/array/pack/shared/string.rb
+++ b/spec/ruby/core/array/pack/shared/string.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_string, shared: true do
it "adds count bytes of a String to the output" do
["abc"].pack(pack_format(2)).should == "ab"
diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb
index b20093a647..1f84095ac4 100644
--- a/spec/ruby/core/array/pack/u_spec.rb
+++ b/spec/ruby/core/array/pack/u_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/w_spec.rb b/spec/ruby/core/array/pack/w_spec.rb
index 48ed4496a5..e770288d67 100644
--- a/spec/ruby/core/array/pack/w_spec.rb
+++ b/spec/ruby/core/array/pack/w_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/x_spec.rb b/spec/ruby/core/array/pack/x_spec.rb
index 86c3ad1aa4..012fe4567f 100644
--- a/spec/ruby/core/array/pack/x_spec.rb
+++ b/spec/ruby/core/array/pack/x_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb
index 5ad3afd69e..60f8f7bf10 100644
--- a/spec/ruby/core/array/pack/z_spec.rb
+++ b/spec/ruby/core/array/pack/z_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
@@ -26,7 +26,7 @@ describe "Array#pack with format 'Z'" do
["abc"].pack("Z*").should == "abc\x00"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("Z6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
index d2866970a5..b80261d32f 100644
--- a/spec/ruby/core/array/shared/slice.rb
+++ b/spec/ruby/core/array/shared/slice.rb
@@ -754,99 +754,97 @@ describe :array_slice, shared: true do
a.send(@method, (...-9)).should == []
end
- ruby_version_is "3.2" do
- describe "can be sliced with Enumerator::ArithmeticSequence" do
- it "with infinite/inverted ranges and negative steps" do
- @array = [0, 1, 2, 3, 4, 5]
- @array.send(@method, (2..).step(-1)).should == [2, 1, 0]
- @array.send(@method, (2..).step(-2)).should == [2, 0]
- @array.send(@method, (2..).step(-3)).should == [2]
- @array.send(@method, (2..).step(-4)).should == [2]
-
- @array.send(@method, (-3..).step(-1)).should == [3, 2, 1, 0]
- @array.send(@method, (-3..).step(-2)).should == [3, 1]
- @array.send(@method, (-3..).step(-3)).should == [3, 0]
- @array.send(@method, (-3..).step(-4)).should == [3]
- @array.send(@method, (-3..).step(-5)).should == [3]
-
- @array.send(@method, (..0).step(-1)).should == [5, 4, 3, 2, 1, 0]
- @array.send(@method, (..0).step(-2)).should == [5, 3, 1]
- @array.send(@method, (..0).step(-3)).should == [5, 2]
- @array.send(@method, (..0).step(-4)).should == [5, 1]
- @array.send(@method, (..0).step(-5)).should == [5, 0]
- @array.send(@method, (..0).step(-6)).should == [5]
- @array.send(@method, (..0).step(-7)).should == [5]
-
- @array.send(@method, (...0).step(-1)).should == [5, 4, 3, 2, 1]
- @array.send(@method, (...0).step(-2)).should == [5, 3, 1]
- @array.send(@method, (...0).step(-3)).should == [5, 2]
- @array.send(@method, (...0).step(-4)).should == [5, 1]
- @array.send(@method, (...0).step(-5)).should == [5]
- @array.send(@method, (...0).step(-6)).should == [5]
-
- @array.send(@method, (...1).step(-1)).should == [5, 4, 3, 2]
- @array.send(@method, (...1).step(-2)).should == [5, 3]
- @array.send(@method, (...1).step(-3)).should == [5, 2]
- @array.send(@method, (...1).step(-4)).should == [5]
- @array.send(@method, (...1).step(-5)).should == [5]
-
- @array.send(@method, (..-5).step(-1)).should == [5, 4, 3, 2, 1]
- @array.send(@method, (..-5).step(-2)).should == [5, 3, 1]
- @array.send(@method, (..-5).step(-3)).should == [5, 2]
- @array.send(@method, (..-5).step(-4)).should == [5, 1]
- @array.send(@method, (..-5).step(-5)).should == [5]
- @array.send(@method, (..-5).step(-6)).should == [5]
-
- @array.send(@method, (...-5).step(-1)).should == [5, 4, 3, 2]
- @array.send(@method, (...-5).step(-2)).should == [5, 3]
- @array.send(@method, (...-5).step(-3)).should == [5, 2]
- @array.send(@method, (...-5).step(-4)).should == [5]
- @array.send(@method, (...-5).step(-5)).should == [5]
-
- @array.send(@method, (4..1).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (4..1).step(-2)).should == [4, 2]
- @array.send(@method, (4..1).step(-3)).should == [4, 1]
- @array.send(@method, (4..1).step(-4)).should == [4]
- @array.send(@method, (4..1).step(-5)).should == [4]
-
- @array.send(@method, (4...1).step(-1)).should == [4, 3, 2]
- @array.send(@method, (4...1).step(-2)).should == [4, 2]
- @array.send(@method, (4...1).step(-3)).should == [4]
- @array.send(@method, (4...1).step(-4)).should == [4]
-
- @array.send(@method, (-2..1).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (-2..1).step(-2)).should == [4, 2]
- @array.send(@method, (-2..1).step(-3)).should == [4, 1]
- @array.send(@method, (-2..1).step(-4)).should == [4]
- @array.send(@method, (-2..1).step(-5)).should == [4]
-
- @array.send(@method, (-2...1).step(-1)).should == [4, 3, 2]
- @array.send(@method, (-2...1).step(-2)).should == [4, 2]
- @array.send(@method, (-2...1).step(-3)).should == [4]
- @array.send(@method, (-2...1).step(-4)).should == [4]
-
- @array.send(@method, (4..-5).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (4..-5).step(-2)).should == [4, 2]
- @array.send(@method, (4..-5).step(-3)).should == [4, 1]
- @array.send(@method, (4..-5).step(-4)).should == [4]
- @array.send(@method, (4..-5).step(-5)).should == [4]
-
- @array.send(@method, (4...-5).step(-1)).should == [4, 3, 2]
- @array.send(@method, (4...-5).step(-2)).should == [4, 2]
- @array.send(@method, (4...-5).step(-3)).should == [4]
- @array.send(@method, (4...-5).step(-4)).should == [4]
-
- @array.send(@method, (-2..-5).step(-1)).should == [4, 3, 2, 1]
- @array.send(@method, (-2..-5).step(-2)).should == [4, 2]
- @array.send(@method, (-2..-5).step(-3)).should == [4, 1]
- @array.send(@method, (-2..-5).step(-4)).should == [4]
- @array.send(@method, (-2..-5).step(-5)).should == [4]
-
- @array.send(@method, (-2...-5).step(-1)).should == [4, 3, 2]
- @array.send(@method, (-2...-5).step(-2)).should == [4, 2]
- @array.send(@method, (-2...-5).step(-3)).should == [4]
- @array.send(@method, (-2...-5).step(-4)).should == [4]
- end
+ describe "can be sliced with Enumerator::ArithmeticSequence" do
+ it "with infinite/inverted ranges and negative steps" do
+ @array = [0, 1, 2, 3, 4, 5]
+ @array.send(@method, (2..).step(-1)).should == [2, 1, 0]
+ @array.send(@method, (2..).step(-2)).should == [2, 0]
+ @array.send(@method, (2..).step(-3)).should == [2]
+ @array.send(@method, (2..).step(-4)).should == [2]
+
+ @array.send(@method, (-3..).step(-1)).should == [3, 2, 1, 0]
+ @array.send(@method, (-3..).step(-2)).should == [3, 1]
+ @array.send(@method, (-3..).step(-3)).should == [3, 0]
+ @array.send(@method, (-3..).step(-4)).should == [3]
+ @array.send(@method, (-3..).step(-5)).should == [3]
+
+ @array.send(@method, (..0).step(-1)).should == [5, 4, 3, 2, 1, 0]
+ @array.send(@method, (..0).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (..0).step(-3)).should == [5, 2]
+ @array.send(@method, (..0).step(-4)).should == [5, 1]
+ @array.send(@method, (..0).step(-5)).should == [5, 0]
+ @array.send(@method, (..0).step(-6)).should == [5]
+ @array.send(@method, (..0).step(-7)).should == [5]
+
+ @array.send(@method, (...0).step(-1)).should == [5, 4, 3, 2, 1]
+ @array.send(@method, (...0).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (...0).step(-3)).should == [5, 2]
+ @array.send(@method, (...0).step(-4)).should == [5, 1]
+ @array.send(@method, (...0).step(-5)).should == [5]
+ @array.send(@method, (...0).step(-6)).should == [5]
+
+ @array.send(@method, (...1).step(-1)).should == [5, 4, 3, 2]
+ @array.send(@method, (...1).step(-2)).should == [5, 3]
+ @array.send(@method, (...1).step(-3)).should == [5, 2]
+ @array.send(@method, (...1).step(-4)).should == [5]
+ @array.send(@method, (...1).step(-5)).should == [5]
+
+ @array.send(@method, (..-5).step(-1)).should == [5, 4, 3, 2, 1]
+ @array.send(@method, (..-5).step(-2)).should == [5, 3, 1]
+ @array.send(@method, (..-5).step(-3)).should == [5, 2]
+ @array.send(@method, (..-5).step(-4)).should == [5, 1]
+ @array.send(@method, (..-5).step(-5)).should == [5]
+ @array.send(@method, (..-5).step(-6)).should == [5]
+
+ @array.send(@method, (...-5).step(-1)).should == [5, 4, 3, 2]
+ @array.send(@method, (...-5).step(-2)).should == [5, 3]
+ @array.send(@method, (...-5).step(-3)).should == [5, 2]
+ @array.send(@method, (...-5).step(-4)).should == [5]
+ @array.send(@method, (...-5).step(-5)).should == [5]
+
+ @array.send(@method, (4..1).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (4..1).step(-2)).should == [4, 2]
+ @array.send(@method, (4..1).step(-3)).should == [4, 1]
+ @array.send(@method, (4..1).step(-4)).should == [4]
+ @array.send(@method, (4..1).step(-5)).should == [4]
+
+ @array.send(@method, (4...1).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (4...1).step(-2)).should == [4, 2]
+ @array.send(@method, (4...1).step(-3)).should == [4]
+ @array.send(@method, (4...1).step(-4)).should == [4]
+
+ @array.send(@method, (-2..1).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (-2..1).step(-2)).should == [4, 2]
+ @array.send(@method, (-2..1).step(-3)).should == [4, 1]
+ @array.send(@method, (-2..1).step(-4)).should == [4]
+ @array.send(@method, (-2..1).step(-5)).should == [4]
+
+ @array.send(@method, (-2...1).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (-2...1).step(-2)).should == [4, 2]
+ @array.send(@method, (-2...1).step(-3)).should == [4]
+ @array.send(@method, (-2...1).step(-4)).should == [4]
+
+ @array.send(@method, (4..-5).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (4..-5).step(-2)).should == [4, 2]
+ @array.send(@method, (4..-5).step(-3)).should == [4, 1]
+ @array.send(@method, (4..-5).step(-4)).should == [4]
+ @array.send(@method, (4..-5).step(-5)).should == [4]
+
+ @array.send(@method, (4...-5).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (4...-5).step(-2)).should == [4, 2]
+ @array.send(@method, (4...-5).step(-3)).should == [4]
+ @array.send(@method, (4...-5).step(-4)).should == [4]
+
+ @array.send(@method, (-2..-5).step(-1)).should == [4, 3, 2, 1]
+ @array.send(@method, (-2..-5).step(-2)).should == [4, 2]
+ @array.send(@method, (-2..-5).step(-3)).should == [4, 1]
+ @array.send(@method, (-2..-5).step(-4)).should == [4]
+ @array.send(@method, (-2..-5).step(-5)).should == [4]
+
+ @array.send(@method, (-2...-5).step(-1)).should == [4, 3, 2]
+ @array.send(@method, (-2...-5).step(-2)).should == [4, 2]
+ @array.send(@method, (-2...-5).step(-3)).should == [4]
+ @array.send(@method, (-2...-5).step(-4)).should == [4]
end
end
diff --git a/spec/ruby/core/array/shared/unshift.rb b/spec/ruby/core/array/shared/unshift.rb
index 4941e098f6..9e0fe7556a 100644
--- a/spec/ruby/core/array/shared/unshift.rb
+++ b/spec/ruby/core/array/shared/unshift.rb
@@ -49,7 +49,7 @@ describe :array_unshift, shared: true do
-> { ArraySpecs.frozen_array.send(@method) }.should raise_error(FrozenError)
end
- # https://github.com/oracle/truffleruby/issues/2772
+ # https://github.com/truffleruby/truffleruby/issues/2772
it "doesn't rely on Array#[]= so it can be overridden" do
subclass = Class.new(Array) do
def []=(*)
diff --git a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
index eaf311783a..13e066cc7f 100644
--- a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
+++ b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
@@ -46,6 +46,16 @@ describe "RUBY_ENGINE" do
end
end
+describe "RUBY_ENGINE_VERSION" do
+ it "is a String" do
+ RUBY_ENGINE_VERSION.should be_kind_of(String)
+ end
+
+ it "is frozen" do
+ RUBY_ENGINE_VERSION.should.frozen?
+ end
+end
+
describe "RUBY_PLATFORM" do
it "is a String" do
RUBY_PLATFORM.should be_kind_of(String)
@@ -75,3 +85,67 @@ describe "RUBY_REVISION" do
RUBY_REVISION.should.frozen?
end
end
+
+ruby_version_is "4.0" do
+ context "The constant" do
+ describe "Ruby" do
+ it "is a Module" do
+ Ruby.should.instance_of?(Module)
+ end
+ end
+
+ describe "Ruby::VERSION" do
+ it "is equal to RUBY_VERSION" do
+ Ruby::VERSION.should equal(RUBY_VERSION)
+ end
+ end
+
+ describe "RUBY::PATCHLEVEL" do
+ it "is equal to RUBY_PATCHLEVEL" do
+ Ruby::PATCHLEVEL.should equal(RUBY_PATCHLEVEL)
+ end
+ end
+
+ describe "Ruby::COPYRIGHT" do
+ it "is equal to RUBY_COPYRIGHT" do
+ Ruby::COPYRIGHT.should equal(RUBY_COPYRIGHT)
+ end
+ end
+
+ describe "Ruby::DESCRIPTION" do
+ it "is equal to RUBY_DESCRIPTION" do
+ Ruby::DESCRIPTION.should equal(RUBY_DESCRIPTION)
+ end
+ end
+
+ describe "Ruby::ENGINE" do
+ it "is equal to RUBY_ENGINE" do
+ Ruby::ENGINE.should equal(RUBY_ENGINE)
+ end
+ end
+
+ describe "Ruby::ENGINE_VERSION" do
+ it "is equal to RUBY_ENGINE_VERSION" do
+ Ruby::ENGINE_VERSION.should equal(RUBY_ENGINE_VERSION)
+ end
+ end
+
+ describe "Ruby::PLATFORM" do
+ it "is equal to RUBY_PLATFORM" do
+ Ruby::PLATFORM.should equal(RUBY_PLATFORM)
+ end
+ end
+
+ describe "Ruby::RELEASE_DATE" do
+ it "is equal to RUBY_RELEASE_DATE" do
+ Ruby::RELEASE_DATE.should equal(RUBY_RELEASE_DATE)
+ end
+ end
+
+ describe "Ruby::REVISION" do
+ it "is equal to RUBY_REVISION" do
+ Ruby::REVISION.should equal(RUBY_REVISION)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/class/attached_object_spec.rb b/spec/ruby/core/class/attached_object_spec.rb
index f1c0f63a44..8f8a0734c6 100644
--- a/spec/ruby/core/class/attached_object_spec.rb
+++ b/spec/ruby/core/class/attached_object_spec.rb
@@ -1,31 +1,29 @@
require_relative '../../spec_helper'
-ruby_version_is '3.2' do
- describe "Class#attached_object" do
- it "returns the object that is attached to a singleton class" do
- a = Class.new
+describe "Class#attached_object" do
+ it "returns the object that is attached to a singleton class" do
+ a = Class.new
- a_obj = a.new
- a_obj.singleton_class.attached_object.should == a_obj
- end
+ a_obj = a.new
+ a_obj.singleton_class.attached_object.should == a_obj
+ end
- it "returns the class object that is attached to a class's singleton class" do
- a = Class.new
- singleton_class = (class << a; self; end)
+ it "returns the class object that is attached to a class's singleton class" do
+ a = Class.new
+ singleton_class = (class << a; self; end)
- singleton_class.attached_object.should == a
- end
+ singleton_class.attached_object.should == a
+ end
- it "raises TypeError if the class is not a singleton class" do
- a = Class.new
+ it "raises TypeError if the class is not a singleton class" do
+ a = Class.new
- -> { a.attached_object }.should raise_error(TypeError, /is not a singleton class/)
- end
+ -> { a.attached_object }.should raise_error(TypeError, /is not a singleton class/)
+ end
- it "raises TypeError for special singleton classes" do
- -> { nil.singleton_class.attached_object }.should raise_error(TypeError, /[`']NilClass' is not a singleton class/)
- -> { true.singleton_class.attached_object }.should raise_error(TypeError, /[`']TrueClass' is not a singleton class/)
- -> { false.singleton_class.attached_object }.should raise_error(TypeError, /[`']FalseClass' is not a singleton class/)
- end
+ it "raises TypeError for special singleton classes" do
+ -> { nil.singleton_class.attached_object }.should raise_error(TypeError, /[`']NilClass' is not a singleton class/)
+ -> { true.singleton_class.attached_object }.should raise_error(TypeError, /[`']TrueClass' is not a singleton class/)
+ -> { false.singleton_class.attached_object }.should raise_error(TypeError, /[`']FalseClass' is not a singleton class/)
end
end
diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb
index 8ef8bb8c35..2a8d1ff813 100644
--- a/spec/ruby/core/class/inherited_spec.rb
+++ b/spec/ruby/core/class/inherited_spec.rb
@@ -98,4 +98,21 @@ describe "Class.inherited" do
-> { Class.new(top) }.should_not raise_error
end
+ it "if the subclass is assigned to a constant, it is all set" do
+ ScratchPad.record []
+
+ parent = Class.new do
+ def self.inherited(subclass)
+ ScratchPad << defined?(self::C)
+ ScratchPad << const_defined?(:C)
+ ScratchPad << constants
+ ScratchPad << const_get(:C)
+ ScratchPad << subclass.name.match?(/\A#<Class:0x\w+>::C\z/)
+ end
+ end
+
+ class parent::C < parent; end
+
+ ScratchPad.recorded.should == ["constant", true, [:C], parent::C, true]
+ end
end
diff --git a/spec/ruby/core/comparable/clamp_spec.rb b/spec/ruby/core/comparable/clamp_spec.rb
index 796d4a18c1..18f616a997 100644
--- a/spec/ruby/core/comparable/clamp_spec.rb
+++ b/spec/ruby/core/comparable/clamp_spec.rb
@@ -24,7 +24,7 @@ describe 'Comparable#clamp' do
c.clamp(two, three).should equal(c)
end
- it 'returns the min parameter if smaller than it' do
+ it 'returns the min parameter if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(0)
@@ -40,6 +40,39 @@ describe 'Comparable#clamp' do
c.clamp(one, two).should equal(two)
end
+ context 'max is nil' do
+ it 'returns min if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(0)
+ c.clamp(one, nil).should equal(one)
+ end
+
+ it 'always returns self if greater than min' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+ c.clamp(one, nil).should equal(c)
+ end
+ end
+
+ context 'min is nil' do
+ it 'returns max if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+ c.clamp(nil, one).should equal(one)
+ end
+
+ it 'always returns self if less than max' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(0)
+ c.clamp(nil, one).should equal(c)
+ end
+ end
+
+ it 'always returns self when min is nil and max is nil' do
+ c = ComparableSpecs::Weird.new(1)
+ c.clamp(nil, nil).should equal(c)
+ end
+
it 'returns self if within the given range parameters' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
@@ -52,7 +85,7 @@ describe 'Comparable#clamp' do
c.clamp(two..three).should equal(c)
end
- it 'returns the minimum value of the range parameters if smaller than it' do
+ it 'returns the minimum value of the range parameters if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(0)
@@ -75,4 +108,116 @@ describe 'Comparable#clamp' do
-> { c.clamp(one...two) }.should raise_error(ArgumentError)
end
+
+ context 'with nil as the max argument' do
+ it 'returns min argument if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one, nil).should equal(one)
+ c.clamp(zero, nil).should equal(c)
+ end
+
+ it 'always returns self if greater than min argument' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one, nil).should equal(c)
+ c.clamp(two, nil).should equal(c)
+ end
+ end
+
+ context 'with endless range' do
+ it 'returns minimum value of the range parameters if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one..).should equal(one)
+ c.clamp(zero..).should equal(c)
+ end
+
+ it 'always returns self if greater than minimum value of the range parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one..).should equal(c)
+ c.clamp(two..).should equal(c)
+ end
+
+ it 'works with exclusive range' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one...).should equal(c)
+ end
+ end
+
+ context 'with nil as the min argument' do
+ it 'returns max argument if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(nil, one).should equal(one)
+ end
+
+ it 'always returns self if less than max argument' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(nil, one).should equal(c)
+ c.clamp(nil, zero).should equal(c)
+ end
+ end
+
+ context 'with beginless range' do
+ it 'returns maximum value of the range parameters if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(..one).should equal(one)
+ end
+
+ it 'always returns self if less than maximum value of the range parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(..one).should equal(c)
+ c.clamp(..zero).should equal(c)
+ end
+
+ it 'raises an Argument error if the range parameter is exclusive' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(0)
+
+ -> { c.clamp(...one) }.should raise_error(ArgumentError)
+ end
+ end
+
+ context 'with nil as the min and the max argument' do
+ it 'always returns self' do
+ c = ComparableSpecs::Weird.new(1)
+
+ c.clamp(nil, nil).should equal(c)
+ end
+ end
+
+ context 'with beginless-and-endless range' do
+ it 'always returns self' do
+ c = ComparableSpecs::Weird.new(1)
+
+ c.clamp(nil..nil).should equal(c)
+ end
+
+ it 'works with exclusive range' do
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(nil...nil).should equal(c)
+ end
+ end
end
diff --git a/spec/ruby/core/comparable/fixtures/classes.rb b/spec/ruby/core/comparable/fixtures/classes.rb
index 4239a47d2f..2bdabbf014 100644
--- a/spec/ruby/core/comparable/fixtures/classes.rb
+++ b/spec/ruby/core/comparable/fixtures/classes.rb
@@ -7,6 +7,7 @@ module ComparableSpecs
end
def <=>(other)
+ return nil if other.nil?
self.value <=> other.value
end
end
diff --git a/spec/ruby/core/complex/polar_spec.rb b/spec/ruby/core/complex/polar_spec.rb
index 3bb3751bc6..56335584ef 100644
--- a/spec/ruby/core/complex/polar_spec.rb
+++ b/spec/ruby/core/complex/polar_spec.rb
@@ -11,20 +11,18 @@ describe "Complex.polar" do
->{ Complex.polar(nil, nil) }.should raise_error(TypeError)
end
- ruby_bug "#19004", ""..."3.2" do
- it "computes the real values of the real & imaginary parts from the polar form" do
- a = Complex.polar(1.0+0.0i, Math::PI/2+0.0i)
- a.real.should be_close(0.0, TOLERANCE)
- a.imag.should be_close(1.0, TOLERANCE)
- a.real.real?.should be_true
- a.imag.real?.should be_true
+ it "computes the real values of the real & imaginary parts from the polar form" do
+ a = Complex.polar(1.0+0.0i, Math::PI/2+0.0i)
+ a.real.should be_close(0.0, TOLERANCE)
+ a.imag.should be_close(1.0, TOLERANCE)
+ a.real.real?.should be_true
+ a.imag.real?.should be_true
- b = Complex.polar(1+0.0i)
- b.real.should be_close(1.0, TOLERANCE)
- b.imag.should be_close(0.0, TOLERANCE)
- b.real.real?.should be_true
- b.imag.real?.should be_true
- end
+ b = Complex.polar(1+0.0i)
+ b.real.should be_close(1.0, TOLERANCE)
+ b.imag.should be_close(0.0, TOLERANCE)
+ b.real.real?.should be_true
+ b.imag.real?.should be_true
end
end
diff --git a/spec/ruby/core/data/constants_spec.rb b/spec/ruby/core/data/constants_spec.rb
index 2eb43d501e..ad0b1ddea7 100644
--- a/spec/ruby/core/data/constants_spec.rb
+++ b/spec/ruby/core/data/constants_spec.rb
@@ -1,21 +1,11 @@
require_relative '../../spec_helper'
-ruby_version_is ''...'3.2' do
- describe "Data" do
- it "does not exist anymore" do
- Object.should_not have_constant(:Data)
- end
+describe "Data" do
+ it "is a new constant" do
+ Data.superclass.should == Object
end
-end
-
-ruby_version_is '3.2' do
- describe "Data" do
- it "is a new constant" do
- Data.superclass.should == Object
- end
- it "is not deprecated" do
- -> { Data }.should_not complain
- end
+ it "is not deprecated" do
+ -> { Data }.should_not complain
end
end
diff --git a/spec/ruby/core/data/deconstruct_keys_spec.rb b/spec/ruby/core/data/deconstruct_keys_spec.rb
index 07af87771d..df378f8b98 100644
--- a/spec/ruby/core/data/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/data/deconstruct_keys_spec.rb
@@ -1,107 +1,130 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#deconstruct" do
- it "returns a hash of attributes" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
- d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
- end
-
- it "requires one argument" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- -> {
- d.deconstruct_keys
- }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
- end
-
- it "returns only specified keys" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
- d.deconstruct_keys([:x] ).should == {x: 1}
- d.deconstruct_keys([] ).should == {}
- end
-
- it "accepts string attribute names" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
- d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
- end
-
- it "accepts argument position number as well but returns them as keys" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([0, 1]).should == {0 => 1, 1 => 2}
- d.deconstruct_keys([0] ).should == {0 => 1}
- d.deconstruct_keys([-1] ).should == {-1 => 2}
- end
-
- it "ignores incorrect position numbers" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([0, 3]).should == {0 => 1}
- end
-
- it "support mixing attribute names and argument position numbers" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([0, :x]).should == {0 => 1, :x => 1}
- end
-
- it "returns an empty hash when there are more keys than attributes" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
- d.deconstruct_keys([:x, :y, :x]).should == {}
- end
-
- it "returns at first not existing attribute name" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([:a, :x]).should == {}
- d.deconstruct_keys([:x, :a]).should == {x: 1}
- end
-
- it "returns at first not existing argument position number" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys([3, 0]).should == {}
- d.deconstruct_keys([0, 3]).should == {0 => 1}
- end
-
- it "accepts nil argument and return all the attributes" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- d.deconstruct_keys(nil).should == {x: 1, y: 2}
- end
-
- it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- -> {
- d.deconstruct_keys([0, []])
- }.should raise_error(TypeError, "no implicit conversion of Array into Integer")
- end
-
- it "raise TypeError if passed anything except nil or array" do
- klass = Data.define(:x, :y)
- d = klass.new(1, 2)
-
- -> { d.deconstruct_keys('x') }.should raise_error(TypeError, /expected Array or nil/)
- -> { d.deconstruct_keys(1) }.should raise_error(TypeError, /expected Array or nil/)
- -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, /expected Array or nil/)
- -> { d.deconstruct_keys({}) }.should raise_error(TypeError, /expected Array or nil/)
- end
+describe "Data#deconstruct_keys" do
+ it "returns a hash of attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ end
+
+ it "requires one argument" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> {
+ d.deconstruct_keys
+ }.should raise_error(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
+
+ it "returns only specified keys" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ d.deconstruct_keys([:x] ).should == {x: 1}
+ d.deconstruct_keys([] ).should == {}
+ end
+
+ it "accepts string attribute names" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
+ end
+
+ it "accepts argument position number as well but returns them as keys" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([0, 1]).should == {0 => 1, 1 => 2}
+ d.deconstruct_keys([0] ).should == {0 => 1}
+ d.deconstruct_keys([-1] ).should == {-1 => 2}
+ end
+
+ it "ignores incorrect position numbers" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([0, 3]).should == {0 => 1}
+ end
+
+ it "support mixing attribute names and argument position numbers" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([0, :x]).should == {0 => 1, :x => 1}
+ end
+
+ it "returns an empty hash when there are more keys than attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y, :x]).should == {}
+ end
+
+ it "returns at first not existing attribute name" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:a, :x]).should == {}
+ d.deconstruct_keys([:x, :a]).should == {x: 1}
+ end
+
+ it "returns at first not existing argument position number" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([3, 0]).should == {}
+ d.deconstruct_keys([0, 3]).should == {0 => 1}
+ end
+
+ it "accepts nil argument and return all the attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys(nil).should == {x: 1, y: 2}
+ end
+
+ it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return(1)
+
+ d.deconstruct_keys([key]).should == { key => 2 }
+ end
+
+ it "raises a TypeError if the conversion with #to_int does not return an Integer" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return("not an Integer")
+
+ -> {
+ d.deconstruct_keys([key])
+ }.should raise_error(TypeError, /can't convert MockObject to Integer/)
+ end
+
+ it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> {
+ d.deconstruct_keys([0, []])
+ }.should raise_error(TypeError, "no implicit conversion of Array into Integer")
+ end
+
+ it "raise TypeError if passed anything except nil or array" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> { d.deconstruct_keys('x') }.should raise_error(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys(1) }.should raise_error(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys({}) }.should raise_error(TypeError, /expected Array or nil/)
end
end
diff --git a/spec/ruby/core/data/deconstruct_spec.rb b/spec/ruby/core/data/deconstruct_spec.rb
index f0995e8fed..4ca0b87039 100644
--- a/spec/ruby/core/data/deconstruct_spec.rb
+++ b/spec/ruby/core/data/deconstruct_spec.rb
@@ -1,10 +1,8 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#deconstruct" do
- it "returns an array of attribute values" do
- DataSpecs::Measure.new(42, "km").deconstruct.should == [42, "km"]
- end
+describe "Data#deconstruct" do
+ it "returns an array of attribute values" do
+ DataSpecs::Measure.new(42, "km").deconstruct.should == [42, "km"]
end
end
diff --git a/spec/ruby/core/data/define_spec.rb b/spec/ruby/core/data/define_spec.rb
index 2aa2c50d4c..c0b4671e39 100644
--- a/spec/ruby/core/data/define_spec.rb
+++ b/spec/ruby/core/data/define_spec.rb
@@ -1,36 +1,34 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data.define" do
- it "accepts no arguments" do
- empty_data = Data.define
- empty_data.members.should == []
- end
+describe "Data.define" do
+ it "accepts no arguments" do
+ empty_data = Data.define
+ empty_data.members.should == []
+ end
- it "accepts symbols" do
- movie = Data.define(:title, :year)
- movie.members.should == [:title, :year]
- end
+ it "accepts symbols" do
+ movie = Data.define(:title, :year)
+ movie.members.should == [:title, :year]
+ end
- it "accepts strings" do
- movie = Data.define("title", "year")
- movie.members.should == [:title, :year]
- end
+ it "accepts strings" do
+ movie = Data.define("title", "year")
+ movie.members.should == [:title, :year]
+ end
- it "accepts a mix of strings and symbols" do
- movie = Data.define("title", :year, "genre")
- movie.members.should == [:title, :year, :genre]
- end
+ it "accepts a mix of strings and symbols" do
+ movie = Data.define("title", :year, "genre")
+ movie.members.should == [:title, :year, :genre]
+ end
- it "accepts a block" do
- movie = Data.define(:title, :year) do
- def title_with_year
- "#{title} (#{year})"
- end
+ it "accepts a block" do
+ movie = Data.define(:title, :year) do
+ def title_with_year
+ "#{title} (#{year})"
end
- movie.members.should == [:title, :year]
- movie.new("Matrix", 1999).title_with_year.should == "Matrix (1999)"
end
+ movie.members.should == [:title, :year]
+ movie.new("Matrix", 1999).title_with_year.should == "Matrix (1999)"
end
end
diff --git a/spec/ruby/core/data/eql_spec.rb b/spec/ruby/core/data/eql_spec.rb
index 906e46316c..6958d5de4a 100644
--- a/spec/ruby/core/data/eql_spec.rb
+++ b/spec/ruby/core/data/eql_spec.rb
@@ -1,65 +1,63 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#eql?" do
- it "returns true if the other is the same object" do
- a = DataSpecs::Measure.new(42, "km")
- a.should.eql?(a)
- end
+describe "Data#eql?" do
+ it "returns true if the other is the same object" do
+ a = DataSpecs::Measure.new(42, "km")
+ a.should.eql?(a)
+ end
- it "returns true if the other has all the same fields" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "km")
- a.should.eql?(b)
- end
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.should.eql?(b)
+ end
- it "returns false if the other is a different object or has different fields" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "mi")
- a.should_not.eql?(b)
- end
+ it "returns false if the other is a different object or has different fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "mi")
+ a.should_not.eql?(b)
+ end
- it "returns false if other is of a different class" do
- a = DataSpecs::Measure.new(42, "km")
- klass = Data.define(*DataSpecs::Measure.members)
- b = klass.new(42, "km")
- a.should_not.eql?(b)
- end
+ it "returns false if other is of a different class" do
+ a = DataSpecs::Measure.new(42, "km")
+ klass = Data.define(*DataSpecs::Measure.members)
+ b = klass.new(42, "km")
+ a.should_not.eql?(b)
+ end
- it "returns false if any corresponding elements are not equal with #eql?" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42.0, "mi")
- a.should_not.eql?(b)
- end
+ it "returns false if any corresponding elements are not equal with #eql?" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42.0, "mi")
+ a.should_not.eql?(b)
+ end
- context "recursive structure" do
- it "returns true the other is the same object" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: 42, unit: a)
+ context "recursive structure" do
+ it "returns true the other is the same object" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
- a.should.eql?(a)
- end
+ a.should.eql?(a)
+ end
- it "returns true if the other has all the same fields" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: 42, unit: a)
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
- b = DataSpecs::Measure.allocate
- b.send(:initialize, amount: 42, unit: b)
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: 42, unit: b)
- a.should.eql?(b)
- end
+ a.should.eql?(b)
+ end
- it "returns false if any corresponding elements are not equal with #eql?" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: a, unit: "km")
+ it "returns false if any corresponding elements are not equal with #eql?" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: a, unit: "km")
- b = DataSpecs::Measure.allocate
- b.send(:initialize, amount: b, unit: "mi")
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: b, unit: "mi")
- a.should_not.eql?(b)
- end
+ a.should_not.eql?(b)
end
end
end
diff --git a/spec/ruby/core/data/equal_value_spec.rb b/spec/ruby/core/data/equal_value_spec.rb
index f90a7d7a62..d9a0dcff3e 100644
--- a/spec/ruby/core/data/equal_value_spec.rb
+++ b/spec/ruby/core/data/equal_value_spec.rb
@@ -1,65 +1,63 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#==" do
- it "returns true if the other is the same object" do
- a = DataSpecs::Measure.new(42, "km")
- a.should == a
- end
+describe "Data#==" do
+ it "returns true if the other is the same object" do
+ a = DataSpecs::Measure.new(42, "km")
+ a.should == a
+ end
- it "returns true if the other has all the same fields" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "km")
- a.should == b
- end
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.should == b
+ end
- it "returns false if the other is a different object or has different fields" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "mi")
- a.should_not == b
- end
+ it "returns false if the other is a different object or has different fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "mi")
+ a.should_not == b
+ end
- it "returns false if other is of a different class" do
- a = DataSpecs::Measure.new(42, "km")
- klass = Data.define(*DataSpecs::Measure.members)
- b = klass.new(42, "km")
- a.should_not == b
- end
+ it "returns false if other is of a different class" do
+ a = DataSpecs::Measure.new(42, "km")
+ klass = Data.define(*DataSpecs::Measure.members)
+ b = klass.new(42, "km")
+ a.should_not == b
+ end
- it "returns false if any corresponding elements are not equal with #==" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42.0, "mi")
- a.should_not == b
- end
+ it "returns false if any corresponding elements are not equal with #==" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42.0, "mi")
+ a.should_not == b
+ end
- context "recursive structure" do
- it "returns true the other is the same object" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: 42, unit: a)
+ context "recursive structure" do
+ it "returns true the other is the same object" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
- a.should == a
- end
+ a.should == a
+ end
- it "returns true if the other has all the same fields" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: 42, unit: a)
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
- b = DataSpecs::Measure.allocate
- b.send(:initialize, amount: 42, unit: b)
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: 42, unit: b)
- a.should == b
- end
+ a.should == b
+ end
- it "returns false if any corresponding elements are not equal with #==" do
- a = DataSpecs::Measure.allocate
- a.send(:initialize, amount: a, unit: "km")
+ it "returns false if any corresponding elements are not equal with #==" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: a, unit: "km")
- b = DataSpecs::Measure.allocate
- b.send(:initialize, amount: b, unit: "mi")
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: b, unit: "mi")
- a.should_not == b
- end
+ a.should_not == b
end
end
end
diff --git a/spec/ruby/core/data/fixtures/classes.rb b/spec/ruby/core/data/fixtures/classes.rb
index f0a526517d..650c0b2a62 100644
--- a/spec/ruby/core/data/fixtures/classes.rb
+++ b/spec/ruby/core/data/fixtures/classes.rb
@@ -1,5 +1,5 @@
module DataSpecs
- guard -> { ruby_version_is "3.2" and Data.respond_to?(:define) } do
+ if Data.respond_to?(:define)
Measure = Data.define(:amount, :unit)
class MeasureWithOverriddenName < Measure
@@ -9,5 +9,26 @@ module DataSpecs
end
class DataSubclass < Data; end
+
+ MeasureSubclass = Class.new(Measure) do
+ def initialize(amount:, unit:)
+ super
+ end
+ end
+
+ Empty = Data.define()
+
+ DataWithOverriddenInitialize = Data.define(:amount, :unit) do
+ def initialize(*rest, **kw)
+ super
+ ScratchPad.record [:initialize, rest, kw]
+ end
+ end
+
+ Area = Data.define(:width, :height, :area) do
+ def initialize(width:, height:)
+ super(width: width, height: height, area: width * height)
+ end
+ end
end
end
diff --git a/spec/ruby/core/data/hash_spec.rb b/spec/ruby/core/data/hash_spec.rb
index 324a2abca4..c23f08a71d 100644
--- a/spec/ruby/core/data/hash_spec.rb
+++ b/spec/ruby/core/data/hash_spec.rb
@@ -1,27 +1,25 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#hash" do
- it "returns the same integer for objects with the same content" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "km")
- a.hash.should == b.hash
- a.hash.should be_an_instance_of(Integer)
- end
+describe "Data#hash" do
+ it "returns the same integer for objects with the same content" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.hash.should == b.hash
+ a.hash.should be_an_instance_of(Integer)
+ end
- it "returns different hashes for objects with different values" do
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(42, "ml")
- a.hash.should_not == b.hash
+ it "returns different hashes for objects with different values" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "ml")
+ a.hash.should_not == b.hash
- a = DataSpecs::Measure.new(42, "km")
- b = DataSpecs::Measure.new(13, "km")
- a.hash.should_not == b.hash
- end
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(13, "km")
+ a.hash.should_not == b.hash
+ end
- it "returns different hashes for different classes" do
- Data.define(:x).new(1).hash.should != Data.define(:x).new(1).hash
- end
+ it "returns different hashes for different classes" do
+ Data.define(:x).new(1).hash.should != Data.define(:x).new(1).hash
end
end
diff --git a/spec/ruby/core/data/initialize_spec.rb b/spec/ruby/core/data/initialize_spec.rb
index 2c36bd3ac4..010c73b91b 100644
--- a/spec/ruby/core/data/initialize_spec.rb
+++ b/spec/ruby/core/data/initialize_spec.rb
@@ -1,65 +1,124 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#initialize" do
- it "accepts positional arguments" do
- data = DataSpecs::Measure.new(42, "km")
+describe "Data#initialize" do
+ it "accepts positional arguments" do
+ data = DataSpecs::Measure.new(42, "km")
- data.amount.should == 42
- data.unit.should == "km"
- end
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
- it "accepts alternative positional arguments" do
- data = DataSpecs::Measure[42, "km"]
+ it "accepts alternative positional arguments" do
+ data = DataSpecs::Measure[42, "km"]
- data.amount.should == 42
- data.unit.should == "km"
- end
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
- it "accepts keyword arguments" do
- data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ it "accepts keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
- data.amount.should == 42
- data.unit.should == "km"
- end
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts alternative keyword arguments" do
+ data = DataSpecs::Measure[amount: 42, unit: "km"]
- it "accepts alternative keyword arguments" do
- data = DataSpecs::Measure[amount: 42, unit: "km"]
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts String keyword arguments" do
+ data = DataSpecs::Measure.new("amount" => 42, "unit" => "km")
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
- data.amount.should == 42
- data.unit.should == "km"
+ it "raises ArgumentError if no arguments are given" do
+ -> {
+ DataSpecs::Measure.new
+ }.should raise_error(ArgumentError) { |e|
+ e.message.should.include?("missing keywords: :amount, :unit")
+ }
+ end
+
+ it "raises ArgumentError if at least one argument is missing" do
+ -> {
+ DataSpecs::Measure.new(unit: "km")
+ }.should raise_error(ArgumentError) { |e|
+ e.message.should.include?("missing keyword: :amount")
+ }
+ end
+
+ it "raises ArgumentError if unknown keyword is given" do
+ -> {
+ DataSpecs::Measure.new(amount: 42, unit: "km", system: "metric")
+ }.should raise_error(ArgumentError) { |e|
+ e.message.should.include?("unknown keyword: :system")
+ }
+ end
+
+ it "supports super from a subclass" do
+ ms = DataSpecs::MeasureSubclass.new(amount: 1, unit: "km")
+
+ ms.amount.should == 1
+ ms.unit.should == "km"
+ end
+
+ it "supports Data with no fields" do
+ -> { DataSpecs::Empty.new }.should_not raise_error
+ end
+
+ it "can be overridden" do
+ ScratchPad.record []
+
+ measure_class = Data.define(:amount, :unit) do
+ def initialize(*, **)
+ super
+ ScratchPad << :initialize
+ end
end
- it "accepts String keyword arguments" do
- data = DataSpecs::Measure.new("amount" => 42, "unit" => "km")
+ measure_class.new(42, "m")
+ ScratchPad.recorded.should == [:initialize]
+ end
+
+ context "when it is overridden" do
+ it "is called with keyword arguments when given positional arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize.new(42, "m")
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
+ end
- data.amount.should == 42
- data.unit.should == "km"
+ it "is called with keyword arguments when given keyword arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize.new(amount: 42, unit: "m")
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
end
- it "raises ArgumentError if no arguments are given" do
- -> {
- DataSpecs::Measure.new
- }.should raise_error(ArgumentError) { |e|
- e.message.should.include?("missing keywords: :amount, :unit")
- }
+ it "is called with keyword arguments when given alternative positional arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize[42, "m"]
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
end
- it "raises ArgumentError if at least one argument is missing" do
- -> {
- DataSpecs::Measure.new(unit: "km")
- }.should raise_error(ArgumentError) { |e|
- e.message.should.include?("missing keyword: :amount")
- }
+ it "is called with keyword arguments when given alternative keyword arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize[amount: 42, unit: "m"]
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
end
- it "raises ArgumentError if unknown keyword is given" do
- -> {
- DataSpecs::Measure.new(amount: 42, unit: "km", system: "metric")
- }.should raise_error(ArgumentError) { |e|
- e.message.should.include?("unknown keyword: :system")
- }
+ # See https://github.com/ruby/psych/pull/765
+ it "can be deserialized by calling Data.instance_method(:initialize)" do
+ d1 = DataSpecs::Area.new(width: 2, height: 3)
+ d1.area.should == 6
+
+ d2 = DataSpecs::Area.allocate
+ Data.instance_method(:initialize).bind_call(d2, **d1.to_h)
+ d2.should == d1
end
end
end
diff --git a/spec/ruby/core/data/inspect_spec.rb b/spec/ruby/core/data/inspect_spec.rb
index 3d337fac68..38642910a0 100644
--- a/spec/ruby/core/data/inspect_spec.rb
+++ b/spec/ruby/core/data/inspect_spec.rb
@@ -1,8 +1,6 @@
require_relative '../../spec_helper'
require_relative 'shared/inspect'
-ruby_version_is "3.2" do
- describe "Data#inspect" do
- it_behaves_like :data_inspect, :inspect
- end
+describe "Data#inspect" do
+ it_behaves_like :data_inspect, :inspect
end
diff --git a/spec/ruby/core/data/members_spec.rb b/spec/ruby/core/data/members_spec.rb
index 1776b0b9c1..457a90a0d6 100644
--- a/spec/ruby/core/data/members_spec.rb
+++ b/spec/ruby/core/data/members_spec.rb
@@ -1,23 +1,21 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#members" do
- it "returns an array of attribute names" do
- measure = DataSpecs::Measure.new(amount: 42, unit: 'km')
- measure.members.should == [:amount, :unit]
- end
+describe "Data#members" do
+ it "returns an array of attribute names" do
+ measure = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ measure.members.should == [:amount, :unit]
end
+end
- describe "DataClass#members" do
- it "returns an array of attribute names" do
- DataSpecs::Measure.members.should == [:amount, :unit]
- end
+describe "DataClass#members" do
+ it "returns an array of attribute names" do
+ DataSpecs::Measure.members.should == [:amount, :unit]
+ end
- context "class inheriting Data" do
- it "isn't available in a subclass" do
- DataSpecs::DataSubclass.should_not.respond_to?(:members)
- end
+ context "class inheriting Data" do
+ it "isn't available in a subclass" do
+ DataSpecs::DataSubclass.should_not.respond_to?(:members)
end
end
end
diff --git a/spec/ruby/core/data/shared/inspect.rb b/spec/ruby/core/data/shared/inspect.rb
index 7f54a46de3..6cd5664da7 100644
--- a/spec/ruby/core/data/shared/inspect.rb
+++ b/spec/ruby/core/data/shared/inspect.rb
@@ -50,5 +50,13 @@ describe :data_inspect, shared: true do
a.send(@method).should == "#<data DataSpecs::Measure amount=42, unit=#<data DataSpecs::Measure:...>>"
end
+
+ it "returns string representation with recursive attribute replaced with ... when an anonymous class" do
+ klass = Class.new(DataSpecs::Measure)
+ a = klass.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ a.send(@method).should =~ /#<data amount=42, unit=#<data #<Class:0x.+?>:\.\.\.>>/
+ end
end
end
diff --git a/spec/ruby/core/data/to_h_spec.rb b/spec/ruby/core/data/to_h_spec.rb
index 41d6960c97..64816b7251 100644
--- a/spec/ruby/core/data/to_h_spec.rb
+++ b/spec/ruby/core/data/to_h_spec.rb
@@ -1,65 +1,63 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#to_h" do
- it "transforms the data object into a hash" do
+describe "Data#to_h" do
+ it "transforms the data object into a hash" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ data.to_h.should == { amount: 42, unit: 'km' }
+ end
+
+ context "with block" do
+ it "transforms [key, value] pairs returned by the block into a hash" do
data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- data.to_h.should == { amount: 42, unit: 'km' }
+ data.to_h { |key, value| [value, key] }.should == { 42 => :amount, 'km' => :unit }
end
- context "with block" do
- it "transforms [key, value] pairs returned by the block into a hash" do
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- data.to_h { |key, value| [value, key] }.should == { 42 => :amount, 'km' => :unit }
- end
-
- it "passes to a block each pair's key and value as separate arguments" do
- ScratchPad.record []
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- data.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
- ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
+ it "passes to a block each pair's key and value as separate arguments" do
+ ScratchPad.record []
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ data.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
+ ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
- ScratchPad.record []
- data.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
- ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
- end
+ ScratchPad.record []
+ data.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
+ end
- it "raises ArgumentError if block returns longer or shorter array" do
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- -> do
- data.to_h { |k, v| [k.to_s, v*v, 1] }
- end.should raise_error(ArgumentError, /element has wrong array length/)
+ it "raises ArgumentError if block returns longer or shorter array" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ -> do
+ data.to_h { |k, v| [k.to_s, v*v, 1] }
+ end.should raise_error(ArgumentError, /element has wrong array length/)
- -> do
- data.to_h { |k, v| [k] }
- end.should raise_error(ArgumentError, /element has wrong array length/)
- end
+ -> do
+ data.to_h { |k, v| [k] }
+ end.should raise_error(ArgumentError, /element has wrong array length/)
+ end
- it "raises TypeError if block returns something other than Array" do
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- -> do
- data.to_h { |k, v| "not-array" }
- end.should raise_error(TypeError, /wrong element type String/)
- end
+ it "raises TypeError if block returns something other than Array" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ -> do
+ data.to_h { |k, v| "not-array" }
+ end.should raise_error(TypeError, /wrong element type String/)
+ end
- it "coerces returned pair to Array with #to_ary" do
- x = mock('x')
- x.stub!(:to_ary).and_return([:b, 'b'])
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- data.to_h { |k| x }.should == { :b => 'b' }
- end
+ data.to_h { |k| x }.should == { :b => 'b' }
+ end
- it "does not coerce returned pair to Array with #to_a" do
- x = mock('x')
- x.stub!(:to_a).and_return([:b, 'b'])
- data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
- -> do
- data.to_h { |k| x }
- end.should raise_error(TypeError, /wrong element type MockObject/)
- end
+ -> do
+ data.to_h { |k| x }
+ end.should raise_error(TypeError, /wrong element type MockObject/)
end
end
end
diff --git a/spec/ruby/core/data/to_s_spec.rb b/spec/ruby/core/data/to_s_spec.rb
index 0b9099f035..2b4a670e8e 100644
--- a/spec/ruby/core/data/to_s_spec.rb
+++ b/spec/ruby/core/data/to_s_spec.rb
@@ -1,8 +1,6 @@
require_relative '../../spec_helper'
require_relative 'shared/inspect'
-ruby_version_is "3.2" do
- describe "Data#to_s" do
- it_behaves_like :data_inspect, :to_s
- end
+describe "Data#to_s" do
+ it_behaves_like :data_inspect, :to_s
end
diff --git a/spec/ruby/core/data/with_spec.rb b/spec/ruby/core/data/with_spec.rb
index 97e34c951f..fd0a99d1fa 100644
--- a/spec/ruby/core/data/with_spec.rb
+++ b/spec/ruby/core/data/with_spec.rb
@@ -1,35 +1,57 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Data#with" do
- it "returns self if given no arguments" do
- data = DataSpecs::Measure.new(amount: 42, unit: "km")
- data = data.with.should.equal?(data)
- end
+describe "Data#with" do
+ it "returns self if given no arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with.should.equal?(data)
+ end
- it "accepts keyword arguments" do
- data = DataSpecs::Measure.new(amount: 42, unit: "km")
- data = data.with(amount: 4, unit: "m")
+ it "accepts keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with(amount: 4, unit: "m")
- data.amount.should == 4
- data.unit.should == "m"
- end
+ data.amount.should == 4
+ data.unit.should == "m"
+ end
+
+ it "accepts String keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with("amount" => 4, "unit" => "m")
+
+ data.amount.should == 4
+ data.unit.should == "m"
+ end
- it "accepts String keyword arguments" do
- data = DataSpecs::Measure.new(amount: 42, unit: "km")
- data = data.with("amount" => 4, "unit" => "m")
+ it "raises ArgumentError if no keyword arguments are given" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
- data.amount.should == 4
- data.unit.should == "m"
+ -> {
+ data.with(4, "m")
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)")
+ end
+
+ it "does not depend on the Data.new method" do
+ subclass = Class.new(DataSpecs::Measure)
+ data = subclass.new(amount: 42, unit: "km")
+
+ def subclass.new(*)
+ raise "Data.new is called"
end
- it "raises ArgumentError if no keyword arguments are given" do
- data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data_copy = data.with(unit: "m")
+ data_copy.amount.should == 42
+ data_copy.unit.should == "m"
+ end
+
+ ruby_version_is "3.3" do
+ it "calls #initialize" do
+ data = DataSpecs::DataWithOverriddenInitialize.new(42, "m")
+ ScratchPad.clear
+
+ data.with(amount: 0)
- -> {
- data.with(4, "m")
- }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)")
+ ScratchPad.recorded.should == [:initialize, [], {amount: 0, unit: "m"}]
end
end
end
diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb
index 1da9307599..015386a902 100644
--- a/spec/ruby/core/dir/chdir_spec.rb
+++ b/spec/ruby/core/dir/chdir_spec.rb
@@ -177,7 +177,7 @@ ruby_version_is '3.3' do
dir.close
end
- guard -> { Dir.respond_to? :fchdir } do
+ platform_is_not :windows do
it "does not raise an Errno::ENOENT if the original directory no longer exists" do
dir_name1 = tmp('testdir1')
dir_name2 = tmp('testdir2')
diff --git a/spec/ruby/core/dir/close_spec.rb b/spec/ruby/core/dir/close_spec.rb
index 5fbf5fcaf2..f7cce318b8 100644
--- a/spec/ruby/core/dir/close_spec.rb
+++ b/spec/ruby/core/dir/close_spec.rb
@@ -14,7 +14,7 @@ describe "Dir#close" do
dir.close.should == nil
dir.close.should == nil
- guard -> { dir.respond_to? :fileno } do
+ platform_is_not :windows do
-> { dir.fileno }.should raise_error(IOError, /closed directory/)
end
end
@@ -25,7 +25,7 @@ describe "Dir#close" do
end
ruby_version_is '3.3'...'3.4' do
- guard -> { Dir.respond_to? :for_fd } do
+ platform_is_not :windows do
it "does not raise an error even if the file descriptor is closed with another Dir instance" do
dir = Dir.open DirSpecs.mock_dir
dir_new = Dir.for_fd(dir.fileno)
@@ -40,7 +40,7 @@ describe "Dir#close" do
end
ruby_version_is '3.4' do
- guard -> { Dir.respond_to? :for_fd } do
+ platform_is_not :windows do
it "raises an error if the file descriptor is closed with another Dir instance" do
dir = Dir.open DirSpecs.mock_dir
dir_new = Dir.for_fd(dir.fileno)
diff --git a/spec/ruby/core/dir/exist_spec.rb b/spec/ruby/core/dir/exist_spec.rb
index 9023de533f..0b8e521894 100644
--- a/spec/ruby/core/dir/exist_spec.rb
+++ b/spec/ruby/core/dir/exist_spec.rb
@@ -14,10 +14,8 @@ describe "Dir.exist?" do
it_behaves_like :dir_exist, :exist?
end
-ruby_version_is "3.2" do
- describe "Dir.exists?" do
- it "has been removed" do
- Dir.should_not.respond_to?(:exists?)
- end
+describe "Dir.exists?" do
+ it "has been removed" do
+ Dir.should_not.respond_to?(:exists?)
end
end
diff --git a/spec/ruby/core/dir/fchdir_spec.rb b/spec/ruby/core/dir/fchdir_spec.rb
index d9dec13aab..52600a95f2 100644
--- a/spec/ruby/core/dir/fchdir_spec.rb
+++ b/spec/ruby/core/dir/fchdir_spec.rb
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/common'
ruby_version_is '3.3' do
- guard -> { Dir.respond_to? :fchdir } do
+ platform_is_not :windows do
describe "Dir.fchdir" do
before :all do
DirSpecs.create_mock_dirs
@@ -62,7 +62,7 @@ ruby_version_is '3.3' do
end
end
- guard_not -> { Dir.respond_to? :fchdir } do
+ platform_is :windows do
describe "Dir.fchdir" do
it "raises NotImplementedError" do
-> { Dir.fchdir 1 }.should raise_error(NotImplementedError)
diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb
index 087f46b331..848656c9b9 100644
--- a/spec/ruby/core/dir/fixtures/common.rb
+++ b/spec/ruby/core/dir/fixtures/common.rb
@@ -192,13 +192,7 @@ module DirSpecs
]
end
- if RUBY_VERSION > '3.1'
- def self.expected_glob_paths
- expected_paths - ['..']
- end
- else
- def self.expected_glob_paths
- expected_paths
- end
+ def self.expected_glob_paths
+ expected_paths - ['..']
end
end
diff --git a/spec/ruby/core/dir/for_fd_spec.rb b/spec/ruby/core/dir/for_fd_spec.rb
index 3afcc7e949..ba467f2f86 100644
--- a/spec/ruby/core/dir/for_fd_spec.rb
+++ b/spec/ruby/core/dir/for_fd_spec.rb
@@ -3,7 +3,7 @@ require_relative 'fixtures/common'
quarantine! do # leads to "Errno::EBADF: Bad file descriptor - closedir" in DirSpecs.delete_mock_dirs
ruby_version_is '3.3' do
- guard -> { Dir.respond_to? :for_fd } do
+ platform_is_not :windows do
describe "Dir.for_fd" do
before :all do
DirSpecs.create_mock_dirs
@@ -68,7 +68,7 @@ ruby_version_is '3.3' do
end
end
- guard_not -> { Dir.respond_to? :for_fd } do
+ platform_is :windows do
describe "Dir.for_fd" do
it "raises NotImplementedError" do
-> { Dir.for_fd 1 }.should raise_error(NotImplementedError)
diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb
index 6abd1a65df..966ac38af3 100644
--- a/spec/ruby/core/dir/home_spec.rb
+++ b/spec/ruby/core/dir/home_spec.rb
@@ -33,28 +33,26 @@ describe "Dir.home" do
end
platform_is :windows do
- ruby_version_is "3.2" do
- it "returns the home directory with forward slashs and as UTF-8" do
- ENV['HOME'] = "C:\\rubyspäc\\home"
- home = Dir.home
- home.should == "C:/rubyspäc/home"
- home.encoding.should == Encoding::UTF_8
- end
+ it "returns the home directory with forward slashs and as UTF-8" do
+ ENV['HOME'] = "C:\\rubyspäc\\home"
+ home = Dir.home
+ home.should == "C:/rubyspäc/home"
+ home.encoding.should == Encoding::UTF_8
+ end
- it "retrieves the directory from HOME, USERPROFILE, HOMEDRIVE/HOMEPATH and the WinAPI in that order" do
- old_dirs = [ENV.delete('HOME'), ENV.delete('USERPROFILE'), ENV.delete('HOMEDRIVE'), ENV.delete('HOMEPATH')]
+ it "retrieves the directory from HOME, USERPROFILE, HOMEDRIVE/HOMEPATH and the WinAPI in that order" do
+ old_dirs = [ENV.delete('HOME'), ENV.delete('USERPROFILE'), ENV.delete('HOMEDRIVE'), ENV.delete('HOMEPATH')]
- Dir.home.should == old_dirs[1].gsub("\\", "/")
- ENV['HOMEDRIVE'] = "C:"
- ENV['HOMEPATH'] = "\\rubyspec\\home1"
- Dir.home.should == "C:/rubyspec/home1"
- ENV['USERPROFILE'] = "C:\\rubyspec\\home2"
- Dir.home.should == "C:/rubyspec/home2"
- ENV['HOME'] = "C:\\rubyspec\\home3"
- Dir.home.should == "C:/rubyspec/home3"
- ensure
- ENV['HOME'], ENV['USERPROFILE'], ENV['HOMEDRIVE'], ENV['HOMEPATH'] = *old_dirs
- end
+ Dir.home.should == old_dirs[1].gsub("\\", "/")
+ ENV['HOMEDRIVE'] = "C:"
+ ENV['HOMEPATH'] = "\\rubyspec\\home1"
+ Dir.home.should == "C:/rubyspec/home1"
+ ENV['USERPROFILE'] = "C:\\rubyspec\\home2"
+ Dir.home.should == "C:/rubyspec/home2"
+ ENV['HOME'] = "C:\\rubyspec\\home3"
+ Dir.home.should == "C:/rubyspec/home3"
+ ensure
+ ENV['HOME'], ENV['USERPROFILE'], ENV['HOMEDRIVE'], ENV['HOMEPATH'] = *old_dirs
end
end
end
diff --git a/spec/ruby/core/encoding/compatible_spec.rb b/spec/ruby/core/encoding/compatible_spec.rb
index 61a651893b..31376a3b75 100644
--- a/spec/ruby/core/encoding/compatible_spec.rb
+++ b/spec/ruby/core/encoding/compatible_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
@@ -171,7 +171,7 @@ describe "Encoding.compatible? String, String" do
# Use the following script to regenerate the matrix:
#
# ```
-# # -*- encoding: binary -*-
+# # encoding: binary
#
# ENCODINGS = [
# "US-ASCII",
diff --git a/spec/ruby/core/encoding/converter/convert_spec.rb b/spec/ruby/core/encoding/converter/convert_spec.rb
index 7f249d90a3..8533af4565 100644
--- a/spec/ruby/core/encoding/converter/convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/convert_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
# frozen_string_literal: true
require_relative '../../../spec_helper'
diff --git a/spec/ruby/core/encoding/converter/last_error_spec.rb b/spec/ruby/core/encoding/converter/last_error_spec.rb
index 78779be70b..ff2a2b4cbe 100644
--- a/spec/ruby/core/encoding/converter/last_error_spec.rb
+++ b/spec/ruby/core/encoding/converter/last_error_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
describe "Encoding::Converter#last_error" do
diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb
index db9c3364d7..a7bef53809 100644
--- a/spec/ruby/core/encoding/converter/new_spec.rb
+++ b/spec/ruby/core/encoding/converter/new_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
describe "Encoding::Converter.new" do
diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
index 63f25eddef..e4aeed103e 100644
--- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
# frozen_string_literal: false
require_relative '../../../spec_helper'
diff --git a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
index 668eb9a924..5ee8b1fecd 100644
--- a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
# frozen_string_literal: false
require_relative '../../../spec_helper'
diff --git a/spec/ruby/core/encoding/converter/putback_spec.rb b/spec/ruby/core/encoding/converter/putback_spec.rb
index e19fe6c314..04bb565655 100644
--- a/spec/ruby/core/encoding/converter/putback_spec.rb
+++ b/spec/ruby/core/encoding/converter/putback_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
describe "Encoding::Converter#putback" do
diff --git a/spec/ruby/core/encoding/find_spec.rb b/spec/ruby/core/encoding/find_spec.rb
index 8a0873070f..9c34fe0e77 100644
--- a/spec/ruby/core/encoding/find_spec.rb
+++ b/spec/ruby/core/encoding/find_spec.rb
@@ -50,7 +50,7 @@ describe "Encoding.find" do
end
it "raises an ArgumentError if the given encoding does not exist" do
- -> { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
+ -> { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError, 'unknown encoding name - dh2dh278d')
end
# Not sure how to do a better test, since locale depends on weird platform-specific stuff
diff --git a/spec/ruby/core/encoding/fixtures/classes.rb b/spec/ruby/core/encoding/fixtures/classes.rb
index 12e9a4f348..943865e8d8 100644
--- a/spec/ruby/core/encoding/fixtures/classes.rb
+++ b/spec/ruby/core/encoding/fixtures/classes.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
module EncodingSpecs
class UndefinedConversionError
def self.exception
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
index d2fc360dce..8b7e87960f 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative "../../../spec_helper"
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
index 8a3f3de69a..83606f77b4 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
index a5e2824984..e5ad0a61bd 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative "../../../spec_helper"
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb
index e22673db7d..2da998837f 100644
--- a/spec/ruby/core/encoding/replicate_spec.rb
+++ b/spec/ruby/core/encoding/replicate_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
describe "Encoding#replicate" do
@@ -67,7 +67,7 @@ describe "Encoding#replicate" do
end
end
- ruby_version_is "3.2"..."3.3" do
+ ruby_version_is ""..."3.3" do
it "warns about deprecation" do
-> {
Encoding::US_ASCII.replicate('MY-US-ASCII')
diff --git a/spec/ruby/core/enumerable/filter_spec.rb b/spec/ruby/core/enumerable/filter_spec.rb
index c9ee23c541..1c3a7e9ff5 100644
--- a/spec/ruby/core/enumerable/filter_spec.rb
+++ b/spec/ruby/core/enumerable/filter_spec.rb
@@ -3,5 +3,5 @@ require_relative 'fixtures/classes'
require_relative 'shared/find_all'
describe "Enumerable#filter" do
- it_behaves_like(:enumerable_find_all, :filter)
+ it_behaves_like :enumerable_find_all, :filter
end
diff --git a/spec/ruby/core/enumerable/fixtures/classes.rb b/spec/ruby/core/enumerable/fixtures/classes.rb
index 2701c6999c..b5feafcfb7 100644
--- a/spec/ruby/core/enumerable/fixtures/classes.rb
+++ b/spec/ruby/core/enumerable/fixtures/classes.rb
@@ -38,12 +38,14 @@ module EnumerableSpecs
class Empty
include Enumerable
def each
+ self
end
end
class EmptyWithSize
include Enumerable
def each
+ self
end
def size
0
@@ -343,9 +345,6 @@ module EnumerableSpecs
end
end
- # Set is a core class since Ruby 3.2
- ruby_version_is '3.2' do
- class SetSubclass < Set
- end
+ class SetSubclass < Set
end
end # EnumerableSpecs utility classes
diff --git a/spec/ruby/core/enumerable/shared/inject.rb b/spec/ruby/core/enumerable/shared/inject.rb
index 92f220efa4..8fb7e98c2b 100644
--- a/spec/ruby/core/enumerable/shared/inject.rb
+++ b/spec/ruby/core/enumerable/shared/inject.rb
@@ -103,7 +103,7 @@ describe :enumerable_inject, shared: true do
it "without inject arguments(legacy rubycon)" do
# no inject argument
- EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| 999 } .should == 2
+ EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| 999 }.should == 2
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| acc }.should == 2
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| x }.should == 2
@@ -135,10 +135,8 @@ describe :enumerable_inject, shared: true do
actual.sort_by(&:to_s).should == expected.sort_by(&:to_s)
end
- ruby_bug '#18635', ''...'3.2' do
- it "raises an ArgumentError when no parameters or block is given" do
- -> { [1,2].send(@method) }.should raise_error(ArgumentError)
- -> { {one: 1, two: 2}.send(@method) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when no parameters or block is given" do
+ -> { [1,2].send(@method) }.should raise_error(ArgumentError)
+ -> { {one: 1, two: 2}.send(@method) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/enumerable/to_set_spec.rb b/spec/ruby/core/enumerable/to_set_spec.rb
index c21a2772c4..c02ead11fa 100644
--- a/spec/ruby/core/enumerable/to_set_spec.rb
+++ b/spec/ruby/core/enumerable/to_set_spec.rb
@@ -1,29 +1,30 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
-ruby_version_is "3.2" do
- describe "Enumerable#to_set" do
- it "returns a new Set created from self" do
- [1, 2, 3].to_set.should == Set[1, 2, 3]
- {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]]
- end
+describe "Enumerable#to_set" do
+ it "returns a new Set created from self" do
+ [1, 2, 3].to_set.should == Set[1, 2, 3]
+ {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]]
+ end
- it "passes down passed blocks" do
- [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
- end
+ it "passes down passed blocks" do
+ [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
+ end
+ ruby_version_is "4.0"..."4.1" do
it "instantiates an object of provided as the first argument set class" do
- set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)
+ set = nil
+ proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)
set.should be_kind_of(EnumerableSpecs::SetSubclass)
set.to_a.sort.should == [1, 2, 3]
end
+ end
- it "does not need explicit `require 'set'`" do
- output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
- puts [1, 2, 3].to_set
- RUBY
-
- output.chomp.should == "#<Set: {1, 2, 3}>"
+ ruby_version_is ""..."4.0" do
+ it "instantiates an object of provided as the first argument set class" do
+ set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)
+ set.should be_kind_of(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
end
end
end
diff --git a/spec/ruby/core/enumerator/product/each_spec.rb b/spec/ruby/core/enumerator/product/each_spec.rb
index cabeb9d93a..88f115a712 100644
--- a/spec/ruby/core/enumerator/product/each_spec.rb
+++ b/spec/ruby/core/enumerator/product/each_spec.rb
@@ -1,73 +1,71 @@
require_relative '../../../spec_helper'
require_relative '../../enumerable/shared/enumeratorized'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#each" do
- it_behaves_like :enumeratorized_with_origin_size, :each, Enumerator::Product.new([1, 2], [:a, :b])
+describe "Enumerator::Product#each" do
+ it_behaves_like :enumeratorized_with_origin_size, :each, Enumerator::Product.new([1, 2], [:a, :b])
- it "yields each element of Cartesian product of enumerators" do
- enum = Enumerator::Product.new([1, 2], [:a, :b])
- acc = []
- enum.each { |e| acc << e }
- acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
-
- it "calls #each_entry method on enumerators" do
- object1 = Object.new
- def object1.each_entry
- yield 1
- yield 2
- end
-
- object2 = Object.new
- def object2.each_entry
- yield :a
- yield :b
- end
+ it "yields each element of Cartesian product of enumerators" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ acc = []
+ enum.each { |e| acc << e }
+ acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- enum = Enumerator::Product.new(object1, object2)
- acc = []
- enum.each { |e| acc << e }
- acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ it "calls #each_entry method on enumerators" do
+ object1 = Object.new
+ def object1.each_entry
+ yield 1
+ yield 2
end
- it "raises a NoMethodError if the object doesn't respond to #each_entry" do
- -> {
- Enumerator::Product.new(Object.new).each {}
- }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
+ object2 = Object.new
+ def object2.each_entry
+ yield :a
+ yield :b
end
- it "returns enumerator if not given a block" do
- enum = Enumerator::Product.new([1, 2], [:a, :b])
- enum.each.should.kind_of?(Enumerator)
+ enum = Enumerator::Product.new(object1, object2)
+ acc = []
+ enum.each { |e| acc << e }
+ acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- enum = Enumerator::Product.new([1, 2], [:a, :b])
- enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
+ it "raises a NoMethodError if the object doesn't respond to #each_entry" do
+ -> {
+ Enumerator::Product.new(Object.new).each {}
+ }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
+ end
- it "returns self if given a block" do
- enum = Enumerator::Product.new([1, 2], [:a, :b])
- enum.each {}.should.equal?(enum)
- end
+ it "returns enumerator if not given a block" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each.should.kind_of?(Enumerator)
- it "doesn't accept arguments" do
- Enumerator::Product.instance_method(:each).arity.should == 0
- end
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- it "yields each element to a block that takes multiple arguments" do
- enum = Enumerator::Product.new([1, 2], [:a, :b])
+ it "returns self if given a block" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each {}.should.equal?(enum)
+ end
- acc = []
- enum.each { |x, y| acc << x }
- acc.should == [1, 1, 2, 2]
+ it "doesn't accept arguments" do
+ Enumerator::Product.instance_method(:each).arity.should == 0
+ end
- acc = []
- enum.each { |x, y| acc << y }
- acc.should == [:a, :b, :a, :b]
+ it "yields each element to a block that takes multiple arguments" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
- acc = []
- enum.each { |x, y, z| acc << z }
- acc.should == [nil, nil, nil, nil]
- end
+ acc = []
+ enum.each { |x, y| acc << x }
+ acc.should == [1, 1, 2, 2]
+
+ acc = []
+ enum.each { |x, y| acc << y }
+ acc.should == [:a, :b, :a, :b]
+
+ acc = []
+ enum.each { |x, y, z| acc << z }
+ acc.should == [nil, nil, nil, nil]
end
end
diff --git a/spec/ruby/core/enumerator/product/initialize_copy_spec.rb b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb
index 46e8421322..b1b9f3ca9b 100644
--- a/spec/ruby/core/enumerator/product/initialize_copy_spec.rb
+++ b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb
@@ -1,54 +1,52 @@
require_relative '../../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#initialize_copy" do
- it "replaces content of the receiver with content of the other object" do
- enum = Enumerator::Product.new([true, false])
- enum2 = Enumerator::Product.new([1, 2], [:a, :b])
+describe "Enumerator::Product#initialize_copy" do
+ it "replaces content of the receiver with content of the other object" do
+ enum = Enumerator::Product.new([true, false])
+ enum2 = Enumerator::Product.new([1, 2], [:a, :b])
- enum.send(:initialize_copy, enum2)
- enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
+ enum.send(:initialize_copy, enum2)
+ enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- it "returns self" do
- enum = Enumerator::Product.new([true, false])
- enum2 = Enumerator::Product.new([1, 2], [:a, :b])
+ it "returns self" do
+ enum = Enumerator::Product.new([true, false])
+ enum2 = Enumerator::Product.new([1, 2], [:a, :b])
- enum.send(:initialize_copy, enum2).should.equal?(enum)
- end
+ enum.send(:initialize_copy, enum2).should.equal?(enum)
+ end
- it "is a private method" do
- Enumerator::Product.should have_private_instance_method(:initialize_copy, false)
- end
+ it "is a private method" do
+ Enumerator::Product.should have_private_instance_method(:initialize_copy, false)
+ end
- it "does nothing if the argument is the same as the receiver" do
- enum = Enumerator::Product.new(1..2)
- enum.send(:initialize_copy, enum).should.equal?(enum)
+ it "does nothing if the argument is the same as the receiver" do
+ enum = Enumerator::Product.new(1..2)
+ enum.send(:initialize_copy, enum).should.equal?(enum)
- enum.freeze
- enum.send(:initialize_copy, enum).should.equal?(enum)
- end
+ enum.freeze
+ enum.send(:initialize_copy, enum).should.equal?(enum)
+ end
- it "raises FrozenError if the receiver is frozen" do
- enum = Enumerator::Product.new(1..2)
- enum2 = Enumerator::Product.new(3..4)
+ it "raises FrozenError if the receiver is frozen" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Enumerator::Product.new(3..4)
- -> { enum.freeze.send(:initialize_copy, enum2) }.should raise_error(FrozenError)
- end
+ -> { enum.freeze.send(:initialize_copy, enum2) }.should raise_error(FrozenError)
+ end
- it "raises TypeError if the objects are of different class" do
- enum = Enumerator::Product.new(1..2)
- enum2 = Class.new(Enumerator::Product).new(3..4)
+ it "raises TypeError if the objects are of different class" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Class.new(Enumerator::Product).new(3..4)
- -> { enum.send(:initialize_copy, enum2) }.should raise_error(TypeError, 'initialize_copy should take same class object')
- -> { enum2.send(:initialize_copy, enum) }.should raise_error(TypeError, 'initialize_copy should take same class object')
- end
+ -> { enum.send(:initialize_copy, enum2) }.should raise_error(TypeError, 'initialize_copy should take same class object')
+ -> { enum2.send(:initialize_copy, enum) }.should raise_error(TypeError, 'initialize_copy should take same class object')
+ end
- it "raises ArgumentError if the argument is not initialized yet" do
- enum = Enumerator::Product.new(1..2)
- enum2 = Enumerator::Product.allocate
+ it "raises ArgumentError if the argument is not initialized yet" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Enumerator::Product.allocate
- -> { enum.send(:initialize_copy, enum2) }.should raise_error(ArgumentError, 'uninitialized product')
- end
+ -> { enum.send(:initialize_copy, enum2) }.should raise_error(ArgumentError, 'uninitialized product')
end
end
diff --git a/spec/ruby/core/enumerator/product/initialize_spec.rb b/spec/ruby/core/enumerator/product/initialize_spec.rb
index 4b60564240..ed2a8a2a13 100644
--- a/spec/ruby/core/enumerator/product/initialize_spec.rb
+++ b/spec/ruby/core/enumerator/product/initialize_spec.rb
@@ -1,33 +1,31 @@
require_relative '../../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#initialize" do
- before :each do
- @uninitialized = Enumerator::Product.allocate
- end
+describe "Enumerator::Product#initialize" do
+ before :each do
+ @uninitialized = Enumerator::Product.allocate
+ end
- it "is a private method" do
- Enumerator::Product.should have_private_instance_method(:initialize, false)
- end
+ it "is a private method" do
+ Enumerator::Product.should have_private_instance_method(:initialize, false)
+ end
- it "returns self" do
- @uninitialized.send(:initialize).should equal(@uninitialized)
- end
+ it "returns self" do
+ @uninitialized.send(:initialize).should equal(@uninitialized)
+ end
- it "accepts many arguments" do
- @uninitialized.send(:initialize, 0..1, 2..3, 4..5).should equal(@uninitialized)
- end
+ it "accepts many arguments" do
+ @uninitialized.send(:initialize, 0..1, 2..3, 4..5).should equal(@uninitialized)
+ end
- it "accepts arguments that are not Enumerable nor responding to :each_entry" do
- @uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
- end
+ it "accepts arguments that are not Enumerable nor responding to :each_entry" do
+ @uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
+ end
- describe "on frozen instance" do
- it "raises a FrozenError" do
- -> {
- @uninitialized.freeze.send(:initialize, 0..1)
- }.should raise_error(FrozenError)
- end
+ describe "on frozen instance" do
+ it "raises a FrozenError" do
+ -> {
+ @uninitialized.freeze.send(:initialize, 0..1)
+ }.should raise_error(FrozenError)
end
end
end
diff --git a/spec/ruby/core/enumerator/product/inspect_spec.rb b/spec/ruby/core/enumerator/product/inspect_spec.rb
index 1ea8e9c49b..e0d7441f26 100644
--- a/spec/ruby/core/enumerator/product/inspect_spec.rb
+++ b/spec/ruby/core/enumerator/product/inspect_spec.rb
@@ -1,22 +1,20 @@
require_relative '../../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#inspect" do
- it "returns a String including enumerators" do
- enum = Enumerator::Product.new([1, 2], [:a, :b])
- enum.inspect.should == "#<Enumerator::Product: [[1, 2], [:a, :b]]>"
- end
+describe "Enumerator::Product#inspect" do
+ it "returns a String including enumerators" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.inspect.should == "#<Enumerator::Product: [[1, 2], [:a, :b]]>"
+ end
- it "represents a recursive element with '[...]'" do
- enum = [1, 2]
- enum_recursive = Enumerator::Product.new(enum)
+ it "represents a recursive element with '[...]'" do
+ enum = [1, 2]
+ enum_recursive = Enumerator::Product.new(enum)
- enum << enum_recursive
- enum_recursive.inspect.should == "#<Enumerator::Product: [[1, 2, #<Enumerator::Product: ...>]]>"
- end
+ enum << enum_recursive
+ enum_recursive.inspect.should == "#<Enumerator::Product: [[1, 2, #<Enumerator::Product: ...>]]>"
+ end
- it "returns a not initialized representation if #initialized is not called yet" do
- Enumerator::Product.allocate.inspect.should == "#<Enumerator::Product: uninitialized>"
- end
+ it "returns a not initialized representation if #initialized is not called yet" do
+ Enumerator::Product.allocate.inspect.should == "#<Enumerator::Product: uninitialized>"
end
end
diff --git a/spec/ruby/core/enumerator/product/rewind_spec.rb b/spec/ruby/core/enumerator/product/rewind_spec.rb
index e8ee730239..2beffaf5c1 100644
--- a/spec/ruby/core/enumerator/product/rewind_spec.rb
+++ b/spec/ruby/core/enumerator/product/rewind_spec.rb
@@ -1,64 +1,62 @@
require_relative '../../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#rewind" do
- before :each do
- @enum = Enumerator::Product.new([1, 2].each.to_enum, [:a, :b].each.to_enum)
- end
+describe "Enumerator::Product#rewind" do
+ before :each do
+ @enum = Enumerator::Product.new([1, 2].each.to_enum, [:a, :b].each.to_enum)
+ end
- it "resets the enumerator to its initial state" do
- @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- @enum.rewind
- @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
+ it "resets the enumerator to its initial state" do
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- it "returns self" do
- @enum.rewind.should.equal? @enum
- end
+ it "returns self" do
+ @enum.rewind.should.equal? @enum
+ end
- it "has no effect on a new enumerator" do
- @enum.rewind
- @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
+ it "has no effect on a new enumerator" do
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- it "has no effect if called multiple, consecutive times" do
- @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- @enum.rewind
- @enum.rewind
- @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
- end
+ it "has no effect if called multiple, consecutive times" do
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ @enum.rewind
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
- it "calls the enclosed object's rewind method if one exists" do
- obj = mock('rewinder')
- enum = Enumerator::Product.new(obj.to_enum)
+ it "calls the enclosed object's rewind method if one exists" do
+ obj = mock('rewinder')
+ enum = Enumerator::Product.new(obj.to_enum)
- obj.should_receive(:rewind)
- enum.rewind
- end
+ obj.should_receive(:rewind)
+ enum.rewind
+ end
- it "does nothing if the object doesn't have a #rewind method" do
- obj = mock('rewinder')
- enum = Enumerator::Product.new(obj.to_enum)
+ it "does nothing if the object doesn't have a #rewind method" do
+ obj = mock('rewinder')
+ enum = Enumerator::Product.new(obj.to_enum)
- enum.rewind.should == enum
- end
+ enum.rewind.should == enum
+ end
- it "calls a rewind method on each enumerable in direct order" do
- ScratchPad.record []
+ it "calls a rewind method on each enumerable in direct order" do
+ ScratchPad.record []
- object1 = Object.new
- def object1.rewind; ScratchPad << :object1; end
+ object1 = Object.new
+ def object1.rewind; ScratchPad << :object1; end
- object2 = Object.new
- def object2.rewind; ScratchPad << :object2; end
+ object2 = Object.new
+ def object2.rewind; ScratchPad << :object2; end
- object3 = Object.new
- def object3.rewind; ScratchPad << :object3; end
+ object3 = Object.new
+ def object3.rewind; ScratchPad << :object3; end
- enum = Enumerator::Product.new(object1, object2, object3)
- enum.rewind
+ enum = Enumerator::Product.new(object1, object2, object3)
+ enum.rewind
- ScratchPad.recorded.should == [:object1, :object2, :object3]
- end
+ ScratchPad.recorded.should == [:object1, :object2, :object3]
end
end
diff --git a/spec/ruby/core/enumerator/product/size_spec.rb b/spec/ruby/core/enumerator/product/size_spec.rb
index 46958b1a22..96632d6eee 100644
--- a/spec/ruby/core/enumerator/product/size_spec.rb
+++ b/spec/ruby/core/enumerator/product/size_spec.rb
@@ -1,56 +1,54 @@
require_relative '../../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator::Product#size" do
- it "returns the total size of the enumerator product calculated by multiplying the sizes of enumerables in the product" do
- product = Enumerator::Product.new(1..2, 1..3, 1..4)
- product.size.should == 24 # 2 * 3 * 4
- end
-
- it "returns nil if any enumerable reports its size as nil" do
- enum = Object.new
- def enum.size; nil; end
-
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == nil
- end
-
- it "returns Float::INFINITY if any enumerable reports its size as Float::INFINITY" do
- enum = Object.new
- def enum.size; Float::INFINITY; end
-
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == Float::INFINITY
- end
-
- it "returns nil if any enumerable reports its size as Float::NAN" do
- enum = Object.new
- def enum.size; Float::NAN; end
-
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == nil
- end
-
- it "returns nil if any enumerable doesn't respond to #size" do
- enum = Object.new
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == nil
- end
-
- it "returns nil if any enumerable reports a not-convertible to Integer" do
- enum = Object.new
- def enum.size; :symbol; end
-
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == nil
- end
-
- it "returns nil if any enumerable reports a non-Integer but convertible to Integer size" do
- enum = Object.new
- def enum.size; 1.0; end
-
- product = Enumerator::Product.new(1..2, enum)
- product.size.should == nil
- end
+describe "Enumerator::Product#size" do
+ it "returns the total size of the enumerator product calculated by multiplying the sizes of enumerables in the product" do
+ product = Enumerator::Product.new(1..2, 1..3, 1..4)
+ product.size.should == 24 # 2 * 3 * 4
+ end
+
+ it "returns nil if any enumerable reports its size as nil" do
+ enum = Object.new
+ def enum.size; nil; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns Float::INFINITY if any enumerable reports its size as Float::INFINITY" do
+ enum = Object.new
+ def enum.size; Float::INFINITY; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == Float::INFINITY
+ end
+
+ it "returns nil if any enumerable reports its size as Float::NAN" do
+ enum = Object.new
+ def enum.size; Float::NAN; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable doesn't respond to #size" do
+ enum = Object.new
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable reports a not-convertible to Integer" do
+ enum = Object.new
+ def enum.size; :symbol; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable reports a non-Integer but convertible to Integer size" do
+ enum = Object.new
+ def enum.size; 1.0; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
end
end
diff --git a/spec/ruby/core/enumerator/product_spec.rb b/spec/ruby/core/enumerator/product_spec.rb
index 0acca6690e..83c7cb8e0e 100644
--- a/spec/ruby/core/enumerator/product_spec.rb
+++ b/spec/ruby/core/enumerator/product_spec.rb
@@ -1,93 +1,91 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Enumerator.product" do
- it "returns a Cartesian product of enumerators" do
- enum = Enumerator.product(1..2, ["A", "B"])
- enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
- end
-
- it "accepts a list of enumerators of any length" do
- enum = Enumerator.product(1..2)
- enum.to_a.should == [[1], [2]]
+describe "Enumerator.product" do
+ it "returns a Cartesian product of enumerators" do
+ enum = Enumerator.product(1..2, ["A", "B"])
+ enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
+ end
- enum = Enumerator.product(1..2, ["A"])
- enum.to_a.should == [[1, "A"], [2, "A"]]
+ it "accepts a list of enumerators of any length" do
+ enum = Enumerator.product(1..2)
+ enum.to_a.should == [[1], [2]]
- enum = Enumerator.product(1..2, ["A"], ["B"])
- enum.to_a.should == [[1, "A", "B"], [2, "A", "B"]]
+ enum = Enumerator.product(1..2, ["A"])
+ enum.to_a.should == [[1, "A"], [2, "A"]]
- enum = Enumerator.product(2..3, ["A"], ["B"], ["C"])
- enum.to_a.should == [[2, "A", "B", "C"], [3, "A", "B", "C"]]
- end
+ enum = Enumerator.product(1..2, ["A"], ["B"])
+ enum.to_a.should == [[1, "A", "B"], [2, "A", "B"]]
- it "returns an enumerator with an empty array when no arguments passed" do
- enum = Enumerator.product
- enum.to_a.should == [[]]
- end
+ enum = Enumerator.product(2..3, ["A"], ["B"], ["C"])
+ enum.to_a.should == [[2, "A", "B", "C"], [3, "A", "B", "C"]]
+ end
- it "returns an instance of Enumerator::Product" do
- enum = Enumerator.product
- enum.class.should == Enumerator::Product
- end
+ it "returns an enumerator with an empty array when no arguments passed" do
+ enum = Enumerator.product
+ enum.to_a.should == [[]]
+ end
- it "accepts infinite enumerators and returns infinite enumerator" do
- enum = Enumerator.product(1.., ["A", "B"])
- enum.take(5).should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"], [3, "A"]]
- enum.size.should == Float::INFINITY
- end
+ it "returns an instance of Enumerator::Product" do
+ enum = Enumerator.product
+ enum.class.should == Enumerator::Product
+ end
- it "accepts a block" do
- elems = []
- enum = Enumerator.product(1..2, ["X", "Y"]) { elems << _1 }
+ it "accepts infinite enumerators and returns infinite enumerator" do
+ enum = Enumerator.product(1.., ["A", "B"])
+ enum.take(5).should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"], [3, "A"]]
+ enum.size.should == Float::INFINITY
+ end
- elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
- end
+ it "accepts a block" do
+ elems = []
+ enum = Enumerator.product(1..2, ["X", "Y"]) { elems << _1 }
- it "returns nil when a block passed" do
- Enumerator.product(1..2) {}.should == nil
- end
+ elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
+ end
- # https://bugs.ruby-lang.org/issues/19829
- it "reject keyword arguments" do
- -> {
- Enumerator.product(1..3, foo: 1, bar: 2)
- }.should raise_error(ArgumentError, "unknown keywords: :foo, :bar")
- end
+ it "returns nil when a block passed" do
+ Enumerator.product(1..2) {}.should == nil
+ end
- it "calls only #each_entry method on arguments" do
- object = Object.new
- def object.each_entry
- yield 1
- yield 2
- end
+ # https://bugs.ruby-lang.org/issues/19829
+ it "reject keyword arguments" do
+ -> {
+ Enumerator.product(1..3, foo: 1, bar: 2)
+ }.should raise_error(ArgumentError, "unknown keywords: :foo, :bar")
+ end
- enum = Enumerator.product(object, ["A", "B"])
- enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
+ it "calls only #each_entry method on arguments" do
+ object = Object.new
+ def object.each_entry
+ yield 1
+ yield 2
end
- it "raises NoMethodError when argument doesn't respond to #each_entry" do
- -> {
- Enumerator.product(Object.new).to_a
- }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
- end
+ enum = Enumerator.product(object, ["A", "B"])
+ enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
+ end
- it "calls #each_entry lazily" do
- Enumerator.product(Object.new).should be_kind_of(Enumerator)
- end
+ it "raises NoMethodError when argument doesn't respond to #each_entry" do
+ -> {
+ Enumerator.product(Object.new).to_a
+ }.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
+ end
+
+ it "calls #each_entry lazily" do
+ Enumerator.product(Object.new).should be_kind_of(Enumerator)
+ end
- it "iterates through consuming enumerator elements only once" do
- a = [1, 2, 3]
- i = 0
+ it "iterates through consuming enumerator elements only once" do
+ a = [1, 2, 3]
+ i = 0
- enum = Enumerator.new do |y|
- while i < a.size
- y << a[i]
- i += 1
- end
+ enum = Enumerator.new do |y|
+ while i < a.size
+ y << a[i]
+ i += 1
end
-
- Enumerator.product(['a', 'b'], enum).to_a.should == [["a", 1], ["a", 2], ["a", 3]]
end
+
+ Enumerator.product(['a', 'b'], enum).to_a.should == [["a", 1], ["a", 2], ["a", 3]]
end
end
diff --git a/spec/ruby/core/env/clone_spec.rb b/spec/ruby/core/env/clone_spec.rb
index 991e4e6774..01a29c6ab4 100644
--- a/spec/ruby/core/env/clone_spec.rb
+++ b/spec/ruby/core/env/clone_spec.rb
@@ -13,11 +13,9 @@ describe "ENV#clone" do
}.should raise_error(ArgumentError)
end
- ruby_version_is "3.2" do
- it "raises TypeError" do
- -> {
- ENV.clone
- }.should raise_error(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
- end
+ it "raises TypeError" do
+ -> {
+ ENV.clone
+ }.should raise_error(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
end
end
diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb
index 560c127a9c..66a9bc9690 100644
--- a/spec/ruby/core/env/element_reference_spec.rb
+++ b/spec/ruby/core/env/element_reference_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'fixtures/common'
diff --git a/spec/ruby/core/env/shared/update.rb b/spec/ruby/core/env/shared/update.rb
index 7d4799955b..e1b1c9c290 100644
--- a/spec/ruby/core/env/shared/update.rb
+++ b/spec/ruby/core/env/shared/update.rb
@@ -15,12 +15,10 @@ describe :env_update, shared: true do
ENV["bar"].should == "1"
end
- ruby_version_is "3.2" do
- it "adds the multiple parameter hashes to ENV, returning ENV" do
- ENV.send(@method, {"foo" => "multi1"}, {"bar" => "multi2"}).should equal(ENV)
- ENV["foo"].should == "multi1"
- ENV["bar"].should == "multi2"
- end
+ it "adds the multiple parameter hashes to ENV, returning ENV" do
+ ENV.send(@method, {"foo" => "multi1"}, {"bar" => "multi2"}).should equal(ENV)
+ ENV["foo"].should == "multi1"
+ ENV["bar"].should == "multi2"
end
it "returns ENV when no block given" do
diff --git a/spec/ruby/core/exception/detailed_message_spec.rb b/spec/ruby/core/exception/detailed_message_spec.rb
index 8178278b2b..9df164a1cf 100644
--- a/spec/ruby/core/exception/detailed_message_spec.rb
+++ b/spec/ruby/core/exception/detailed_message_spec.rb
@@ -2,51 +2,49 @@ require_relative '../../spec_helper'
require_relative 'fixtures/common'
describe "Exception#detailed_message" do
- ruby_version_is "3.2" do
- it "returns decorated message" do
- RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)"
- end
+ it "returns decorated message" do
+ RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)"
+ end
- it "is called by #full_message to allow message customization" do
- exception = Exception.new("new error")
- def exception.detailed_message(**)
- "<prefix>#{message}<suffix>"
- end
- exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
+ it "is called by #full_message to allow message customization" do
+ exception = Exception.new("new error")
+ def exception.detailed_message(**)
+ "<prefix>#{message}<suffix>"
end
+ exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
+ end
- it "returns just a message if exception class is anonymous" do
- Class.new(RuntimeError).new("message").detailed_message.should == "message"
- end
+ it "returns just a message if exception class is anonymous" do
+ Class.new(RuntimeError).new("message").detailed_message.should == "message"
+ end
- it "returns 'unhandled exception' for an instance of RuntimeError with empty message" do
- RuntimeError.new("").detailed_message.should == "unhandled exception"
- end
+ it "returns 'unhandled exception' for an instance of RuntimeError with empty message" do
+ RuntimeError.new("").detailed_message.should == "unhandled exception"
+ end
- it "returns just class name for an instance other than RuntimeError with empty message" do
- DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
- StandardError.new("").detailed_message.should == "StandardError"
- end
+ it "returns just class name for an instance other than RuntimeError with empty message" do
+ DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
+ StandardError.new("").detailed_message.should == "StandardError"
+ end
- it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
- klass = Class.new(RuntimeError)
- klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
- end
+ it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
+ klass = Class.new(RuntimeError)
+ klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
+ end
- it "accepts highlight keyword argument and adds escape control sequences" do
- RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
- end
+ it "accepts highlight keyword argument and adds escape control sequences" do
+ RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
+ end
- it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do
- RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m"
- end
+ it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do
+ RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m"
+ end
- it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do
- StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m"
- end
+ it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do
+ StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m"
+ end
- it "allows and ignores other keyword arguments" do
- RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
- end
+ it "allows and ignores other keyword arguments" do
+ RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
end
end
diff --git a/spec/ruby/core/exception/frozen_error_spec.rb b/spec/ruby/core/exception/frozen_error_spec.rb
index 979ec2ff98..af2e925661 100644
--- a/spec/ruby/core/exception/frozen_error_spec.rb
+++ b/spec/ruby/core/exception/frozen_error_spec.rb
@@ -21,6 +21,22 @@ describe "FrozenError#receiver" do
end
end
+describe "FrozenError#message" do
+ it "includes a receiver" do
+ object = Object.new
+ object.freeze
+
+ msg_class = ruby_version_is("4.0") ? "Object" : "object"
+
+ -> {
+ def object.x; end
+ }.should raise_error(FrozenError, "can't modify frozen #{msg_class}: #{object}")
+
+ object = [].freeze
+ -> { object << nil }.should raise_error(FrozenError, "can't modify frozen Array: []")
+ end
+end
+
describe "Modifying a frozen object" do
context "#inspect is redefined and modifies the object" do
it "returns ... instead of String representation of object" do
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb
index d752083db2..0761d2b40c 100644
--- a/spec/ruby/core/exception/full_message_spec.rb
+++ b/spec/ruby/core/exception/full_message_spec.rb
@@ -165,52 +165,62 @@ describe "Exception#full_message" do
exception.full_message.should include "origin exception"
end
- ruby_version_is "3.2" do
- it "relies on #detailed_message" do
- e = RuntimeError.new("new error")
- e.define_singleton_method(:detailed_message) { |**| "DETAILED MESSAGE" }
+ it "relies on #detailed_message" do
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| "DETAILED MESSAGE" }
- e.full_message.lines.first.should =~ /DETAILED MESSAGE/
+ e.full_message.lines.first.should =~ /DETAILED MESSAGE/
+ end
+
+ it "passes all its own keyword arguments (with :highlight default value and without :order default value) to #detailed_message" do
+ e = RuntimeError.new("new error")
+ options_passed = nil
+ e.define_singleton_method(:detailed_message) do |**options|
+ options_passed = options
+ "DETAILED MESSAGE"
end
- it "passes all its own keyword arguments (with :highlight default value and without :order default value) to #detailed_message" do
- e = RuntimeError.new("new error")
- options_passed = nil
- e.define_singleton_method(:detailed_message) do |**options|
- options_passed = options
- "DETAILED MESSAGE"
- end
+ e.full_message(foo: "bar")
+ options_passed.should == { foo: "bar", highlight: Exception.to_tty? }
+ end
- e.full_message(foo: "bar")
- options_passed.should == { foo: "bar", highlight: Exception.to_tty? }
- end
+ it "converts #detailed_message returned value to String if it isn't a String" do
+ message = Object.new
+ def message.to_str; "DETAILED MESSAGE"; end
- it "converts #detailed_message returned value to String if it isn't a String" do
- message = Object.new
- def message.to_str; "DETAILED MESSAGE"; end
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| message }
- e = RuntimeError.new("new error")
- e.define_singleton_method(:detailed_message) { |**| message }
+ e.full_message.lines.first.should =~ /DETAILED MESSAGE/
+ end
- e.full_message.lines.first.should =~ /DETAILED MESSAGE/
- end
+ it "uses class name if #detailed_message returns nil" do
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| nil }
- it "uses class name if #detailed_message returns nil" do
- e = RuntimeError.new("new error")
- e.define_singleton_method(:detailed_message) { |**| nil }
+ e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
+ e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ end
- e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
- e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ it "uses class name if exception object doesn't respond to #detailed_message" do
+ e = RuntimeError.new("new error")
+ class << e
+ undef :detailed_message
end
- it "uses class name if exception object doesn't respond to #detailed_message" do
- e = RuntimeError.new("new error")
- class << e
- undef :detailed_message
- end
+ e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
+ e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ end
- e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
- e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ it "allows cause with empty backtrace" do
+ begin
+ raise RuntimeError.new("Some runtime error"), cause: RuntimeError.new("Some other runtime error")
+ rescue => e
end
+
+ full_message = e.full_message
+ full_message.should include "RuntimeError"
+ full_message.should include "Some runtime error"
+ full_message.should include "Some other runtime error"
end
end
diff --git a/spec/ruby/core/exception/set_backtrace_spec.rb b/spec/ruby/core/exception/set_backtrace_spec.rb
index 12c1da919c..2cd93326ec 100644
--- a/spec/ruby/core/exception/set_backtrace_spec.rb
+++ b/spec/ruby/core/exception/set_backtrace_spec.rb
@@ -1,13 +1,8 @@
require_relative '../../spec_helper'
require_relative 'fixtures/common'
+require_relative 'shared/set_backtrace'
describe "Exception#set_backtrace" do
- it "accepts an Array of Strings" do
- err = RuntimeError.new
- err.set_backtrace ["unhappy"]
- err.backtrace.should == ["unhappy"]
- end
-
it "allows the user to set the backtrace from a rescued exception" do
bt = ExceptionSpecs::Backtrace.backtrace
err = RuntimeError.new
@@ -20,65 +15,9 @@ describe "Exception#set_backtrace" do
err.backtrace_locations.should == nil
end
- ruby_version_is "3.4" do
- it "allows the user to set backtrace locations from a rescued exception" do
- bt_locations = ExceptionSpecs::Backtrace.backtrace_locations
- err = RuntimeError.new
- err.backtrace.should == nil
- err.backtrace_locations.should == nil
-
- err.set_backtrace bt_locations
-
- err.backtrace_locations.size.should == bt_locations.size
- err.backtrace_locations.each_with_index do |loc, index|
- other_loc = bt_locations[index]
-
- loc.path.should == other_loc.path
- loc.label.should == other_loc.label
- loc.base_label.should == other_loc.base_label
- loc.lineno.should == other_loc.lineno
- loc.absolute_path.should == other_loc.absolute_path
- loc.to_s.should == other_loc.to_s
- end
- err.backtrace.size.should == err.backtrace_locations.size
- end
- end
-
- it "accepts an empty Array" do
- err = RuntimeError.new
- err.set_backtrace []
- err.backtrace.should == []
- end
-
- it "accepts a String" do
+ it_behaves_like :exception_set_backtrace, -> backtrace {
err = RuntimeError.new
- err.set_backtrace "unhappy"
- err.backtrace.should == ["unhappy"]
- end
-
- it "accepts nil" do
- err = RuntimeError.new
- err.set_backtrace nil
- err.backtrace.should be_nil
- end
-
- it "raises a TypeError when passed a Symbol" do
- err = RuntimeError.new
- -> { err.set_backtrace :unhappy }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when the Array contains a Symbol" do
- err = RuntimeError.new
- -> { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when the array contains nil" do
- err = Exception.new
- -> { err.set_backtrace ["String", nil] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when the argument is a nested array" do
- err = Exception.new
- -> { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError)
- end
+ err.set_backtrace(backtrace)
+ err
+ }
end
diff --git a/spec/ruby/core/exception/shared/set_backtrace.rb b/spec/ruby/core/exception/shared/set_backtrace.rb
new file mode 100644
index 0000000000..c6213b42b4
--- /dev/null
+++ b/spec/ruby/core/exception/shared/set_backtrace.rb
@@ -0,0 +1,64 @@
+require_relative '../fixtures/common'
+
+describe :exception_set_backtrace, shared: true do
+ it "accepts an Array of Strings" do
+ err = @method.call(["unhappy"])
+ err.backtrace.should == ["unhappy"]
+ end
+
+ it "allows the user to set the backtrace from a rescued exception" do
+ bt = ExceptionSpecs::Backtrace.backtrace
+ err = @method.call(bt)
+ err.backtrace.should == bt
+ end
+
+ ruby_version_is "3.4" do
+ it "allows the user to set backtrace locations from a rescued exception" do
+ bt_locations = ExceptionSpecs::Backtrace.backtrace_locations
+ err = @method.call(bt_locations)
+ err.backtrace_locations.size.should == bt_locations.size
+ err.backtrace_locations.each_with_index do |loc, index|
+ other_loc = bt_locations[index]
+
+ loc.path.should == other_loc.path
+ loc.label.should == other_loc.label
+ loc.base_label.should == other_loc.base_label
+ loc.lineno.should == other_loc.lineno
+ loc.absolute_path.should == other_loc.absolute_path
+ loc.to_s.should == other_loc.to_s
+ end
+ err.backtrace.size.should == err.backtrace_locations.size
+ end
+ end
+
+ it "accepts an empty Array" do
+ err = @method.call([])
+ err.backtrace.should == []
+ end
+
+ it "accepts a String" do
+ err = @method.call("unhappy")
+ err.backtrace.should == ["unhappy"]
+ end
+
+ it "accepts nil" do
+ err = @method.call(nil)
+ err.backtrace.should be_nil
+ end
+
+ it "raises a TypeError when passed a Symbol" do
+ -> { @method.call(:unhappy) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when the Array contains a Symbol" do
+ -> { @method.call(["String", :unhappy]) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when the array contains nil" do
+ -> { @method.call(["String", nil]) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when the argument is a nested array" do
+ -> { @method.call(["String", ["String"]]) }.should raise_error(TypeError)
+ end
+end
diff --git a/spec/ruby/core/exception/syntax_error_spec.rb b/spec/ruby/core/exception/syntax_error_spec.rb
index 6cc8522de3..4c713a3507 100644
--- a/spec/ruby/core/exception/syntax_error_spec.rb
+++ b/spec/ruby/core/exception/syntax_error_spec.rb
@@ -1,27 +1,25 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "SyntaxError#path" do
- it "returns the file path provided to eval" do
- filename = "speccing.rb"
+describe "SyntaxError#path" do
+ it "returns the file path provided to eval" do
+ filename = "speccing.rb"
- -> {
- eval("if true", TOPLEVEL_BINDING, filename)
- }.should raise_error(SyntaxError) { |e|
- e.path.should == filename
- }
- end
+ -> {
+ eval("if true", TOPLEVEL_BINDING, filename)
+ }.should raise_error(SyntaxError) { |e|
+ e.path.should == filename
+ }
+ end
- it "returns the file path that raised an exception" do
- expected_path = fixture(__FILE__, "syntax_error.rb")
+ it "returns the file path that raised an exception" do
+ expected_path = fixture(__FILE__, "syntax_error.rb")
- -> {
- require_relative "fixtures/syntax_error"
- }.should raise_error(SyntaxError) { |e| e.path.should == expected_path }
- end
+ -> {
+ require_relative "fixtures/syntax_error"
+ }.should raise_error(SyntaxError) { |e| e.path.should == expected_path }
+ end
- it "returns nil when constructed directly" do
- SyntaxError.new.path.should == nil
- end
+ it "returns nil when constructed directly" do
+ SyntaxError.new.path.should == nil
end
end
diff --git a/spec/ruby/core/fiber/blocking_spec.rb b/spec/ruby/core/fiber/blocking_spec.rb
index ed3c057516..d5caf81fbe 100644
--- a/spec/ruby/core/fiber/blocking_spec.rb
+++ b/spec/ruby/core/fiber/blocking_spec.rb
@@ -57,19 +57,17 @@ describe "Fiber#blocking?" do
end
end
-ruby_version_is "3.2" do
- describe "Fiber.blocking" do
- context "when fiber is non-blocking" do
- it "can become blocking" do
- fiber = Fiber.new(blocking: false) do
- Fiber.blocking do |f|
- f.blocking? ? :blocking : :non_blocking
- end
+describe "Fiber.blocking" do
+ context "when fiber is non-blocking" do
+ it "can become blocking" do
+ fiber = Fiber.new(blocking: false) do
+ Fiber.blocking do |f|
+ f.blocking? ? :blocking : :non_blocking
end
-
- blocking = fiber.resume
- blocking.should == :blocking
end
+
+ blocking = fiber.resume
+ blocking.should == :blocking
end
end
end
diff --git a/spec/ruby/core/fiber/fixtures/classes.rb b/spec/ruby/core/fiber/fixtures/classes.rb
index c00facd6e1..6b0e0fbc42 100644
--- a/spec/ruby/core/fiber/fixtures/classes.rb
+++ b/spec/ruby/core/fiber/fixtures/classes.rb
@@ -1,10 +1,20 @@
module FiberSpecs
class NewFiberToRaise
- def self.raise(*args)
- fiber = Fiber.new { Fiber.yield }
+ def self.raise(*args, **kwargs, &block)
+ fiber = Fiber.new do
+ if block_given?
+ block.call do
+ Fiber.yield
+ end
+ else
+ Fiber.yield
+ end
+ end
+
fiber.resume
- fiber.raise(*args)
+
+ fiber.raise(*args, **kwargs)
end
end
diff --git a/spec/ruby/core/fiber/fixtures/scheduler.rb b/spec/ruby/core/fiber/fixtures/scheduler.rb
new file mode 100644
index 0000000000..16bd2f6b44
--- /dev/null
+++ b/spec/ruby/core/fiber/fixtures/scheduler.rb
@@ -0,0 +1,35 @@
+module FiberSpecs
+
+ class LoggingScheduler
+ attr_reader :events
+ def initialize
+ @events = []
+ end
+
+ def block(*args)
+ @events << { event: :block, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def io_wait(*args)
+ @events << { event: :io_wait, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def kernel_sleep(*args)
+ @events << { event: :kernel_sleep, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def unblock(*args)
+ @events << { event: :unblock, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def fiber_interrupt(*args)
+ @events << { event: :fiber_interrupt, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+ end
+
+end
diff --git a/spec/ruby/core/fiber/raise_spec.rb b/spec/ruby/core/fiber/raise_spec.rb
index 124f56fe7d..896f760290 100644
--- a/spec/ruby/core/fiber/raise_spec.rb
+++ b/spec/ruby/core/fiber/raise_spec.rb
@@ -4,6 +4,7 @@ require_relative '../../shared/kernel/raise'
describe "Fiber#raise" do
it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
+ it_behaves_like :kernel_raise_across_contexts, :raise, FiberSpecs::NewFiberToRaise
end
describe "Fiber#raise" do
diff --git a/spec/ruby/core/fiber/scheduler_spec.rb b/spec/ruby/core/fiber/scheduler_spec.rb
new file mode 100644
index 0000000000..15a03c1479
--- /dev/null
+++ b/spec/ruby/core/fiber/scheduler_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'shared/scheduler'
+
+require "fiber"
+
+describe "Fiber.scheduler" do
+ it_behaves_like :scheduler, :scheduler
+end
diff --git a/spec/ruby/core/fiber/set_scheduler_spec.rb b/spec/ruby/core/fiber/set_scheduler_spec.rb
new file mode 100644
index 0000000000..82f6acbe86
--- /dev/null
+++ b/spec/ruby/core/fiber/set_scheduler_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'shared/scheduler'
+
+require "fiber"
+
+describe "Fiber.scheduler" do
+ it_behaves_like :scheduler, :set_scheduler
+end
diff --git a/spec/ruby/core/fiber/shared/scheduler.rb b/spec/ruby/core/fiber/shared/scheduler.rb
new file mode 100644
index 0000000000..19bfb75e3e
--- /dev/null
+++ b/spec/ruby/core/fiber/shared/scheduler.rb
@@ -0,0 +1,51 @@
+describe :scheduler, shared: true do
+ it "validates the scheduler for required methods" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ required_methods.each do |missing_method|
+ scheduler = Object.new
+ required_methods.difference([missing_method]).each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ -> {
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ }.should raise_error(ArgumentError, /Scheduler must implement ##{missing_method}/)
+ end
+ end
+
+ it "can set and get the scheduler" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ Fiber.scheduler.should == scheduler
+ end
+
+ it "returns the scheduler after setting it" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ result = suppress_warning { Fiber.set_scheduler(scheduler) }
+ result.should == scheduler
+ end
+
+ it "can remove the scheduler" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ Fiber.set_scheduler(nil)
+ Fiber.scheduler.should be_nil
+ end
+
+ it "can assign a nil scheduler multiple times" do
+ Fiber.set_scheduler(nil)
+ Fiber.set_scheduler(nil)
+ Fiber.scheduler.should be_nil
+ end
+end
diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb
index 03e9e3b822..015caaf3bb 100644
--- a/spec/ruby/core/fiber/storage_spec.rb
+++ b/spec/ruby/core/fiber/storage_spec.rb
@@ -1,183 +1,181 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Fiber.new(storage:)" do
- it "creates a Fiber with the given storage" do
- storage = {life: 42}
- fiber = Fiber.new(storage: storage) { Fiber.current.storage }
- fiber.resume.should == storage
- end
-
- it "creates a fiber with lazily initialized storage" do
- Fiber.new(storage: nil) { Fiber[:x] = 10; Fiber.current.storage }.resume.should == {x: 10}
- end
+describe "Fiber.new(storage:)" do
+ it "creates a Fiber with the given storage" do
+ storage = {life: 42}
+ fiber = Fiber.new(storage: storage) { Fiber.current.storage }
+ fiber.resume.should == storage
+ end
- it "creates a fiber by inheriting the storage of the parent fiber" do
- fiber = Fiber.new(storage: {life: 42}) do
- Fiber.new { Fiber.current.storage }.resume
- end
- fiber.resume.should == {life: 42}
- end
+ it "creates a fiber with lazily initialized storage" do
+ Fiber.new(storage: nil) { Fiber[:x] = 10; Fiber.current.storage }.resume.should == {x: 10}
+ end
- it "cannot create a fiber with non-hash storage" do
- -> { Fiber.new(storage: 42) {} }.should raise_error(TypeError)
+ it "creates a fiber by inheriting the storage of the parent fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.new { Fiber.current.storage }.resume
end
+ fiber.resume.should == {life: 42}
+ end
- it "cannot create a fiber with a frozen hash as storage" do
- -> { Fiber.new(storage: {life: 43}.freeze) {} }.should raise_error(FrozenError)
- end
+ it "cannot create a fiber with non-hash storage" do
+ -> { Fiber.new(storage: 42) {} }.should raise_error(TypeError)
+ end
- it "cannot create a fiber with a storage hash with non-symbol keys" do
- -> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should raise_error(TypeError)
- end
+ it "cannot create a fiber with a frozen hash as storage" do
+ -> { Fiber.new(storage: {life: 43}.freeze) {} }.should raise_error(FrozenError)
end
- describe "Fiber#storage" do
- it "cannot be accessed from a different fiber" do
- f = Fiber.new(storage: {life: 42}) { nil }
- -> {
- f.storage
- }.should raise_error(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/)
- end
+ it "cannot create a fiber with a storage hash with non-symbol keys" do
+ -> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should raise_error(TypeError)
end
+end
- describe "Fiber#storage=" do
- it "can clear the storage of the fiber" do
- fiber = Fiber.new(storage: {life: 42}) do
- Fiber.current.storage = nil
- Fiber[:x] = 10
- Fiber.current.storage
- end
- fiber.resume.should == {x: 10}
- end
+describe "Fiber#storage" do
+ it "cannot be accessed from a different fiber" do
+ f = Fiber.new(storage: {life: 42}) { nil }
+ -> {
+ f.storage
+ }.should raise_error(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/)
+ end
+end
- it "can set the storage of the fiber" do
- fiber = Fiber.new(storage: {life: 42}) do
- Fiber.current.storage = {life: 43}
- Fiber.current.storage
- end
- fiber.resume.should == {life: 43}
+describe "Fiber#storage=" do
+ it "can clear the storage of the fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.current.storage = nil
+ Fiber[:x] = 10
+ Fiber.current.storage
end
+ fiber.resume.should == {x: 10}
+ end
- it "can't set the storage of the fiber to non-hash" do
- -> { Fiber.current.storage = 42 }.should raise_error(TypeError)
+ it "can set the storage of the fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.current.storage = {life: 43}
+ Fiber.current.storage
end
+ fiber.resume.should == {life: 43}
+ end
- it "can't set the storage of the fiber to a frozen hash" do
- -> { Fiber.current.storage = {life: 43}.freeze }.should raise_error(FrozenError)
- end
+ it "can't set the storage of the fiber to non-hash" do
+ -> { Fiber.current.storage = 42 }.should raise_error(TypeError)
+ end
- it "can't set the storage of the fiber to a hash with non-symbol keys" do
- -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
- end
+ it "can't set the storage of the fiber to a frozen hash" do
+ -> { Fiber.current.storage = {life: 43}.freeze }.should raise_error(FrozenError)
end
- describe "Fiber.[]" do
- it "returns the value of the given key in the storage of the current fiber" do
- Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42
- end
+ it "can't set the storage of the fiber to a hash with non-symbol keys" do
+ -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError)
+ end
+end
- it "returns nil if the key is not present in the storage of the current fiber" do
- Fiber.new(storage: {life: 42}) { Fiber[:death] }.resume.should be_nil
- end
+describe "Fiber.[]" do
+ it "returns the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42
+ end
- it "returns nil if the current fiber has no storage" do
- Fiber.new { Fiber[:life] }.resume.should be_nil
- end
+ it "returns nil if the key is not present in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:death] }.resume.should be_nil
+ end
- ruby_version_is "3.2.3" do
- it "can use dynamically defined keys" do
- key = :"#{self.class.name}#.#{self.object_id}"
- Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
- end
+ it "returns nil if the current fiber has no storage" do
+ Fiber.new { Fiber[:life] }.resume.should be_nil
+ end
- it "can't use invalid keys" do
- invalid_keys = [Object.new, 12]
- invalid_keys.each do |key|
- -> { Fiber[key] }.should raise_error(TypeError)
- end
- end
+ ruby_version_is "3.2.3" do
+ it "can use dynamically defined keys" do
+ key = :"#{self.class.name}#.#{self.object_id}"
+ Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
end
- ruby_bug "#20978", "3.2"..."3.4" do
- it "can use keys as strings" do
- key = Object.new
- def key.to_str; "Foo"; end
- Fiber.new { Fiber[key] = 42; Fiber["Foo"] }.resume.should == 42
+ it "can't use invalid keys" do
+ invalid_keys = [Object.new, 12]
+ invalid_keys.each do |key|
+ -> { Fiber[key] }.should raise_error(TypeError)
end
+ end
+ end
- it "converts a String key into a Symbol" do
- Fiber.new { Fiber["key"] = 42; Fiber[:key] }.resume.should == 42
- Fiber.new { Fiber[:key] = 42; Fiber["key"] }.resume.should == 42
- end
+ ruby_bug "#20978", ""..."3.4" do
+ it "can use keys as strings" do
+ key = Object.new
+ def key.to_str; "Foo"; end
+ Fiber.new { Fiber[key] = 42; Fiber["Foo"] }.resume.should == 42
+ end
- it "can use any object that responds to #to_str as a key" do
- key = mock("key")
- key.should_receive(:to_str).twice.and_return("key")
- Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
- end
+ it "converts a String key into a Symbol" do
+ Fiber.new { Fiber["key"] = 42; Fiber[:key] }.resume.should == 42
+ Fiber.new { Fiber[:key] = 42; Fiber["key"] }.resume.should == 42
end
- it "does not call #to_sym on the key" do
+ it "can use any object that responds to #to_str as a key" do
key = mock("key")
- key.should_not_receive(:to_sym)
- -> { Fiber[key] }.should raise_error(TypeError)
+ key.should_receive(:to_str).twice.and_return("key")
+ Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
end
+ end
- it "can access the storage of the parent fiber" do
- f = Fiber.new(storage: {life: 42}) do
- Fiber.new { Fiber[:life] }.resume
- end
- f.resume.should == 42
- end
+ it "does not call #to_sym on the key" do
+ key = mock("key")
+ key.should_not_receive(:to_sym)
+ -> { Fiber[key] }.should raise_error(TypeError)
+ end
- it "can't access the storage of the fiber with non-symbol keys" do
- -> { Fiber[Object.new] }.should raise_error(TypeError)
+ it "can access the storage of the parent fiber" do
+ f = Fiber.new(storage: {life: 42}) do
+ Fiber.new { Fiber[:life] }.resume
end
+ f.resume.should == 42
end
- describe "Fiber.[]=" do
- it "sets the value of the given key in the storage of the current fiber" do
- Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
- end
+ it "can't access the storage of the fiber with non-symbol keys" do
+ -> { Fiber[Object.new] }.should raise_error(TypeError)
+ end
+end
- it "sets the value of the given key in the storage of the current fiber" do
- Fiber.new(storage: {life: 42}) { Fiber[:death] = 43; Fiber[:death] }.resume.should == 43
- end
+describe "Fiber.[]=" do
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
+ end
- it "sets the value of the given key in the storage of the current fiber" do
- Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
- end
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:death] = 43; Fiber[:death] }.resume.should == 43
+ end
- it "does not overwrite the storage of the parent fiber" do
- f = Fiber.new(storage: {life: 42}) do
- Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume
- Fiber[:life]
- end
- f.resume.should == 43 # Value of the inner fiber
- f.resume.should == 42 # Value of the outer fiber
- end
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
+ end
- it "can't access the storage of the fiber with non-symbol keys" do
- -> { Fiber[Object.new] = 44 }.should raise_error(TypeError)
+ it "does not overwrite the storage of the parent fiber" do
+ f = Fiber.new(storage: {life: 42}) do
+ Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume
+ Fiber[:life]
end
+ f.resume.should == 43 # Value of the inner fiber
+ f.resume.should == 42 # Value of the outer fiber
+ end
- ruby_version_is "3.3" do
- it "deletes the fiber storage key when assigning nil" do
- Fiber.new(storage: {life: 42}) {
- Fiber[:life] = nil
- Fiber.current.storage
- }.resume.should == {}
- end
+ it "can't access the storage of the fiber with non-symbol keys" do
+ -> { Fiber[Object.new] = 44 }.should raise_error(TypeError)
+ end
+
+ ruby_version_is "3.3" do
+ it "deletes the fiber storage key when assigning nil" do
+ Fiber.new(storage: {life: 42}) {
+ Fiber[:life] = nil
+ Fiber.current.storage
+ }.resume.should == {}
end
end
+end
- describe "Thread.new" do
- it "creates a thread with the storage of the current fiber" do
- fiber = Fiber.new(storage: {life: 42}) do
- Thread.new { Fiber.current.storage }.value
- end
- fiber.resume.should == {life: 42}
+describe "Thread.new" do
+ it "creates a thread with the storage of the current fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Thread.new { Fiber.current.storage }.value
end
+ fiber.resume.should == {life: 42}
end
end
diff --git a/spec/ruby/core/file/birthtime_spec.rb b/spec/ruby/core/file/birthtime_spec.rb
index 755601df64..f82eaf7cca 100644
--- a/spec/ruby/core/file/birthtime_spec.rb
+++ b/spec/ruby/core/file/birthtime_spec.rb
@@ -1,60 +1,56 @@
require_relative '../../spec_helper'
-describe "File.birthtime" do
- before :each do
- @file = __FILE__
- end
+platform_is :windows, :darwin, :freebsd, :netbsd, :linux do
+ not_implemented_messages = [
+ "birthtime() function is unimplemented", # unsupported OS/version
+ "birthtime is unimplemented", # unsupported filesystem
+ ]
+
+ describe "File.birthtime" do
+ before :each do
+ @file = __FILE__
+ end
- after :each do
- @file = nil
- end
+ after :each do
+ @file = nil
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
it "returns the birth time for the named file as a Time object" do
File.birthtime(@file)
File.birthtime(@file).should be_kind_of(Time)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
it "accepts an object that has a #to_path method" do
+ File.birthtime(@file) # Avoid to failure of mock object with old Kernel and glibc
File.birthtime(mock_to_path(@file))
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
it "raises an Errno::ENOENT exception if the file is not found" do
-> { File.birthtime('bogus') }.should raise_error(Errno::ENOENT)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
- platform_is :openbsd do
- it "raises an NotImplementedError" do
- -> { File.birthtime(@file) }.should raise_error(NotImplementedError)
+ describe "File#birthtime" do
+ before :each do
+ @file = File.open(__FILE__)
end
- end
-
- # TODO: depends on Linux kernel version
-end
-describe "File#birthtime" do
- before :each do
- @file = File.open(__FILE__)
- end
-
- after :each do
- @file.close
- @file = nil
- end
+ after :each do
+ @file.close
+ @file = nil
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
it "returns the birth time for self" do
@file.birthtime
@file.birthtime.should be_kind_of(Time)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
-
- platform_is :openbsd do
- it "raises an NotImplementedError" do
- -> { @file.birthtime }.should raise_error(NotImplementedError)
- end
- end
-
- # TODO: depends on Linux kernel version
end
diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb
index 2633376880..b5600e5b07 100644
--- a/spec/ruby/core/file/exist_spec.rb
+++ b/spec/ruby/core/file/exist_spec.rb
@@ -5,10 +5,8 @@ describe "File.exist?" do
it_behaves_like :file_exist, :exist?, File
end
-ruby_version_is "3.2" do
- describe "File.exists?" do
- it "has been removed" do
- File.should_not.respond_to?(:exists?)
- end
+describe "File.exists?" do
+ it "has been removed" do
+ File.should_not.respond_to?(:exists?)
end
end
diff --git a/spec/ruby/core/file/path_spec.rb b/spec/ruby/core/file/path_spec.rb
index dfa0c4ec02..726febcc2b 100644
--- a/spec/ruby/core/file/path_spec.rb
+++ b/spec/ruby/core/file/path_spec.rb
@@ -37,4 +37,45 @@ describe "File.path" do
path.should_receive(:to_path).and_return("abc")
File.path(path).should == "abc"
end
+
+ it "raises TypeError when #to_path result is not a string" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return(nil)
+ -> { File.path(path) }.should raise_error TypeError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return(42)
+ -> { File.path(path) }.should raise_error TypeError
+ end
+
+ it "raises ArgumentError for string argument contains NUL character" do
+ -> { File.path("\0") }.should raise_error ArgumentError
+ -> { File.path("a\0") }.should raise_error ArgumentError
+ -> { File.path("a\0c") }.should raise_error ArgumentError
+ end
+
+ it "raises ArgumentError when #to_path result contains NUL character" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return("\0")
+ -> { File.path(path) }.should raise_error ArgumentError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return("a\0")
+ -> { File.path(path) }.should raise_error ArgumentError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return("a\0c")
+ -> { File.path(path) }.should raise_error ArgumentError
+ end
+
+ it "raises Encoding::CompatibilityError for ASCII-incompatible string argument" do
+ path = "abc".encode(Encoding::UTF_32BE)
+ -> { File.path(path) }.should raise_error Encoding::CompatibilityError
+ end
+
+ it "raises Encoding::CompatibilityError when #to_path result is ASCII-incompatible" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return("abc".encode(Encoding::UTF_32BE))
+ -> { File.path(path) }.should raise_error Encoding::CompatibilityError
+ end
end
diff --git a/spec/ruby/core/file/socket_spec.rb b/spec/ruby/core/file/socket_spec.rb
index 5d12e21f55..d3f4eb013a 100644
--- a/spec/ruby/core/file/socket_spec.rb
+++ b/spec/ruby/core/file/socket_spec.rb
@@ -1,42 +1,10 @@
require_relative '../../spec_helper'
require_relative '../../shared/file/socket'
-require 'socket'
describe "File.socket?" do
it_behaves_like :file_socket, :socket?, File
-end
-describe "File.socket?" do
it "returns false if file does not exist" do
File.socket?("I_am_a_bogus_file").should == false
end
-
- it "returns false if the file is not a socket" do
- filename = tmp("i_exist")
- touch(filename)
-
- File.socket?(filename).should == false
-
- rm_r filename
- end
-end
-
-platform_is_not :windows do
- describe "File.socket?" do
- before :each do
- # We need a really short name here.
- # On Linux the path length is limited to 107, see unix(7).
- @name = tmp("s")
- @server = UNIXServer.new @name
- end
-
- after :each do
- @server.close
- rm_r @name
- end
-
- it "returns true if the file is a socket" do
- File.socket?(@name).should == true
- end
- end
end
diff --git a/spec/ruby/core/file/stat/birthtime_spec.rb b/spec/ruby/core/file/stat/birthtime_spec.rb
index a727bbe566..9aa39297b2 100644
--- a/spec/ruby/core/file/stat/birthtime_spec.rb
+++ b/spec/ruby/core/file/stat/birthtime_spec.rb
@@ -1,27 +1,29 @@
require_relative '../../../spec_helper'
-describe "File::Stat#birthtime" do
- before :each do
- @file = tmp('i_exist')
- touch(@file) { |f| f.write "rubinius" }
- end
+platform_is(:windows, :darwin, :freebsd, :netbsd,
+ *ruby_version_is("4.0") { :linux },
+ ) do
+ not_implemented_messages = [
+ "birthtime() function is unimplemented", # unsupported OS/version
+ "birthtime is unimplemented", # unsupported filesystem
+ ]
- after :each do
- rm_r @file
- end
+ describe "File::Stat#birthtime" do
+ before :each do
+ @file = tmp('i_exist')
+ touch(@file) { |f| f.write "rubinius" }
+ end
+
+ after :each do
+ rm_r @file
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
it "returns the birthtime of a File::Stat object" do
st = File.stat(@file)
st.birthtime.should be_kind_of(Time)
st.birthtime.should <= Time.now
- end
- end
-
- platform_is :linux, :openbsd do
- it "raises an NotImplementedError" do
- st = File.stat(@file)
- -> { st.birthtime }.should raise_error(NotImplementedError)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
end
diff --git a/spec/ruby/core/filetest/exist_spec.rb b/spec/ruby/core/filetest/exist_spec.rb
index a95d3f91a1..612ffa9fcb 100644
--- a/spec/ruby/core/filetest/exist_spec.rb
+++ b/spec/ruby/core/filetest/exist_spec.rb
@@ -5,10 +5,8 @@ describe "FileTest.exist?" do
it_behaves_like :file_exist, :exist?, FileTest
end
-ruby_version_is "3.2" do
- describe "FileTest.exists?" do
- it "has been removed" do
- FileTest.should_not.respond_to?(:exists?)
- end
+describe "FileTest.exists?" do
+ it "has been removed" do
+ FileTest.should_not.respond_to?(:exists?)
end
end
diff --git a/spec/ruby/core/filetest/socket_spec.rb b/spec/ruby/core/filetest/socket_spec.rb
index 63a6a31ecb..f274be6318 100644
--- a/spec/ruby/core/filetest/socket_spec.rb
+++ b/spec/ruby/core/filetest/socket_spec.rb
@@ -3,4 +3,8 @@ require_relative '../../shared/file/socket'
describe "FileTest.socket?" do
it_behaves_like :file_socket, :socket?, FileTest
+
+ it "returns false if file does not exist" do
+ FileTest.socket?("I_am_a_bogus_file").should == false
+ end
end
diff --git a/spec/ruby/core/gc/config_spec.rb b/spec/ruby/core/gc/config_spec.rb
new file mode 100644
index 0000000000..e20e8e4a16
--- /dev/null
+++ b/spec/ruby/core/gc/config_spec.rb
@@ -0,0 +1,83 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "GC.config" do
+ context "without arguments" do
+ it "returns a hash of current settings" do
+ GC.config.should be_kind_of(Hash)
+ end
+
+ it "includes the name of currently loaded GC implementation as a global key" do
+ GC.config.should include(:implementation)
+ GC.config[:implementation].should be_kind_of(String)
+ end
+ end
+
+ context "with a hash of options" do
+ it "allows to set GC implementation's options, returning the new config" do
+ config = GC.config({})
+ # Try to find a boolean setting to reliably test changing it.
+ key, _value = config.find { |_k, v| v == true }
+ skip unless key
+
+ GC.config(key => false).should == config.merge(key => false)
+ GC.config[key].should == false
+ GC.config(key => true).should == config
+ GC.config[key].should == true
+ ensure
+ GC.config(config.except(:implementation))
+ end
+
+ it "does not change settings that aren't present in the hash" do
+ previous = GC.config
+ GC.config({})
+ GC.config.should == previous
+ end
+
+ it "ignores unknown keys" do
+ previous = GC.config
+ GC.config(foo: "bar")
+ GC.config.should == previous
+ end
+
+ it "raises an ArgumentError if options include global keys" do
+ -> { GC.config(implementation: "default") }.should raise_error(ArgumentError, 'Attempting to set read-only key "Implementation"')
+ end
+ end
+
+ context "with a non-hash argument" do
+ it "returns current settings if argument is nil" do
+ GC.config(nil).should == GC.config
+ end
+
+ it "raises ArgumentError for all other arguments" do
+ -> { GC.config([]) }.should raise_error(ArgumentError)
+ -> { GC.config("default") }.should raise_error(ArgumentError)
+ -> { GC.config(1) }.should raise_error(ArgumentError)
+ end
+ end
+
+ guard -> { PlatformGuard.standard? && GC.config[:implementation] == "default" } do
+ context "with default GC implementation on MRI" do
+ before do
+ @default_config = GC.config({})
+ end
+
+ after do
+ GC.config(@default_config.except(:implementation))
+ end
+
+ it "includes :rgengc_allow_full_mark option, true by default" do
+ GC.config.should include(:rgengc_allow_full_mark)
+ GC.config[:rgengc_allow_full_mark].should be_true
+ end
+
+ it "allows to set :rgengc_allow_full_mark" do
+ # This key maps truthy and falsey values to true and false.
+ GC.config(rgengc_allow_full_mark: nil).should == @default_config.merge(rgengc_allow_full_mark: false)
+ GC.config(rgengc_allow_full_mark: 1.23).should == @default_config.merge(rgengc_allow_full_mark: true)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/hash/compact_spec.rb b/spec/ruby/core/hash/compact_spec.rb
index 76aa43949d..13371bce43 100644
--- a/spec/ruby/core/hash/compact_spec.rb
+++ b/spec/ruby/core/hash/compact_spec.rb
@@ -35,7 +35,7 @@ describe "Hash#compact" do
hash.compact.default_proc.should == pr
end
- it "retains compare_by_identity_flag" do
+ it "retains compare_by_identity flag" do
hash = {}.compare_by_identity
hash.compact.compare_by_identity?.should == true
hash[:a] = 1
diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb
index 8d29773909..0f97f7b40e 100644
--- a/spec/ruby/core/hash/constructor_spec.rb
+++ b/spec/ruby/core/hash/constructor_spec.rb
@@ -103,14 +103,14 @@ describe "Hash.[]" do
HashSpecs::MyInitializerHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyInitializerHash)
end
- it "removes the default value" do
+ it "does not retain the default value" do
hash = Hash.new(1)
Hash[hash].default.should be_nil
hash[:a] = 1
Hash[hash].default.should be_nil
end
- it "removes the default_proc" do
+ it "does not retain the default_proc" do
hash = Hash.new { |h, k| h[k] = [] }
Hash[hash].default_proc.should be_nil
hash[:a] = 1
@@ -118,10 +118,11 @@ describe "Hash.[]" do
end
ruby_version_is '3.3' do
- it "does not retain compare_by_identity_flag" do
- hash = {}.compare_by_identity
+ it "does not retain compare_by_identity flag" do
+ hash = { a: 1 }.compare_by_identity
Hash[hash].compare_by_identity?.should == false
- hash[:a] = 1
+
+ hash = {}.compare_by_identity
Hash[hash].compare_by_identity?.should == false
end
end
diff --git a/spec/ruby/core/hash/except_spec.rb b/spec/ruby/core/hash/except_spec.rb
index ac84f9975c..026e454b13 100644
--- a/spec/ruby/core/hash/except_spec.rb
+++ b/spec/ruby/core/hash/except_spec.rb
@@ -19,14 +19,24 @@ describe "Hash#except" do
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
end
- it "always returns a Hash without a default" do
- klass = Class.new(Hash)
- h = klass.new(:default)
- h[:bar] = 12
- h[:foo] = 42
- r = h.except(:foo)
- r.should == {bar: 12}
- r.class.should == Hash
- r.default.should == nil
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.except(:a).default.should be_nil
+ h[:a] = 1
+ h.except(:a).default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.except(:a).default_proc.should be_nil
+ h[:a] = 1
+ h.except(:a).default_proc.should be_nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.except(:a)
+ h2.compare_by_identity?.should == true
end
end
diff --git a/spec/ruby/core/hash/invert_spec.rb b/spec/ruby/core/hash/invert_spec.rb
index 73377a9e97..c06e15ff7c 100644
--- a/spec/ruby/core/hash/invert_spec.rb
+++ b/spec/ruby/core/hash/invert_spec.rb
@@ -24,4 +24,25 @@ describe "Hash#invert" do
HashSpecs::MyHash[1 => 2, 3 => 4].invert.class.should == Hash
HashSpecs::MyHash[].invert.class.should == Hash
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.invert.default.should be_nil
+ h[:a] = 1
+ h.invert.default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.invert.default_proc.should be_nil
+ h[:a] = 1
+ h.invert.default_proc.should be_nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.invert
+ h2.compare_by_identity?.should == false
+ end
end
diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb
index 5521864297..6710d121ef 100644
--- a/spec/ruby/core/hash/merge_spec.rb
+++ b/spec/ruby/core/hash/merge_spec.rb
@@ -93,6 +93,29 @@ describe "Hash#merge" do
merged.should eql(hash)
merged.should_not equal(hash)
end
+
+ it "retains the default value" do
+ h = Hash.new(1)
+ h.merge(b: 1, d: 2).default.should == 1
+ end
+
+ it "retains the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.merge(b: 1, d: 2).default_proc.should == pr
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.merge(b: 1, d: 2)
+ h2.compare_by_identity?.should == true
+ end
+
+ it "ignores compare_by_identity flag of an argument" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = { b: 1, d: 2 }.merge(h)
+ h2.compare_by_identity?.should == false
+ end
end
describe "Hash#merge!" do
diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb
index dd8e817237..8381fc7fc1 100644
--- a/spec/ruby/core/hash/reject_spec.rb
+++ b/spec/ruby/core/hash/reject_spec.rb
@@ -44,6 +44,27 @@ describe "Hash#reject" do
reject_pairs.should == reject_bang_pairs
end
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.reject { false }.default.should be_nil
+ h[:a] = 1
+ h.reject { false }.default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.reject { false }.default_proc.should be_nil
+ h[:a] = 1
+ h.reject { false }.default_proc.should be_nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.reject { |k, _| k == :a }
+ h2.compare_by_identity?.should == true
+ end
+
it_behaves_like :hash_iteration_no_block, :reject
it_behaves_like :enumeratorized_with_origin_size, :reject, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/replace_spec.rb b/spec/ruby/core/hash/replace_spec.rb
index a26a31f5f9..db30145e1a 100644
--- a/spec/ruby/core/hash/replace_spec.rb
+++ b/spec/ruby/core/hash/replace_spec.rb
@@ -23,39 +23,48 @@ describe "Hash#replace" do
h.should == { 1 => 2 }
end
- it "transfers the compare_by_identity flag" do
- hash_a = { a: 1 }
- hash_b = { b: 2 }
- hash_b.compare_by_identity
- hash_a.should_not.compare_by_identity?
- hash_a.replace(hash_b)
- hash_a.should.compare_by_identity?
+ it "does not retain the default value" do
+ hash = Hash.new(1)
+ hash.replace(b: 2).default.should be_nil
+ end
- hash_a = { a: 1 }
- hash_b = { b: 2 }
- hash_a.compare_by_identity
- hash_a.should.compare_by_identity?
- hash_a.replace(hash_b)
- hash_a.should_not.compare_by_identity?
+ it "transfers the default value of an argument" do
+ hash = Hash.new(1)
+ { a: 1 }.replace(hash).default.should == 1
end
- it "does not transfer default values" do
- hash_a = {}
- hash_b = Hash.new(5)
- hash_a.replace(hash_b)
- hash_a.default.should == 5
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ hash.replace(b: 2).default_proc.should be_nil
+ end
- hash_a = {}
- hash_b = Hash.new { |h, k| k * 2 }
- hash_a.replace(hash_b)
- hash_a.default(5).should == 10
+ it "transfers the default_proc of an argument" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ { a: 1 }.replace(hash).default_proc.should == pr
+ end
+ it "does not call the default_proc of an argument" do
hash_a = Hash.new { |h, k| k * 5 }
hash_b = Hash.new(-> { raise "Should not invoke lambda" })
hash_a.replace(hash_b)
hash_a.default.should == hash_b.default
end
+ it "transfers compare_by_identity flag of an argument" do
+ h = { a: 1, c: 3 }
+ h2 = { b: 2, d: 4 }.compare_by_identity
+ h.replace(h2)
+ h.compare_by_identity?.should == true
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 1, c: 3 }.compare_by_identity
+ h.replace(b: 2, d: 4)
+ h.compare_by_identity?.should == false
+ end
+
it "raises a FrozenError if called on a frozen instance that would not be modified" do
-> do
HashSpecs.frozen_hash.replace(HashSpecs.frozen_hash)
diff --git a/spec/ruby/core/hash/shared/select.rb b/spec/ruby/core/hash/shared/select.rb
index 5170af50d6..fbeff07330 100644
--- a/spec/ruby/core/hash/shared/select.rb
+++ b/spec/ruby/core/hash/shared/select.rb
@@ -40,6 +40,27 @@ describe :hash_select, shared: true do
@empty.send(@method).should be_an_instance_of(Enumerator)
end
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.send(@method) { true }.default.should be_nil
+ h[:a] = 1
+ h.send(@method) { true }.default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.send(@method) { true }.default_proc.should be_nil
+ h[:a] = 1
+ h.send(@method) { true }.default_proc.should be_nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.send(@method) { |k, _| k == :a }
+ h2.compare_by_identity?.should == true
+ end
+
it_should_behave_like :hash_iteration_no_block
before :each do
diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb
index 5f0a8f97fd..e116b8878b 100644
--- a/spec/ruby/core/hash/shared/to_s.rb
+++ b/spec/ruby/core/hash/shared/to_s.rb
@@ -84,4 +84,10 @@ describe :hash_to_s, shared: true do
expected = ruby_version_is("3.4") ? "{true => false}" : "{true=>false}"
{ true => false }.to_s.should == expected
end
+
+ ruby_version_is "3.4" do
+ it "adds quotes to symbol keys that are not valid symbol literals" do
+ { "needs-quotes": 1 }.send(@method).should == '{"needs-quotes": 1}'
+ end
+ end
end
diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb
index ea36488a04..3f31b9864c 100644
--- a/spec/ruby/core/hash/shift_spec.rb
+++ b/spec/ruby/core/hash/shift_spec.rb
@@ -30,45 +30,22 @@ describe "Hash#shift" do
h.should == {}
end
- ruby_version_is '3.2' do
- it "returns nil if the Hash is empty" do
- h = {}
- def h.default(key)
- raise
- end
- h.shift.should == nil
- end
- end
-
- ruby_version_is ''...'3.2' do
- it "calls #default with nil if the Hash is empty" do
- h = {}
- def h.default(key)
- key.should == nil
- :foo
- end
- h.shift.should == :foo
+ it "returns nil if the Hash is empty" do
+ h = {}
+ def h.default(key)
+ raise
end
+ h.shift.should == nil
end
it "returns nil from an empty hash" do
{}.shift.should == nil
end
- ruby_version_is '3.2' do
- it "returns nil for empty hashes with defaults and default procs" do
- Hash.new(5).shift.should == nil
- h = Hash.new { |*args| args }
- h.shift.should == nil
- end
- end
-
- ruby_version_is ''...'3.2' do
- it "returns (computed) default for empty hashes" do
- Hash.new(5).shift.should == 5
- h = Hash.new { |*args| args }
- h.shift.should == [h, nil]
- end
+ it "returns nil for empty hashes with defaults and default procs" do
+ Hash.new(5).shift.should == nil
+ h = Hash.new { |*args| args }
+ h.shift.should == nil
end
it "preserves Hash invariants when removing the last item" do
diff --git a/spec/ruby/core/hash/slice_spec.rb b/spec/ruby/core/hash/slice_spec.rb
index e3046d83d7..4fcc01f9a6 100644
--- a/spec/ruby/core/hash/slice_spec.rb
+++ b/spec/ruby/core/hash/slice_spec.rb
@@ -50,4 +50,25 @@ describe "Hash#slice" do
ScratchPad.recorded.should == []
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.slice(:a).default.should be_nil
+ h[:a] = 1
+ h.slice(:a).default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.slice(:a).default_proc.should be_nil
+ h[:a] = 1
+ h.slice(:a).default_proc.should be_nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.slice(:a)
+ h2.compare_by_identity?.should == true
+ end
end
diff --git a/spec/ruby/core/hash/to_h_spec.rb b/spec/ruby/core/hash/to_h_spec.rb
index e17ca7e671..f84fd7b503 100644
--- a/spec/ruby/core/hash/to_h_spec.rb
+++ b/spec/ruby/core/hash/to_h_spec.rb
@@ -19,17 +19,22 @@ describe "Hash#to_h" do
@h[:foo].should == :bar
end
- it "copies the default" do
+ it "retains the default" do
@h.default = 42
@h.to_h.default.should == 42
@h[:hello].should == 42
end
- it "copies the default_proc" do
+ it "retains the default_proc" do
@h.default_proc = prc = Proc.new{ |h, k| h[k] = 2 * k }
@h.to_h.default_proc.should == prc
@h[42].should == 84
end
+
+ it "retains compare_by_identity flag" do
+ @h.compare_by_identity
+ @h.to_h.compare_by_identity?.should == true
+ end
end
context "with block" do
@@ -78,5 +83,24 @@ describe "Hash#to_h" do
{ a: 1 }.to_h { |k| x }
end.should raise_error(TypeError, /wrong element type MockObject/)
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.default_proc.should be_nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.compare_by_identity?.should == false
+ end
end
end
diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb
index f63d39ecc8..e2eeab1813 100644
--- a/spec/ruby/core/hash/transform_keys_spec.rb
+++ b/spec/ruby/core/hash/transform_keys_spec.rb
@@ -54,6 +54,27 @@ describe "Hash#transform_keys" do
it "allows a combination of hash and block argument" do
@hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 }
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.transform_keys(&:succ).default.should be_nil
+ h[:a] = 1
+ h.transform_keys(&:succ).default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.transform_values(&:succ).default_proc.should be_nil
+ h[:a] = 1
+ h.transform_values(&:succ).default_proc.should be_nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.transform_keys(&:succ)
+ h2.compare_by_identity?.should == false
+ end
end
describe "Hash#transform_keys!" do
diff --git a/spec/ruby/core/hash/transform_values_spec.rb b/spec/ruby/core/hash/transform_values_spec.rb
index acb469416a..4a0ae8a5a5 100644
--- a/spec/ruby/core/hash/transform_values_spec.rb
+++ b/spec/ruby/core/hash/transform_values_spec.rb
@@ -39,6 +39,27 @@ describe "Hash#transform_values" do
r[:foo].should == 84
r.class.should == Hash
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.transform_values(&:succ).default.should be_nil
+ h[:a] = 1
+ h.transform_values(&:succ).default.should be_nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.transform_values(&:succ).default_proc.should be_nil
+ h[:a] = 1
+ h.transform_values(&:succ).default_proc.should be_nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.transform_values(&:succ)
+ h2.compare_by_identity?.should == true
+ end
end
describe "Hash#transform_values!" do
diff --git a/spec/ruby/core/integer/ceildiv_spec.rb b/spec/ruby/core/integer/ceildiv_spec.rb
index 18d07c66d0..c6e22a457d 100644
--- a/spec/ruby/core/integer/ceildiv_spec.rb
+++ b/spec/ruby/core/integer/ceildiv_spec.rb
@@ -1,22 +1,20 @@
require_relative '../../spec_helper'
describe "Integer#ceildiv" do
- ruby_version_is '3.2' do
- it "returns a quotient of division which is rounded up to the nearest integer" do
- 0.ceildiv(3).should eql(0)
- 1.ceildiv(3).should eql(1)
- 3.ceildiv(3).should eql(1)
- 4.ceildiv(3).should eql(2)
+ it "returns a quotient of division which is rounded up to the nearest integer" do
+ 0.ceildiv(3).should eql(0)
+ 1.ceildiv(3).should eql(1)
+ 3.ceildiv(3).should eql(1)
+ 4.ceildiv(3).should eql(2)
- 4.ceildiv(-3).should eql(-1)
- -4.ceildiv(3).should eql(-1)
- -4.ceildiv(-3).should eql(2)
+ 4.ceildiv(-3).should eql(-1)
+ -4.ceildiv(3).should eql(-1)
+ -4.ceildiv(-3).should eql(2)
- 3.ceildiv(1.2).should eql(3)
- 3.ceildiv(6/5r).should eql(3)
+ 3.ceildiv(1.2).should eql(3)
+ 3.ceildiv(6/5r).should eql(3)
- (10**100-11).ceildiv(10**99-1).should eql(10)
- (10**100-9).ceildiv(10**99-1).should eql(11)
- end
+ (10**100-11).ceildiv(10**99-1).should eql(10)
+ (10**100-9).ceildiv(10**99-1).should eql(11)
end
end
diff --git a/spec/ruby/core/integer/constants_spec.rb b/spec/ruby/core/integer/constants_spec.rb
index 2077ad451e..937806c72f 100644
--- a/spec/ruby/core/integer/constants_spec.rb
+++ b/spec/ruby/core/integer/constants_spec.rb
@@ -1,41 +1,13 @@
require_relative '../../spec_helper'
describe "Fixnum" do
- ruby_version_is ""..."3.2" do
- it "is unified into Integer" do
- suppress_warning do
- Fixnum.should equal(Integer)
- end
- end
-
- it "is deprecated" do
- -> { Fixnum }.should complain(/constant ::Fixnum is deprecated/)
- end
- end
-
- ruby_version_is "3.2" do
- it "is no longer defined" do
- Object.should_not.const_defined?(:Fixnum)
- end
+ it "is no longer defined" do
+ Object.should_not.const_defined?(:Fixnum)
end
end
describe "Bignum" do
- ruby_version_is ""..."3.2" do
- it "is unified into Integer" do
- suppress_warning do
- Bignum.should equal(Integer)
- end
- end
-
- it "is deprecated" do
- -> { Bignum }.should complain(/constant ::Bignum is deprecated/)
- end
- end
-
- ruby_version_is "3.2" do
- it "is no longer defined" do
- Object.should_not.const_defined?(:Bignum)
- end
+ it "is no longer defined" do
+ Object.should_not.const_defined?(:Bignum)
end
end
diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb
index 665f4d57be..0d5e16e986 100644
--- a/spec/ruby/core/integer/divide_spec.rb
+++ b/spec/ruby/core/integer/divide_spec.rb
@@ -106,4 +106,21 @@ describe "Integer#/" do
-> { @bignum / :symbol }.should raise_error(TypeError)
end
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 / obj).should == 2
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 / obj).should == 2
+ end
end
diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb
index 0781371d93..86c2b18ae2 100644
--- a/spec/ruby/core/integer/left_shift_spec.rb
+++ b/spec/ruby/core/integer/left_shift_spec.rb
@@ -181,10 +181,8 @@ describe "Integer#<< (with n << m)" do
(bignum_value << -(2**40)).should == 0
end
- ruby_bug "#18517", ""..."3.2" do
- it "returns 0 when m > 0 long and n == 0" do
- (0 << (2**40)).should == 0
- end
+ it "returns 0 when m > 0 long and n == 0" do
+ (0 << (2**40)).should == 0
end
it "returns 0 when m > 0 bignum and n == 0" do
diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb
index aadf416a05..6072ba7c8b 100644
--- a/spec/ruby/core/integer/minus_spec.rb
+++ b/spec/ruby/core/integer/minus_spec.rb
@@ -40,4 +40,21 @@ describe "Integer#-" do
-> { @bignum - :symbol }.should raise_error(TypeError)
end
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(5).and_return([5, 10])
+ (5 - obj).should == -5
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 10]
+ end
+ end
+
+ (5 - obj).should == -5
+ end
end
diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb
index d01a76ab58..38428e56c5 100644
--- a/spec/ruby/core/integer/plus_spec.rb
+++ b/spec/ruby/core/integer/plus_spec.rb
@@ -55,4 +55,21 @@ describe "Integer#+" do
RUBY
ruby_exe(code).should == "-1"
end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 + obj).should == 9
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 + obj).should == 9
+ end
end
diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb
index e91613d8d1..c902674e2f 100644
--- a/spec/ruby/core/integer/right_shift_spec.rb
+++ b/spec/ruby/core/integer/right_shift_spec.rb
@@ -203,10 +203,8 @@ describe "Integer#>> (with n >> m)" do
(bignum_value >> (2**40)).should == 0
end
- ruby_bug "#18517", ""..."3.2" do
- it "returns 0 when m < 0 long and n == 0" do
- (0 >> -(2**40)).should == 0
- end
+ it "returns 0 when m < 0 long and n == 0" do
+ (0 >> -(2**40)).should == 0
end
it "returns 0 when m < 0 bignum and n == 0" do
diff --git a/spec/ruby/core/integer/shared/modulo.rb b/spec/ruby/core/integer/shared/modulo.rb
index f678a10806..d91af1e924 100644
--- a/spec/ruby/core/integer/shared/modulo.rb
+++ b/spec/ruby/core/integer/shared/modulo.rb
@@ -1,6 +1,12 @@
describe :integer_modulo, shared: true do
context "fixnum" do
it "returns the modulus obtained from dividing self by the given argument" do
+ # test all possible combinations:
+ # - integer/double/bignum argument
+ # - positive/negative argument
+ # - positive/negative self
+ # - self greater/smaller than argument
+
13.send(@method, 4).should == 1
4.send(@method, 13).should == 4
@@ -16,8 +22,22 @@ describe :integer_modulo, shared: true do
(200).send(@method, -256).should == -56
(1000).send(@method, -512).should == -24
+ 13.send(@method, -4.0).should == -3.0
+ 4.send(@method, -13.0).should == -9.0
+
+ -13.send(@method, -4.0).should == -1.0
+ -4.send(@method, -13.0).should == -4.0
+
+ -13.send(@method, 4.0).should == 3.0
+ -4.send(@method, 13.0).should == 9.0
+
1.send(@method, 2.0).should == 1.0
200.send(@method, bignum_value).should == 200
+
+ 4.send(@method, bignum_value(10)).should == 4
+ 4.send(@method, -bignum_value(10)).should == -18446744073709551622
+ -4.send(@method, bignum_value(10)).should == 18446744073709551622
+ -4.send(@method, -bignum_value(10)).should == -4
end
it "raises a ZeroDivisionError when the given argument is 0" do
@@ -44,15 +64,35 @@ describe :integer_modulo, shared: true do
context "bignum" do
before :each do
- @bignum = bignum_value
+ @bignum = bignum_value(10)
end
it "returns the modulus obtained from dividing self by the given argument" do
+ # test all possible combinations:
+ # - integer/double/bignum argument
+ # - positive/negative argument
+ # - positive/negative self
+ # - self greater/smaller than argument
+
@bignum.send(@method, 5).should == 1
@bignum.send(@method, -5).should == -4
- @bignum.send(@method, -100).should == -84
+ (-@bignum).send(@method, 5).should == 4
+ (-@bignum).send(@method, -5).should == -1
+
@bignum.send(@method, 2.22).should be_close(1.5603603603605034, TOLERANCE)
- @bignum.send(@method, bignum_value(10)).should == 18446744073709551616
+ @bignum.send(@method, -2.22).should be_close(-0.6596396396394968, TOLERANCE)
+ (-@bignum).send(@method, 2.22).should be_close(0.6596396396394968, TOLERANCE)
+ (-@bignum).send(@method, -2.22).should be_close(-1.5603603603605034, TOLERANCE)
+
+ @bignum.send(@method, @bignum + 10).should == 18446744073709551626
+ @bignum.send(@method, -(@bignum + 10)).should == -10
+ (-@bignum).send(@method, @bignum + 10).should == 10
+ (-@bignum).send(@method, -(@bignum + 10)).should == -18446744073709551626
+
+ (@bignum + 10).send(@method, @bignum).should == 10
+ (@bignum + 10).send(@method, -@bignum).should == -18446744073709551616
+ (-(@bignum + 10)).send(@method, @bignum).should == 18446744073709551616
+ (-(@bignum + 10)).send(@method, -@bignum).should == -10
end
it "raises a ZeroDivisionError when the given argument is 0" do
diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb
index 418e89213b..9e36b84da9 100644
--- a/spec/ruby/core/io/binread_spec.rb
+++ b/spec/ruby/core/io/binread_spec.rb
@@ -45,7 +45,7 @@ describe "IO.binread" do
-> { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL)
end
- ruby_version_is "3.3" do
+ ruby_version_is "3.3"..."4.0" do
# https://bugs.ruby-lang.org/issues/19630
it "warns about deprecation given a path with a pipe" do
cmd = "|echo ok"
diff --git a/spec/ruby/core/io/buffer/empty_spec.rb b/spec/ruby/core/io/buffer/empty_spec.rb
new file mode 100644
index 0000000000..e1fd4ab6a2
--- /dev/null
+++ b/spec/ruby/core/io/buffer/empty_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/null_and_empty'
+
+describe "IO::Buffer#empty?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it_behaves_like :io_buffer_null_and_empty, :empty?
+
+ it "is true for a 0-length String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("")
+ @buffer.empty?.should be_true
+ end
+
+ ruby_version_is "3.3" do
+ it "is true for a 0-length String-backed buffer created with .string" do
+ IO::Buffer.string(0) do |buffer|
+ buffer.empty?.should be_true
+ end
+ end
+ end
+
+ it "is true for a 0-length slice of a buffer with size > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(3, 0).empty?.should be_true
+ end
+end
diff --git a/spec/ruby/core/io/buffer/external_spec.rb b/spec/ruby/core/io/buffer/external_spec.rb
new file mode 100644
index 0000000000..4377a38357
--- /dev/null
+++ b/spec/ruby/core/io/buffer/external_spec.rb
@@ -0,0 +1,108 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#external?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is false for an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.external?.should be_false
+ end
+
+ it "is false for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.external?.should be_false
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is true for a regular mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.external?.should be_true
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.external?.should be_false
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is true for a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.external?.should be_true
+ end
+
+ it "is true for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.external?.should be_true
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "is true" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.external?.should be_true
+ end
+ end
+ end
+ end
+
+ # Always false for slices
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.external?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.external?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.external?.should be_false
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is false when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.slice.external?.should be_false
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.external?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.external?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/free_spec.rb b/spec/ruby/core/io/buffer/free_spec.rb
new file mode 100644
index 0000000000..f3a4918978
--- /dev/null
+++ b/spec/ruby/core/io/buffer/free_spec.rb
@@ -0,0 +1,104 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#free" do
+ context "with a buffer created with .new" do
+ it "frees internal memory and nullifies the buffer" do
+ buffer = IO::Buffer.new(4)
+ buffer.free
+ buffer.null?.should be_true
+ end
+
+ it "frees mapped memory and nullifies the buffer" do
+ buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ buffer.free
+ buffer.null?.should be_true
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "frees mapped memory and nullifies the buffer" do
+ File.open(__FILE__, "r") do |file|
+ buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ buffer.free
+ buffer.null?.should be_true
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string = +"test"
+ buffer = IO::Buffer.for(string)
+ # Read-only buffer, can't modify the string.
+ buffer.free
+ buffer.null?.should be_true
+ end
+ end
+
+ context "with a block" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string = +"test"
+ IO::Buffer.for(string) do |buffer|
+ buffer.set_string("meat")
+ buffer.free
+ buffer.null?.should be_true
+ end
+ string.should == "meat"
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string =
+ IO::Buffer.string(4) do |buffer|
+ buffer.set_string("meat")
+ buffer.free
+ buffer.null?.should be_true
+ end
+ string.should == "meat"
+ end
+ end
+ end
+
+ it "can be called repeatedly without an error" do
+ buffer = IO::Buffer.new(4)
+ buffer.free
+ buffer.null?.should be_true
+ buffer.free
+ buffer.null?.should be_true
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ buffer = IO::Buffer.new(4)
+ buffer.locked do
+ -> { buffer.free }.should raise_error(IO::Buffer::LockedError, "Buffer is locked!")
+ end
+ buffer.free
+ buffer.null?.should be_true
+ end
+
+ context "with a slice of a buffer" do
+ it "nullifies the slice, not touching the buffer" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+
+ slice.free
+ slice.null?.should be_true
+ buffer.null?.should be_false
+
+ buffer.free
+ end
+
+ it "nullifies buffer, invalidating the slice" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+
+ buffer.free
+ slice.null?.should be_false
+ slice.valid?.should be_false
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/initialize_spec.rb b/spec/ruby/core/io/buffer/initialize_spec.rb
new file mode 100644
index 0000000000..c86d1e7f1d
--- /dev/null
+++ b/spec/ruby/core/io/buffer/initialize_spec.rb
@@ -0,0 +1,103 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#initialize" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "creates a new zero-filled buffer with default size" do
+ @buffer = IO::Buffer.new
+ @buffer.size.should == IO::Buffer::DEFAULT_SIZE
+ @buffer.each(:U8).should.all? { |_offset, value| value.eql?(0) }
+ end
+
+ it "creates a buffer with default state" do
+ @buffer = IO::Buffer.new
+ @buffer.should_not.shared?
+ @buffer.should_not.readonly?
+
+ @buffer.should_not.empty?
+ @buffer.should_not.null?
+
+ # This is run-time state, set by #locked.
+ @buffer.should_not.locked?
+ end
+
+ context "with size argument" do
+ it "creates a new internal buffer if size is less than IO::Buffer::PAGE_SIZE" do
+ size = IO::Buffer::PAGE_SIZE - 1
+ @buffer = IO::Buffer.new(size)
+ @buffer.size.should == size
+ @buffer.should.internal?
+ @buffer.should_not.mapped?
+ @buffer.should_not.empty?
+ end
+
+ it "creates a new mapped buffer if size is greater than or equal to IO::Buffer::PAGE_SIZE" do
+ size = IO::Buffer::PAGE_SIZE
+ @buffer = IO::Buffer.new(size)
+ @buffer.size.should == size
+ @buffer.should_not.internal?
+ @buffer.should.mapped?
+ @buffer.should_not.empty?
+ end
+
+ it "creates a null buffer if size is 0" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.size.should.zero?
+ @buffer.should_not.internal?
+ @buffer.should_not.mapped?
+ @buffer.should.null?
+ @buffer.should.empty?
+ end
+
+ it "raises TypeError if size is not an Integer" do
+ -> { IO::Buffer.new(nil) }.should raise_error(TypeError, "not an Integer")
+ -> { IO::Buffer.new(10.0) }.should raise_error(TypeError, "not an Integer")
+ end
+
+ it "raises ArgumentError if size is negative" do
+ -> { IO::Buffer.new(-1) }.should raise_error(ArgumentError, "Size can't be negative!")
+ end
+ end
+
+ context "with size and flags arguments" do
+ it "forces mapped buffer with IO::Buffer::MAPPED flag" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE - 1, IO::Buffer::MAPPED)
+ @buffer.should.mapped?
+ @buffer.should_not.internal?
+ @buffer.should_not.empty?
+ end
+
+ it "forces internal buffer with IO::Buffer::INTERNAL flag" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::INTERNAL)
+ @buffer.should.internal?
+ @buffer.should_not.mapped?
+ @buffer.should_not.empty?
+ end
+
+ it "raises IO::Buffer::AllocationError if neither IO::Buffer::MAPPED nor IO::Buffer::INTERNAL is given" do
+ -> { IO::Buffer.new(10, IO::Buffer::READONLY) }.should raise_error(IO::Buffer::AllocationError, "Could not allocate buffer!")
+ -> { IO::Buffer.new(10, 0) }.should raise_error(IO::Buffer::AllocationError, "Could not allocate buffer!")
+ end
+
+ ruby_version_is "3.3" do
+ it "raises ArgumentError if flags is negative" do
+ -> { IO::Buffer.new(10, -1) }.should raise_error(ArgumentError, "Flags can't be negative!")
+ end
+ end
+
+ ruby_version_is ""..."3.3" do
+ it "raises IO::Buffer::AllocationError with non-Integer flags" do
+ -> { IO::Buffer.new(10, 0.0) }.should raise_error(IO::Buffer::AllocationError, "Could not allocate buffer!")
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "raises TypeError with non-Integer flags" do
+ -> { IO::Buffer.new(10, 0.0) }.should raise_error(TypeError, "not an Integer")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/internal_spec.rb b/spec/ruby/core/io/buffer/internal_spec.rb
new file mode 100644
index 0000000000..409699cc3c
--- /dev/null
+++ b/spec/ruby/core/io/buffer/internal_spec.rb
@@ -0,0 +1,108 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#internal?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is true for an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.internal?.should be_true
+ end
+
+ it "is false for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.internal?.should be_false
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is false for a regular mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.internal?.should be_false
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.internal?.should be_false
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is false for a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.internal?.should be_false
+ end
+
+ it "is false for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.internal?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.internal?.should be_false
+ end
+ end
+ end
+ end
+
+ # Always false for slices
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.internal?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.internal?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.internal?.should be_false
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is false when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.slice.internal?.should be_false
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.internal?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.internal?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/locked_spec.rb b/spec/ruby/core/io/buffer/locked_spec.rb
new file mode 100644
index 0000000000..4ffa569fd2
--- /dev/null
+++ b/spec/ruby/core/io/buffer/locked_spec.rb
@@ -0,0 +1,75 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#locked" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "when buffer is locked" do
+ it "allows reading and writing operations on the buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.set_string("test")
+ @buffer.locked do
+ @buffer.get_string.should == "test"
+ @buffer.set_string("meat")
+ end
+ @buffer.get_string.should == "meat"
+ end
+
+ it "disallows operations changing buffer itself, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ # Just an example, each method is responsible for checking the lock state.
+ -> { @buffer.resize(8) }.should raise_error(IO::Buffer::LockedError)
+ end
+ end
+ end
+
+ it "disallows reentrant locking, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.locked {} }.should raise_error(IO::Buffer::LockedError, "Buffer already locked!")
+ end
+ end
+
+ it "does not propagate to buffer's slices" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ @buffer.locked do
+ @buffer.locked?.should be_true
+ slice.locked?.should be_false
+ slice.locked { slice.locked?.should be_true }
+ end
+ end
+
+ it "does not propagate backwards from buffer's slices" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ slice.locked do
+ slice.locked?.should be_true
+ @buffer.locked?.should be_false
+ @buffer.locked { @buffer.locked?.should be_true }
+ end
+ end
+end
+
+describe "IO::Buffer#locked?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is false by default" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked?.should be_false
+ end
+
+ it "is true only inside of #locked block" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ @buffer.locked?.should be_true
+ end
+ @buffer.locked?.should be_false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/mapped_spec.rb b/spec/ruby/core/io/buffer/mapped_spec.rb
new file mode 100644
index 0000000000..b3610207ff
--- /dev/null
+++ b/spec/ruby/core/io/buffer/mapped_spec.rb
@@ -0,0 +1,108 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#mapped?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is false for an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.mapped?.should be_false
+ end
+
+ it "is true for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.mapped?.should be_true
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is true for a regular mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.mapped?.should be_true
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is true for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.mapped?.should be_true
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is false for a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.mapped?.should be_false
+ end
+
+ it "is false for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.mapped?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.mapped?.should be_false
+ end
+ end
+ end
+ end
+
+ # Always false for slices
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.mapped?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.mapped?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.mapped?.should be_false
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is false when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.slice.mapped?.should be_false
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.mapped?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.mapped?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/null_spec.rb b/spec/ruby/core/io/buffer/null_spec.rb
new file mode 100644
index 0000000000..3fb1144d0e
--- /dev/null
+++ b/spec/ruby/core/io/buffer/null_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/null_and_empty'
+
+describe "IO::Buffer#null?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it_behaves_like :io_buffer_null_and_empty, :null?
+
+ it "is false for a 0-length String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("")
+ @buffer.null?.should be_false
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a 0-length String-backed buffer created with .string" do
+ IO::Buffer.string(0) do |buffer|
+ buffer.null?.should be_false
+ end
+ end
+ end
+
+ it "is false for a 0-length slice of a buffer with size > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(3, 0).null?.should be_false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/private_spec.rb b/spec/ruby/core/io/buffer/private_spec.rb
new file mode 100644
index 0000000000..7aa308997b
--- /dev/null
+++ b/spec/ruby/core/io/buffer/private_spec.rb
@@ -0,0 +1,111 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is "3.3" do
+ describe "IO::Buffer#private?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is false for an internal buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::INTERNAL)
+ @buffer.private?.should be_false
+ end
+
+ it "is false for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.private?.should be_false
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is false for a regular mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.private?.should be_false
+ end
+ end
+
+ it "is true for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.private?.should be_true
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is false for a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.private?.should be_false
+ end
+
+ it "is false for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.private?.should be_false
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.private?.should be_false
+ end
+ end
+ end
+
+ # Always false for slices
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.private?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.private?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false when slicing a regular file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.private?.should be_false
+ end
+ end
+
+ it "is false when slicing a private file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.slice.private?.should be_false
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is false when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.slice.private?.should be_false
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.private?.should be_false
+ end
+ end
+ end
+
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.private?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/readonly_spec.rb b/spec/ruby/core/io/buffer/readonly_spec.rb
new file mode 100644
index 0000000000..0014a876ed
--- /dev/null
+++ b/spec/ruby/core/io/buffer/readonly_spec.rb
@@ -0,0 +1,143 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#readonly?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is false for an internal buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::INTERNAL)
+ @buffer.readonly?.should be_false
+ end
+
+ it "is false for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.readonly?.should be_false
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is false for a writable mapping" do
+ File.open(__FILE__, "r+") do |file|
+ @buffer = IO::Buffer.map(file)
+ @buffer.readonly?.should be_false
+ end
+ end
+
+ it "is true for a readonly mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.readonly?.should be_true
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE)
+ @buffer.readonly?.should be_false
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is true for a buffer created without a block" do
+ @buffer = IO::Buffer.for(+"test")
+ @buffer.readonly?.should be_true
+ end
+
+ it "is false for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.readonly?.should be_false
+ end
+ end
+
+ it "is true for a buffer created with a block from a frozen string" do
+ IO::Buffer.for(-"test") do |buffer|
+ buffer.readonly?.should be_true
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.readonly?.should be_false
+ end
+ end
+ end
+ end
+
+ # This seems to be the only flag propagated from the source buffer to the slice.
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.readonly?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.readonly?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false when slicing a read-write file-backed buffer" do
+ File.open(__FILE__, "r+") do |file|
+ @buffer = IO::Buffer.map(file)
+ @buffer.slice.readonly?.should be_false
+ end
+ end
+
+ it "is true when slicing a readonly file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.readonly?.should be_true
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false when slicing a private file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE)
+ @buffer.slice.readonly?.should be_false
+ end
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is true when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for(+"test")
+ @buffer.slice.readonly?.should be_true
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.readonly?.should be_false
+ end
+ end
+
+ it "is true when slicing a buffer created with a block from a frozen string" do
+ IO::Buffer.for(-"test") do |buffer|
+ buffer.slice.readonly?.should be_true
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.readonly?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/resize_spec.rb b/spec/ruby/core/io/buffer/resize_spec.rb
new file mode 100644
index 0000000000..0da3a23356
--- /dev/null
+++ b/spec/ruby/core/io/buffer/resize_spec.rb
@@ -0,0 +1,155 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#resize" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "resizes internal buffer, preserving type" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(IO::Buffer::PAGE_SIZE)
+ @buffer.size.should == IO::Buffer::PAGE_SIZE
+ @buffer.internal?.should be_true
+ @buffer.mapped?.should be_false
+ end
+
+ platform_is :linux do
+ it "resizes mapped buffer, preserving type" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::MAPPED)
+ @buffer.resize(4)
+ @buffer.size.should == 4
+ @buffer.internal?.should be_false
+ @buffer.mapped?.should be_true
+ end
+ end
+
+ platform_is_not :linux do
+ it "resizes mapped buffer, changing type to internal" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::MAPPED)
+ @buffer.resize(4)
+ @buffer.size.should == 4
+ @buffer.internal?.should be_true
+ @buffer.mapped?.should be_false
+ end
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "disallows resizing shared buffer, raising IO::Buffer::AccessError" do
+ File.open(__FILE__, "r+") do |file|
+ @buffer = IO::Buffer.map(file)
+ -> { @buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "resizes private buffer, discarding excess contents" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE)
+ @buffer.resize(10)
+ @buffer.size.should == 10
+ @buffer.get_string.should == "require_re"
+ @buffer.resize(12)
+ @buffer.size.should == 12
+ @buffer.get_string.should == "require_re\0\0"
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ @buffer = IO::Buffer.for(+"test")
+ -> { @buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+
+ context "with a block" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ IO::Buffer.for(+'test') do |buffer|
+ -> { buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ IO::Buffer.string(4) do |buffer|
+ -> { buffer.resize(10) }.should raise_error(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+ end
+ end
+
+ context "with a null buffer" do
+ it "allows resizing a 0-sized buffer, creating a regular buffer according to new size" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.resize(IO::Buffer::PAGE_SIZE)
+ @buffer.size.should == IO::Buffer::PAGE_SIZE
+ @buffer.internal?.should be_false
+ @buffer.mapped?.should be_true
+ end
+
+ it "allows resizing after a free, creating a regular buffer according to new size" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.free
+ @buffer.resize(10)
+ @buffer.size.should == 10
+ @buffer.internal?.should be_true
+ @buffer.mapped?.should be_false
+ end
+ end
+
+ it "allows resizing to 0, freeing memory" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(0)
+ @buffer.null?.should be_true
+ end
+
+ it "can be called repeatedly" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(10)
+ @buffer.resize(27)
+ @buffer.resize(1)
+ @buffer.size.should == 1
+ end
+
+ it "always clears extra memory" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.set_string("test")
+ # This should not cause a re-allocation, just a technical resizing,
+ # even with very aggressive memory allocation.
+ @buffer.resize(2)
+ @buffer.resize(4)
+ @buffer.get_string.should == "te\0\0"
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.resize(10) }.should raise_error(IO::Buffer::LockedError, "Cannot resize locked buffer!")
+ end
+ end
+
+ it "raises ArgumentError if size is negative" do
+ @buffer = IO::Buffer.new(4)
+ -> { @buffer.resize(-1) }.should raise_error(ArgumentError, "Size can't be negative!")
+ end
+
+ it "raises TypeError if size is not an Integer" do
+ @buffer = IO::Buffer.new(4)
+ -> { @buffer.resize(nil) }.should raise_error(TypeError, "not an Integer")
+ -> { @buffer.resize(10.0) }.should raise_error(TypeError, "not an Integer")
+ end
+
+ context "with a slice of a buffer" do
+ # Current behavior of slice resizing seems unintended (it's undocumented, too).
+ # It either creates a completely new buffer, or breaks the slice on size 0.
+ it "needs to be reviewed for spec completeness"
+ end
+end
diff --git a/spec/ruby/core/io/buffer/shared/null_and_empty.rb b/spec/ruby/core/io/buffer/shared/null_and_empty.rb
new file mode 100644
index 0000000000..c8fe9e5e46
--- /dev/null
+++ b/spec/ruby/core/io/buffer/shared/null_and_empty.rb
@@ -0,0 +1,59 @@
+describe :io_buffer_null_and_empty, shared: true do
+ it "is false for a buffer with size > 0" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.send(@method).should be_false
+ end
+
+ it "is false for a slice with length > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(1, 2).send(@method).should be_false
+ end
+
+ it "is false for a file-mapped buffer" do
+ File.open(__FILE__, "rb") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.send(@method).should be_false
+ end
+ end
+
+ it "is false for a non-empty String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.send(@method).should be_false
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a non-empty String-backed buffer created with .string" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.send(@method).should be_false
+ end
+ end
+ end
+
+ it "is true for a 0-sized buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.send(@method).should be_true
+ end
+
+ it "is true for a slice of a 0-sized buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.slice(0, 0).send(@method).should be_true
+ end
+
+ it "is true for a freed buffer" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.free
+ @buffer.send(@method).should be_true
+ end
+
+ it "is true for a buffer resized to 0" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.resize(0)
+ @buffer.send(@method).should be_true
+ end
+
+ it "is true for a buffer whose memory was transferred" do
+ buffer = IO::Buffer.new(1)
+ @buffer = buffer.transfer
+ buffer.send(@method).should be_true
+ end
+end
diff --git a/spec/ruby/core/io/buffer/shared_spec.rb b/spec/ruby/core/io/buffer/shared_spec.rb
new file mode 100644
index 0000000000..f2a638cf39
--- /dev/null
+++ b/spec/ruby/core/io/buffer/shared_spec.rb
@@ -0,0 +1,117 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#shared?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "is false for an internal buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::INTERNAL)
+ @buffer.shared?.should be_false
+ end
+
+ it "is false for a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.shared?.should be_false
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "is true for a regular mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.shared?.should be_true
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false for a private mapping" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.shared?.should be_false
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ it "is false for a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.shared?.should be_false
+ end
+
+ it "is false for a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.shared?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.shared?.should be_false
+ end
+ end
+ end
+ end
+
+ # Always false for slices
+ context "with a slice of a buffer" do
+ context "created with .new" do
+ it "is false when slicing an internal buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice.shared?.should be_false
+ end
+
+ it "is false when slicing a mapped buffer" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ @buffer.slice.shared?.should be_false
+ end
+ end
+
+ context "created with .map" do
+ it "is false when slicing a regular file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.slice.shared?.should be_false
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "is false when slicing a private file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
+ @buffer.slice.shared?.should be_false
+ end
+ end
+ end
+ end
+
+ context "created with .for" do
+ it "is false when slicing a buffer created without a block" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.slice.shared?.should be_false
+ end
+
+ it "is false when slicing a buffer created with a block" do
+ IO::Buffer.for(+"test") do |buffer|
+ buffer.slice.shared?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "created with .string" do
+ it "is false" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.slice.shared?.should be_false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/transfer_spec.rb b/spec/ruby/core/io/buffer/transfer_spec.rb
new file mode 100644
index 0000000000..cb8c843ff2
--- /dev/null
+++ b/spec/ruby/core/io/buffer/transfer_spec.rb
@@ -0,0 +1,118 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#transfer" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "transfers internal memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.new(4)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+
+ it "transfers mapped memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "transfers mapped memory to a new buffer, nullifying the original" do
+ File.open(__FILE__, "r") do |file|
+ buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "transfers memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.for("test")
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+ end
+
+ context "with a block" do
+ it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do
+ IO::Buffer.for(+"test") do |buffer|
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+ @buffer.null?.should be_false
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ context "with a String-backed buffer created with .string" do
+ it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do
+ IO::Buffer.string(4) do |buffer|
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should be_true
+ end
+ @buffer.null?.should be_false
+ end
+ end
+ end
+
+ it "allows multiple transfers" do
+ buffer_1 = IO::Buffer.new(4)
+ buffer_2 = buffer_1.transfer
+ @buffer = buffer_2.transfer
+ buffer_1.null?.should be_true
+ buffer_2.null?.should be_true
+ @buffer.null?.should be_false
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.transfer }.should raise_error(IO::Buffer::LockedError, "Cannot transfer ownership of locked buffer!")
+ end
+ end
+
+ context "with a slice of a buffer" do
+ it "transfers source to a new slice, not touching the buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ @buffer.set_string("test")
+
+ new_slice = slice.transfer
+ slice.null?.should be_true
+ new_slice.null?.should be_false
+ @buffer.null?.should be_false
+
+ new_slice.set_string("ea")
+ @buffer.get_string.should == "east"
+ end
+
+ it "nullifies buffer, invalidating the slice" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+ @buffer = buffer.transfer
+
+ slice.null?.should be_false
+ slice.valid?.should be_false
+ -> { slice.get_string }.should raise_error(IO::Buffer::InvalidatedError, "Buffer has been invalidated!")
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/valid_spec.rb b/spec/ruby/core/io/buffer/valid_spec.rb
new file mode 100644
index 0000000000..680a35ae9a
--- /dev/null
+++ b/spec/ruby/core/io/buffer/valid_spec.rb
@@ -0,0 +1,110 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#valid?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ # Non-slices are always valid
+ context "with a non-slice buffer" do
+ it "is true for a regular buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.valid?.should be_true
+ end
+
+ it "is true for a 0-size buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.valid?.should be_true
+ end
+
+ it "is true for a freed buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.free
+ @buffer.valid?.should be_true
+ end
+
+ it "is true for a freed file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.valid?.should be_true
+ @buffer.free
+ @buffer.valid?.should be_true
+ end
+ end
+
+ it "is true for a freed string-backed buffer" do
+ @buffer = IO::Buffer.for("hello")
+ @buffer.valid?.should be_true
+ @buffer.free
+ @buffer.valid?.should be_true
+ end
+ end
+
+ # "A buffer becomes invalid if it is a slice of another buffer (or string)
+ # which has been freed or re-allocated at a different address."
+ context "with a slice" do
+ it "is true for a slice of a live buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should be_true
+ end
+
+ context "when buffer is resized" do
+ it "is false when slice becomes outside the buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(2, 2)
+ @buffer.resize(3)
+ slice.valid?.should be_false
+ end
+
+ platform_is_not :linux do
+ # This test does not cause a copy-resize on Linux.
+ # `#resize` MAY cause the buffer to move, but there is no guarantee.
+ it "is false when buffer is copied on resize" do
+ @buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ slice = @buffer.slice(0, 2)
+ @buffer.resize(8)
+ slice.valid?.should be_false
+ end
+ end
+ end
+
+ it "is false for a slice of a transferred buffer" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+ @buffer = buffer.transfer
+ slice.valid?.should be_false
+ end
+
+ it "is false for a slice of a freed buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ @buffer.free
+ slice.valid?.should be_false
+ end
+
+ it "is false for a slice of a freed file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should be_true
+ @buffer.free
+ slice.valid?.should be_false
+ end
+ end
+
+ it "is true for a slice of a freed string-backed buffer while string is alive" do
+ @buffer = IO::Buffer.for("alive")
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should be_true
+ @buffer.free
+ slice.valid?.should be_true
+ end
+
+ # There probably should be a test with a garbage-collected string,
+ # but it's not clear how to force that.
+
+ it "needs to be reviewed for spec completeness"
+ end
+end
diff --git a/spec/ruby/core/io/foreach_spec.rb b/spec/ruby/core/io/foreach_spec.rb
index c361d27879..6abe8901ba 100644
--- a/spec/ruby/core/io/foreach_spec.rb
+++ b/spec/ruby/core/io/foreach_spec.rb
@@ -14,33 +14,35 @@ describe "IO.foreach" do
IO.foreach(@name) { $..should == @count += 1 }
end
- describe "when the filename starts with |" do
- it "gets data from the standard out of the subprocess" do
- cmd = "|sh -c 'echo hello;echo line2'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello&echo line2"
- end
+ ruby_version_is ""..."4.0" do
+ describe "when the filename starts with |" do
+ it "gets data from the standard out of the subprocess" do
+ cmd = "|sh -c 'echo hello;echo line2'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello&echo line2"
+ end
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.foreach(cmd) { |l| ScratchPad << l }
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.foreach(cmd) { |l| ScratchPad << l }
+ end
+ ScratchPad.recorded.should == ["hello\n", "line2\n"]
end
- ScratchPad.recorded.should == ["hello\n", "line2\n"]
- end
- platform_is_not :windows do
- it "gets data from a fork when passed -" do
- parent_pid = $$
+ platform_is_not :windows do
+ it "gets data from a fork when passed -" do
+ parent_pid = $$
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.foreach("|-") { |l| ScratchPad << l }
- end
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.foreach("|-") { |l| ScratchPad << l }
+ end
- if $$ == parent_pid
- ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
- else # child
- puts "hello"
- puts "from a fork"
- exit!
+ if $$ == parent_pid
+ ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
+ else # child
+ puts "hello"
+ puts "from a fork"
+ exit!
+ end
end
end
end
diff --git a/spec/ruby/core/io/path_spec.rb b/spec/ruby/core/io/path_spec.rb
index 8145c32f39..798adb2163 100644
--- a/spec/ruby/core/io/path_spec.rb
+++ b/spec/ruby/core/io/path_spec.rb
@@ -1,14 +1,12 @@
require_relative '../../spec_helper'
describe "IO#path" do
- ruby_version_is "3.2" do
- it "returns the path of the file associated with the IO object" do
- path = tmp("io_path.txt")
- File.open(path, "w") do |file|
- IO.new(file.fileno, path: file.path, autoclose: false).path.should == file.path
- end
- ensure
- File.unlink(path)
+ it "returns the path of the file associated with the IO object" do
+ path = tmp("io_path.txt")
+ File.open(path, "w") do |file|
+ IO.new(file.fileno, path: file.path, autoclose: false).path.should == file.path
end
+ ensure
+ File.unlink(path)
end
end
diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb
index e9d32c5c7d..6043862614 100644
--- a/spec/ruby/core/io/popen_spec.rb
+++ b/spec/ruby/core/io/popen_spec.rb
@@ -95,6 +95,22 @@ describe "IO.popen" do
@io = IO.popen(ruby_cmd('exit 0'), mode)
end
+ it "accepts a path using the chdir: keyword argument" do
+ path = File.dirname(@fname)
+
+ @io = IO.popen(ruby_cmd("puts Dir.pwd"), "r", chdir: path)
+ @io.read.chomp.should == path
+ end
+
+ it "accepts a path using the chdir: keyword argument and a coercible path" do
+ path = File.dirname(@fname)
+ object = mock("path")
+ object.should_receive(:to_path).and_return(path)
+
+ @io = IO.popen(ruby_cmd("puts Dir.pwd"), "r", chdir: object)
+ @io.read.chomp.should == path
+ end
+
describe "with a block" do
it "yields an open IO to the block" do
IO.popen(ruby_cmd('exit'), "r") do |io|
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb
index 567daa55df..988ec2ce30 100644
--- a/spec/ruby/core/io/read_spec.rb
+++ b/spec/ruby/core/io/read_spec.rb
@@ -168,76 +168,78 @@ describe "IO.read" do
end
end
-describe "IO.read from a pipe" do
- it "runs the rest as a subprocess and returns the standard output" do
- cmd = "|sh -c 'echo hello'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello"
- end
-
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.read(cmd).should == "hello\n"
- end
- end
-
- platform_is_not :windows do
- it "opens a pipe to a fork if the rest is -" do
- str = nil
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- str = IO.read("|-")
+ruby_version_is ""..."4.0" do
+ describe "IO.read from a pipe" do
+ it "runs the rest as a subprocess and returns the standard output" do
+ cmd = "|sh -c 'echo hello'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello"
end
- if str # parent
- str.should == "hello from child\n"
- else #child
- puts "hello from child"
- exit!
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read(cmd).should == "hello\n"
end
end
- end
- it "reads only the specified number of bytes requested" do
- cmd = "|sh -c 'echo hello'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello"
- end
+ platform_is_not :windows do
+ it "opens a pipe to a fork if the rest is -" do
+ str = nil
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ str = IO.read("|-")
+ end
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.read(cmd, 1).should == "h"
+ if str # parent
+ str.should == "hello from child\n"
+ else #child
+ puts "hello from child"
+ exit!
+ end
+ end
end
- end
- platform_is_not :windows do
- it "raises Errno::ESPIPE if passed an offset" do
- -> {
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.read("|sh -c 'echo hello'", 1, 1)
- end
- }.should raise_error(Errno::ESPIPE)
+ it "reads only the specified number of bytes requested" do
+ cmd = "|sh -c 'echo hello'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello"
+ end
+
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read(cmd, 1).should == "h"
+ end
end
- end
- quarantine! do # The process tried to write to a nonexistent pipe.
- platform_is :windows do
- # TODO: It should raise Errno::ESPIPE on Windows as well
- # once https://bugs.ruby-lang.org/issues/12230 is fixed.
- it "raises Errno::EINVAL if passed an offset" do
+ platform_is_not :windows do
+ it "raises Errno::ESPIPE if passed an offset" do
-> {
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- IO.read("|cmd.exe /C echo hello", 1, 1)
+ IO.read("|sh -c 'echo hello'", 1, 1)
end
- }.should raise_error(Errno::EINVAL)
+ }.should raise_error(Errno::ESPIPE)
end
end
- end
- ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19630
- it "warns about deprecation given a path with a pipe" do
- cmd = "|echo ok"
- -> {
- IO.read(cmd)
- }.should complain(/IO process creation with a leading '\|'/)
+ quarantine! do # The process tried to write to a nonexistent pipe.
+ platform_is :windows do
+ # TODO: It should raise Errno::ESPIPE on Windows as well
+ # once https://bugs.ruby-lang.org/issues/12230 is fixed.
+ it "raises Errno::EINVAL if passed an offset" do
+ -> {
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read("|cmd.exe /C echo hello", 1, 1)
+ end
+ }.should raise_error(Errno::EINVAL)
+ end
+ end
+ end
+
+ ruby_version_is "3.3" do
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation" do
+ cmd = "|echo ok"
+ -> {
+ IO.read(cmd)
+ }.should complain(/IO process creation with a leading '\|'/)
+ end
end
end
end
diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb
index 3a6ff3d0f3..b4770775d1 100644
--- a/spec/ruby/core/io/readlines_spec.rb
+++ b/spec/ruby/core/io/readlines_spec.rb
@@ -174,45 +174,47 @@ describe "IO.readlines" do
$_.should == "test"
end
- describe "when passed a string that starts with a |" do
- it "gets data from the standard out of the subprocess" do
- cmd = "|sh -c 'echo hello;echo line2'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello&echo line2"
- end
-
- lines = nil
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- lines = IO.readlines(cmd)
- end
- lines.should == ["hello\n", "line2\n"]
- end
+ ruby_version_is ""..."4.0" do
+ describe "when passed a string that starts with a |" do
+ it "gets data from the standard out of the subprocess" do
+ cmd = "|sh -c 'echo hello;echo line2'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello&echo line2"
+ end
- platform_is_not :windows do
- it "gets data from a fork when passed -" do
lines = nil
suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- lines = IO.readlines("|-")
+ lines = IO.readlines(cmd)
end
+ lines.should == ["hello\n", "line2\n"]
+ end
- if lines # parent
- lines.should == ["hello\n", "from a fork\n"]
- else
- puts "hello"
- puts "from a fork"
- exit!
+ platform_is_not :windows do
+ it "gets data from a fork when passed -" do
+ lines = nil
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ lines = IO.readlines("|-")
+ end
+
+ if lines # parent
+ lines.should == ["hello\n", "from a fork\n"]
+ else
+ puts "hello"
+ puts "from a fork"
+ exit!
+ end
end
end
end
- end
- ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19630
- it "warns about deprecation given a path with a pipe" do
- cmd = "|echo ok"
- -> {
- IO.readlines(cmd)
- }.should complain(/IO process creation with a leading '\|'/)
+ ruby_version_is "3.3" do
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ IO.readlines(cmd)
+ }.should complain(/IO process creation with a leading '\|'/)
+ end
end
end
diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb
index 547da0677d..176c33cf9e 100644
--- a/spec/ruby/core/io/readpartial_spec.rb
+++ b/spec/ruby/core/io/readpartial_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
@@ -93,6 +93,11 @@ describe "IO#readpartial" do
@rd.readpartial(0).should == ""
end
+ it "raises IOError if the stream is closed and the length argument is 0" do
+ @rd.close
+ -> { @rd.readpartial(0) }.should raise_error(IOError, "closed stream")
+ end
+
it "clears and returns the given buffer if the length argument is 0" do
buffer = +"existing content"
@rd.readpartial(0, buffer).should == buffer
diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb
index aca622834f..0747f31b8a 100644
--- a/spec/ruby/core/io/shared/each.rb
+++ b/spec/ruby/core/io/shared/each.rb
@@ -202,20 +202,10 @@ describe :io_each, shared: true do
end
describe "when passed chomp and nil as a separator" do
- ruby_version_is "3.2" do
- it "yields self's content" do
- @io.pos = 100
- @io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
- ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
- end
- end
-
- ruby_version_is ""..."3.2" do
- it "yields self's content without trailing new line character" do
- @io.pos = 100
- @io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
- ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six."]
- end
+ it "yields self's content" do
+ @io.pos = 100
+ @io.send(@method, nil, chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
end
end
diff --git a/spec/ruby/core/io/shared/gets_ascii.rb b/spec/ruby/core/io/shared/gets_ascii.rb
index 2a8fe3c9a5..2bd5470d99 100644
--- a/spec/ruby/core/io/shared/gets_ascii.rb
+++ b/spec/ruby/core/io/shared/gets_ascii.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :io_gets_ascii, shared: true do
describe "with ASCII separator" do
before :each do
diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb
index cba5f33ebf..e84133493c 100644
--- a/spec/ruby/core/io/shared/new.rb
+++ b/spec/ruby/core/io/shared/new.rb
@@ -208,6 +208,26 @@ describe :io_new, shared: true do
@io.internal_encoding.to_s.should == 'IBM866'
end
+ it "does not use binary encoding when mode encoding is specified along with binmode: true option" do
+ @io = IO.send(@method, @fd, 'w:iso-8859-1', binmode: true)
+ @io.external_encoding.to_s.should == 'ISO-8859-1'
+ end
+
+ it "does not use textmode argument when mode encoding is specified" do
+ @io = IO.send(@method, @fd, 'w:ascii-8bit', textmode: true)
+ @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ end
+
+ it "does not use binmode argument when external encoding is specified via the :external_encoding option" do
+ @io = IO.send(@method, @fd, 'w', binmode: true, external_encoding: 'iso-8859-1')
+ @io.external_encoding.to_s.should == 'ISO-8859-1'
+ end
+
+ it "does not use textmode argument when external encoding is specified via the :external_encoding option" do
+ @io = IO.send(@method, @fd, 'w', textmode: true, external_encoding: 'ascii-8bit')
+ @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ end
+
it "raises ArgumentError for nil options" do
-> {
IO.send(@method, @fd, 'w', nil)
@@ -325,6 +345,9 @@ describe :io_new_errors, shared: true do
@io = IO.send(@method, @fd, 'w:ISO-8859-1', external_encoding: 'ISO-8859-1')
}.should raise_error(ArgumentError)
-> {
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', internal_encoding: 'ISO-8859-1')
+ }.should raise_error(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1')
}.should raise_error(ArgumentError)
end
diff --git a/spec/ruby/core/io/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb
index 8851214283..d56a27b3af 100644
--- a/spec/ruby/core/io/sysread_spec.rb
+++ b/spec/ruby/core/io/sysread_spec.rb
@@ -131,9 +131,7 @@ describe "IO#sysread" do
@read.sysread(3).should == "ab"
end
- guard_not -> { platform_is :windows and ruby_version_is ""..."3.2" } do # https://bugs.ruby-lang.org/issues/18880
- it "raises ArgumentError when length is less than 0" do
- -> { @read.sysread(-1) }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError when length is less than 0" do
+ -> { @read.sysread(-1) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb
index 4a26f8dbaf..e58100f846 100644
--- a/spec/ruby/core/io/write_spec.rb
+++ b/spec/ruby/core/io/write_spec.rb
@@ -220,7 +220,7 @@ describe "IO.write" do
end
end
- ruby_version_is "3.3" do
+ ruby_version_is "3.3"..."4.0" do
# https://bugs.ruby-lang.org/issues/19630
it "warns about deprecation given a path with a pipe" do
-> {
diff --git a/spec/ruby/core/kernel/Float_spec.rb b/spec/ruby/core/kernel/Float_spec.rb
index 6cedfe0617..9c436b05f7 100644
--- a/spec/ruby/core/kernel/Float_spec.rb
+++ b/spec/ruby/core/kernel/Float_spec.rb
@@ -163,6 +163,7 @@ describe :kernel_float, shared: true do
-> { @object.send(:Float, "+1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "-1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "1.e+0") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "1.e-2") }.should raise_error(ArgumentError)
end
end
@@ -172,6 +173,7 @@ describe :kernel_float, shared: true do
@object.send(:Float, "+1.").should == 1.0
@object.send(:Float, "-1.").should == -1.0
@object.send(:Float, "1.e+0").should == 1.0
+ @object.send(:Float, "1.e-2").should be_close(0.01, TOLERANCE)
end
end
@@ -222,59 +224,107 @@ describe :kernel_float, shared: true do
end
end
- describe "for hexadecimal literals with binary exponent" do
- %w(p P).each do |p|
- it "interprets the fractional part (on the left side of '#{p}') in hexadecimal" do
- @object.send(:Float, "0x10#{p}0").should == 16.0
- end
-
- it "interprets the exponent (on the right of '#{p}') in decimal" do
- @object.send(:Float, "0x1#{p}10").should == 1024.0
- end
-
- it "raises an ArgumentError if #{p} is the trailing character" do
- -> { @object.send(:Float, "0x1#{p}") }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError if #{p} is the leading character" do
- -> { @object.send(:Float, "0x#{p}1") }.should raise_error(ArgumentError)
- end
+ context "for hexadecimal literals" do
+ it "interprets the 0x prefix as hexadecimal" do
+ @object.send(:Float, "0x10").should == 16.0
+ @object.send(:Float, "0x0F").should == 15.0
+ @object.send(:Float, "0x0f").should == 15.0
+ end
- it "returns Infinity for '0x1#{p}10000'" do
- @object.send(:Float, "0x1#{p}10000").should == Float::INFINITY
- end
+ it "interprets negative hex value" do
+ @object.send(:Float, "-0x10").should == -16.0
+ end
- it "returns 0 for '0x1#{p}-10000'" do
- @object.send(:Float, "0x1#{p}-10000").should == 0
- end
+ it "accepts embedded _ if the number does not contain a-f" do
+ @object.send(:Float, "0x1_0").should == 16.0
+ end
- it "allows embedded _ in a number on either side of the #{p}" do
- @object.send(:Float, "0x1_0#{p}10").should == 16384.0
- @object.send(:Float, "0x10#{p}1_0").should == 16384.0
- @object.send(:Float, "0x1_0#{p}1_0").should == 16384.0
+ ruby_version_is ""..."3.4.3" do
+ it "does not accept embedded _ if the number contains a-f" do
+ -> { @object.send(:Float, "0x1_0a") }.should raise_error(ArgumentError)
+ @object.send(:Float, "0x1_0a", exception: false).should be_nil
end
+ end
- it "raises an exception if a space is embedded on either side of the '#{p}'" do
- -> { @object.send(:Float, "0x1 0#{p}10") }.should raise_error(ArgumentError)
- -> { @object.send(:Float, "0x10#{p}1 0") }.should raise_error(ArgumentError)
+ ruby_version_is "3.4.3" do
+ it "accepts embedded _ if the number contains a-f" do
+ @object.send(:Float, "0x1_0a").should == 0x10a.to_f
end
+ end
- it "raises an exception if there's a leading _ on either side of the '#{p}'" do
- -> { @object.send(:Float, "0x_10#{p}10") }.should raise_error(ArgumentError)
- -> { @object.send(:Float, "0x10#{p}_10") }.should raise_error(ArgumentError)
- end
+ it "does not accept _ before, after or inside the 0x prefix" do
+ -> { @object.send(:Float, "_0x10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "0_x10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "0x_10") }.should raise_error(ArgumentError)
+ @object.send(:Float, "_0x10", exception: false).should be_nil
+ @object.send(:Float, "0_x10", exception: false).should be_nil
+ @object.send(:Float, "0x_10", exception: false).should be_nil
+ end
- it "raises an exception if there's a trailing _ on either side of the '#{p}'" do
- -> { @object.send(:Float, "0x10_#{p}10") }.should raise_error(ArgumentError)
- -> { @object.send(:Float, "0x10#{p}10_") }.should raise_error(ArgumentError)
- end
+ it "parses negative hexadecimal string as negative float" do
+ @object.send(:Float, "-0x7b").should == -123.0
+ end
- it "allows hexadecimal points on the left side of the '#{p}'" do
- @object.send(:Float, "0x1.8#{p}0").should == 1.5
+ ruby_version_is "3.4" do
+ it "accepts a fractional part" do
+ @object.send(:Float, "0x0.8").should == 0.5
end
+ end
- it "raises an ArgumentError if there's a decimal point on the right side of the '#{p}'" do
- -> { @object.send(:Float, "0x1#{p}1.0") }.should raise_error(ArgumentError)
+ describe "with binary exponent" do
+ %w(p P).each do |p|
+ it "interprets the fractional part (on the left side of '#{p}') in hexadecimal" do
+ @object.send(:Float, "0x10#{p}0").should == 16.0
+ end
+
+ it "interprets the exponent (on the right of '#{p}') in decimal" do
+ @object.send(:Float, "0x1#{p}10").should == 1024.0
+ end
+
+ it "raises an ArgumentError if #{p} is the trailing character" do
+ -> { @object.send(:Float, "0x1#{p}") }.should raise_error(ArgumentError)
+ end
+
+ it "raises an ArgumentError if #{p} is the leading character" do
+ -> { @object.send(:Float, "0x#{p}1") }.should raise_error(ArgumentError)
+ end
+
+ it "returns Infinity for '0x1#{p}10000'" do
+ @object.send(:Float, "0x1#{p}10000").should == Float::INFINITY
+ end
+
+ it "returns 0 for '0x1#{p}-10000'" do
+ @object.send(:Float, "0x1#{p}-10000").should == 0
+ end
+
+ it "allows embedded _ in a number on either side of the #{p}" do
+ @object.send(:Float, "0x1_0#{p}10").should == 16384.0
+ @object.send(:Float, "0x10#{p}1_0").should == 16384.0
+ @object.send(:Float, "0x1_0#{p}1_0").should == 16384.0
+ end
+
+ it "raises an exception if a space is embedded on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x1 0#{p}10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}1 0") }.should raise_error(ArgumentError)
+ end
+
+ it "raises an exception if there's a leading _ on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x_10#{p}10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}_10") }.should raise_error(ArgumentError)
+ end
+
+ it "raises an exception if there's a trailing _ on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x10_#{p}10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}10_") }.should raise_error(ArgumentError)
+ end
+
+ it "allows hexadecimal points on the left side of the '#{p}'" do
+ @object.send(:Float, "0x1.8#{p}0").should == 1.5
+ end
+
+ it "raises an ArgumentError if there's a decimal point on the right side of the '#{p}'" do
+ -> { @object.send(:Float, "0x1#{p}1.0") }.should raise_error(ArgumentError)
+ end
end
end
end
diff --git a/spec/ruby/core/kernel/Rational_spec.rb b/spec/ruby/core/kernel/Rational_spec.rb
index 841c8e8c64..cc11a35451 100644
--- a/spec/ruby/core/kernel/Rational_spec.rb
+++ b/spec/ruby/core/kernel/Rational_spec.rb
@@ -76,12 +76,62 @@ describe "Kernel.Rational" do
end
describe "when passed a Complex" do
- it "returns a Rational from the real part if the imaginary part is 0" do
- Rational(Complex(1, 0)).should == Rational(1)
+ context "[Complex]" do
+ it "returns a Rational from the real part if the imaginary part is 0" do
+ Rational(Complex(1, 0)).should == Rational(1)
+ end
+
+ it "raises a RangeError if the imaginary part is not 0" do
+ -> { Rational(Complex(1, 2)) }.should raise_error(RangeError, "can't convert 1+2i into Rational")
+ end
end
- it "raises a RangeError if the imaginary part is not 0" do
- -> { Rational(Complex(1, 2)) }.should raise_error(RangeError)
+ context "[Numeric, Complex]" do
+ it "uses the real part if the imaginary part is 0" do
+ Rational(1, Complex(2, 0)).should == Rational(1, 2)
+ end
+
+ it "divides a numerator by the Complex denominator if the imaginary part is not 0" do
+ Rational(1, Complex(2, 1)).should == Complex(2/5r, -1/5r)
+ end
+ end
+ end
+
+ context "when passed neither a Numeric nor a String" do
+ it "converts to Rational with #to_r method" do
+ obj = Object.new
+ def obj.to_r; 1/2r; end
+
+ Rational(obj).should == 1/2r
+ end
+
+ it "tries to convert to Integer with #to_int method if it does not respond to #to_r" do
+ obj = Object.new
+ def obj.to_int; 1; end
+
+ Rational(obj).should == 1r
+ end
+
+ it "raises TypeError if it neither responds to #to_r nor #to_int method" do
+ -> { Rational([]) }.should raise_error(TypeError, "can't convert Array into Rational")
+ -> { Rational({}) }.should raise_error(TypeError, "can't convert Hash into Rational")
+ -> { Rational(nil) }.should raise_error(TypeError, "can't convert nil into Rational")
+ end
+
+ it "swallows exception raised in #to_int method" do
+ object = Object.new
+ def object.to_int() raise NoMethodError; end
+
+ -> { Rational(object) }.should raise_error(TypeError)
+ -> { Rational(object, 1) }.should raise_error(TypeError)
+ -> { Rational(1, object) }.should raise_error(TypeError)
+ end
+
+ it "raises TypeError if #to_r does not return Rational" do
+ obj = Object.new
+ def obj.to_r; []; end
+
+ -> { Rational(obj) }.should raise_error(TypeError, "can't convert Object to Rational (Object#to_r gives Array)")
end
end
@@ -91,11 +141,11 @@ describe "Kernel.Rational" do
end
it "raises a TypeError if the first argument is nil" do
- -> { Rational(nil) }.should raise_error(TypeError)
+ -> { Rational(nil) }.should raise_error(TypeError, "can't convert nil into Rational")
end
it "raises a TypeError if the second argument is nil" do
- -> { Rational(1, nil) }.should raise_error(TypeError)
+ -> { Rational(1, nil) }.should raise_error(TypeError, "can't convert nil into Rational")
end
it "raises a TypeError if the first argument is a Symbol" do
@@ -112,6 +162,18 @@ describe "Kernel.Rational" do
Rational(:sym, exception: false).should == nil
Rational("abc", exception: false).should == nil
end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, exception: false).should == nil
+ end
end
describe "and [non-Numeric, Numeric]" do
@@ -119,6 +181,18 @@ describe "Kernel.Rational" do
Rational(:sym, 1, exception: false).should == nil
Rational("abc", 1, exception: false).should == nil
end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, 1, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, 1, exception: false).should == nil
+ end
end
describe "and [anything, non-Numeric]" do
@@ -126,6 +200,18 @@ describe "Kernel.Rational" do
Rational(:sym, :sym, exception: false).should == nil
Rational("abc", :sym, exception: false).should == nil
end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, obj, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, obj, exception: false).should == nil
+ end
end
describe "and non-Numeric String arguments" do
diff --git a/spec/ruby/core/kernel/autoload_spec.rb b/spec/ruby/core/kernel/autoload_spec.rb
index 0404caec6d..5edb70541d 100644
--- a/spec/ruby/core/kernel/autoload_spec.rb
+++ b/spec/ruby/core/kernel/autoload_spec.rb
@@ -7,7 +7,9 @@ require_relative 'fixtures/classes'
autoload :KSAutoloadA, "autoload_a.rb"
autoload :KSAutoloadB, fixture(__FILE__, "autoload_b.rb")
-autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb"
+define_autoload_KSAutoloadCallsRequire = -> {
+ autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb"
+}
def check_autoload(const)
autoload? const
@@ -43,6 +45,7 @@ describe "Kernel#autoload" do
end
it "calls main.require(path) to load the file" do
+ define_autoload_KSAutoloadCallsRequire.call
main = TOPLEVEL_BINDING.eval("self")
main.should_receive(:require).with("main_autoload_not_exist.rb")
# The constant won't be defined since require is mocked to do nothing
diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb
index aaacd9a910..a917dba504 100644
--- a/spec/ruby/core/kernel/caller_locations_spec.rb
+++ b/spec/ruby/core/kernel/caller_locations_spec.rb
@@ -83,7 +83,7 @@ describe 'Kernel#caller_locations' do
end
end
- ruby_version_is "3.4" do
+ ruby_version_is "3.4"..."4.0" do
it "includes core library methods defined in Ruby" do
file, line = Kernel.instance_method(:tap).source_location
file.should.start_with?('<internal:')
@@ -94,5 +94,17 @@ describe 'Kernel#caller_locations' do
loc.path.should.start_with? "<internal:"
end
end
+
+ ruby_version_is "4.0" do
+ it "does not include core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller_locations(1, 1)[0] }
+ loc.label.should == "Kernel#tap"
+ loc.path.should == __FILE__
+ end
+ end
end
end
diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb
index 33c7929a31..7cd703de5a 100644
--- a/spec/ruby/core/kernel/caller_spec.rb
+++ b/spec/ruby/core/kernel/caller_spec.rb
@@ -84,13 +84,26 @@ describe 'Kernel#caller' do
end
guard -> { Kernel.instance_method(:tap).source_location } do
- it "includes core library methods defined in Ruby" do
- file, line = Kernel.instance_method(:tap).source_location
- file.should.start_with?('<internal:')
+ ruby_version_is ""..."4.0" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller(1, 1)[0] }
+ loc.should =~ /\A<internal:.*in [`'](?:Kernel#)?tap'\z/
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
- loc = nil
- tap { loc = caller(1, 1)[0] }
- loc.should =~ /\A<internal:.*in [`'](?:Kernel#)?tap'\z/
+ loc = nil
+ tap { loc = caller(1, 1)[0] }
+ loc.should =~ /\A#{ __FILE__ }:.*in [`'](?:Kernel#)?tap'\z/
+ end
end
end
end
diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb
index c189d5f0a2..e027294347 100644
--- a/spec/ruby/core/kernel/eval_spec.rb
+++ b/spec/ruby/core/kernel/eval_spec.rb
@@ -175,6 +175,75 @@ describe "Kernel#eval" do
end
end
+ context "parameter forwarding" do
+ it "allows anonymous rest parameter forwarding" do
+ object = Object.new
+ def object.foo(a, b, c)
+ [a, b, c]
+ end
+ def object.bar(*)
+ eval "foo(*)"
+ end
+
+ object.bar(1, 2, 3).should == [1, 2, 3]
+ end
+
+ it "allows anonymous keyword parameters forwarding" do
+ object = Object.new
+ def object.foo(a:, b:, c:)
+ [a, b, c]
+ end
+ def object.bar(**)
+ eval "foo(**)"
+ end
+
+ object.bar(a: 1, b: 2, c: 3).should == [1, 2, 3]
+ end
+
+ it "allows anonymous block parameter forwarding" do
+ object = Object.new
+ def object.foo(&block)
+ block.call
+ end
+ def object.bar(&)
+ eval "foo(&)"
+ end
+
+ object.bar { :foobar }.should == :foobar
+ end
+
+ it "allows ... forwarding" do
+ object = Object.new
+ def object.foo(a, b:, &block)
+ [a, b, block.call]
+ end
+ def object.bar(...)
+ eval "foo(...)"
+ end
+
+ object.bar(1, b: 2) { 3 }.should == [1, 2, 3]
+ end
+
+ it "allows parameter forwarding to super" do
+ m = Module.new do
+ def foo(a, b:, &block)
+ [a, b, block.call]
+ end
+ end
+
+ c = Class.new do
+ include m
+
+ def foo(a, b:, &block)
+ eval "super"
+ end
+ end
+
+ object = c.new
+ object.foo(1, b: 2) { 3 }.should == [1, 2, 3]
+ end
+ end
+
ruby_version_is "3.3" do
it "uses (eval at __FILE__:__LINE__) if none is provided" do
eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})"
diff --git a/spec/ruby/core/kernel/inspect_spec.rb b/spec/ruby/core/kernel/inspect_spec.rb
index 1f9ce834ab..1fa66cab98 100644
--- a/spec/ruby/core/kernel/inspect_spec.rb
+++ b/spec/ruby/core/kernel/inspect_spec.rb
@@ -28,4 +28,63 @@ describe "Kernel#inspect" do
end
obj.inspect.should be_kind_of(String)
end
+
+ ruby_version_is "4.0" do
+ it "calls #instance_variables_to_inspect private method to know which variables to display" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = %i[@host @user @does_not_exist]
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == '#<Object:0x00 @host="localhost", @user="root">'
+
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = []
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == "#<Object:0x00>"
+ end
+
+ it "displays all instance variables if #instance_variables_to_inspect returns nil" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = nil
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == %{#<Object:0x00 @host="localhost", @user="root", @password="hunter2">}
+ end
+
+ it "raises an error if #instance_variables_to_inspect returns an invalid value" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = {}
+ end
+
+ ->{ obj.inspect }.should raise_error(TypeError, "Expected #instance_variables_to_inspect to return an Array or nil, but it returned Hash")
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/match_spec.rb b/spec/ruby/core/kernel/match_spec.rb
index aa25006163..cd6330fe91 100644
--- a/spec/ruby/core/kernel/match_spec.rb
+++ b/spec/ruby/core/kernel/match_spec.rb
@@ -1,30 +1,7 @@
require_relative '../../spec_helper'
describe "Kernel#=~" do
- ruby_version_is ''...'3.2' do
- it "returns nil matching any object" do
- o = Object.new
-
- suppress_warning do
- (o =~ /Object/).should be_nil
- (o =~ 'Object').should be_nil
- (o =~ Object).should be_nil
- (o =~ Object.new).should be_nil
- (o =~ nil).should be_nil
- (o =~ true).should be_nil
- end
- end
-
- it "is deprecated" do
- -> do
- Object.new =~ /regexp/
- end.should complain(/deprecated Object#=~ is called on Object/, verbose: true)
- end
- end
-
- ruby_version_is '3.2' do
- it "is no longer defined" do
- Object.new.should_not.respond_to?(:=~)
- end
+ it "is no longer defined" do
+ Object.new.should_not.respond_to?(:=~)
end
end
diff --git a/spec/ruby/core/kernel/not_match_spec.rb b/spec/ruby/core/kernel/not_match_spec.rb
index f8dd82fad8..082e56fed7 100644
--- a/spec/ruby/core/kernel/not_match_spec.rb
+++ b/spec/ruby/core/kernel/not_match_spec.rb
@@ -14,18 +14,8 @@ describe "Kernel#!~" do
(obj !~ :foo).should == false
end
- ruby_version_is ""..."3.2" do
- it "returns true if self does not respond to #=~" do
- suppress_warning do
- (Object.new !~ :foo).should == true
- end
- end
- end
-
- ruby_version_is "3.2" do
- it "raises NoMethodError if self does not respond to #=~" do
- -> { Object.new !~ :foo }.should raise_error(NoMethodError)
- end
+ it "raises NoMethodError if self does not respond to #=~" do
+ -> { Object.new !~ :foo }.should raise_error(NoMethodError)
end
it 'can be overridden in subclasses' do
diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb
index bb42c31f31..b967d5044b 100644
--- a/spec/ruby/core/kernel/open_spec.rb
+++ b/spec/ruby/core/kernel/open_spec.rb
@@ -27,64 +27,66 @@ describe "Kernel#open" do
open(@name, "r") { |f| f.gets }.should == @content
end
- platform_is_not :windows, :wasi do
- it "opens an io when path starts with a pipe" do
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- @io = open("|date")
+ ruby_version_is ""..."4.0" do
+ platform_is_not :windows, :wasi do
+ it "opens an io when path starts with a pipe" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @io = open("|date")
+ end
+ begin
+ @io.should be_kind_of(IO)
+ @io.read
+ ensure
+ @io.close
+ end
end
- begin
- @io.should be_kind_of(IO)
- @io.read
- ensure
- @io.close
- end
- end
- it "opens an io when called with a block" do
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- @output = open("|date") { |f| f.read }
+ it "opens an io when called with a block" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @output = open("|date") { |f| f.read }
+ end
+ @output.should_not == ''
end
- @output.should_not == ''
- end
- it "opens an io for writing" do
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- -> {
- bytes = open("|cat", "w") { |io| io.write(".") }
- bytes.should == 1
- }.should output_to_fd(".")
+ it "opens an io for writing" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ -> {
+ bytes = open("|cat", "w") { |io| io.write(".") }
+ bytes.should == 1
+ }.should output_to_fd(".")
+ end
end
end
- end
- platform_is :windows do
- it "opens an io when path starts with a pipe" do
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- @io = open("|date /t")
+ platform_is :windows do
+ it "opens an io when path starts with a pipe" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @io = open("|date /t")
+ end
+ begin
+ @io.should be_kind_of(IO)
+ @io.read
+ ensure
+ @io.close
+ end
end
- begin
- @io.should be_kind_of(IO)
- @io.read
- ensure
- @io.close
- end
- end
- it "opens an io when called with a block" do
- suppress_warning do # https://bugs.ruby-lang.org/issues/19630
- @output = open("|date /t") { |f| f.read }
+ it "opens an io when called with a block" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @output = open("|date /t") { |f| f.read }
+ end
+ @output.should_not == ''
end
- @output.should_not == ''
end
- end
- ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19630
- it "warns about deprecation given a path with a pipe" do
- cmd = "|echo ok"
- -> {
- open(cmd) { |f| f.read }
- }.should complain(/Kernel#open with a leading '\|'/)
+ ruby_version_is "3.3" do
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ open(cmd) { |f| f.read }
+ }.should complain(/Kernel#open with a leading '\|'/)
+ end
end
end
@@ -106,7 +108,7 @@ describe "Kernel#open" do
ScratchPad.clear
end
- it "calls #to_path to covert the argument to a String before calling #to_str" do
+ it "calls #to_path to convert the argument to a String before calling #to_str" do
obj = mock("open to_path")
obj.should_receive(:to_path).at_least(1).times.and_return(@name)
obj.should_not_receive(:to_str)
diff --git a/spec/ruby/core/kernel/raise_spec.rb b/spec/ruby/core/kernel/raise_spec.rb
index a038dcf031..fcd011d4e6 100644
--- a/spec/ruby/core/kernel/raise_spec.rb
+++ b/spec/ruby/core/kernel/raise_spec.rb
@@ -44,7 +44,53 @@ describe "Kernel#raise" do
it "raises an ArgumentError when only cause is given" do
cause = StandardError.new
- -> { raise(cause: cause) }.should raise_error(ArgumentError)
+ -> { raise(cause: cause) }.should raise_error(ArgumentError, "only cause is given with no arguments")
+ end
+
+ it "raises an ArgumentError when only cause is given even if it has nil value" do
+ -> { raise(cause: nil) }.should raise_error(ArgumentError, "only cause is given with no arguments")
+ end
+
+ it "raises a TypeError when given cause is not an instance of Exception" do
+ -> { raise "message", cause: Object.new }.should raise_error(TypeError, "exception object expected")
+ end
+
+ it "doesn't raise a TypeError when given cause is nil" do
+ -> { raise "message", cause: nil }.should raise_error(RuntimeError, "message")
+ end
+
+ it "allows cause equal an exception" do
+ e = RuntimeError.new("message")
+ -> { raise e, cause: e }.should raise_error(e)
+ end
+
+ it "doesn't set given cause when it equals an exception" do
+ e = RuntimeError.new("message")
+
+ begin
+ raise e, cause: e
+ rescue
+ end
+
+ e.cause.should == nil
+ end
+
+ it "raises ArgumentError when exception is part of the cause chain" do
+ -> {
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ begin
+ raise "Error 3"
+ rescue => e3
+ raise e1, cause: e3
+ end
+ end
+ end
+ }.should raise_error(ArgumentError, "circular causes")
end
it "re-raises a rescued exception" do
@@ -62,6 +108,179 @@ describe "Kernel#raise" do
end
end.should raise_error(StandardError, "aaa")
end
+
+ it "re-raises a previously rescued exception without overwriting the cause" do
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2
+ end
+ rescue => e
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception with overwriting the cause when it's explicitly specified with :cause option" do
+ e4 = RuntimeError.new("Error 4")
+
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2, cause: e4
+ end
+ rescue => e
+ e.cause.should == e4
+ end
+ end
+
+ it "re-raises a previously rescued exception without overwriting the cause when it's explicitly specified with :cause option and has nil value" do
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2, cause: nil
+ end
+ rescue => e
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that has a cause without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ raise
+ end
+ end
+ rescue => e
+ e.should == e2
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and isn't a cause of any other exception with setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ raise "Error 3"
+ end
+ end
+ rescue => e
+ e.message.should == "Error 3"
+ e.cause.should == e2
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and is a cause of other exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ e1.cause.should == nil
+ e2.cause.should == e1
+ raise e1
+ end
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and is a cause of other exception (that wasn't raised explicitly) without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ foo # raises NameError
+ rescue => e2
+ e1.cause.should == nil
+ e2.cause.should == e1
+ raise e1
+ end
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that has a cause but isn't a cause of any other exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ begin
+ raise "Error 3", cause: RuntimeError.new("Error 4")
+ rescue => e3
+ e2.cause.should == e1
+ e3.cause.should_not == e2
+ raise e2
+ end
+ end
+ end
+ rescue => e
+ e.should == e2
+ e.cause.should == e1
+ end
+ end
end
describe "Kernel#raise" do
diff --git a/spec/ruby/core/kernel/require_spec.rb b/spec/ruby/core/kernel/require_spec.rb
index e78e7176ec..60d17242fe 100644
--- a/spec/ruby/core/kernel/require_spec.rb
+++ b/spec/ruby/core/kernel/require_spec.rb
@@ -17,6 +17,10 @@ describe "Kernel#require" do
end
provided = %w[complex enumerator fiber rational thread ruby2_keywords]
+ ruby_version_is "4.0" do
+ provided << "set"
+ provided << "pathname"
+ end
it "#{provided.join(', ')} are already required" do
out = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems --disable-did-you-mean')
@@ -28,9 +32,14 @@ describe "Kernel#require" do
features.sort.should == provided.sort
- code = provided.map { |f| "puts require #{f.inspect}\n" }.join
+ requires = provided
+ ruby_version_is "4.0" do
+ requires = requires.map { |f| f == "pathname" ? "pathname.so" : f }
+ end
+
+ code = requires.map { |f| "puts require #{f.inspect}\n" }.join
required = ruby_exe(code, options: '--disable-gems')
- required.should == "false\n" * provided.size
+ required.should == "false\n" * requires.size
end
it_behaves_like :kernel_require_basic, :require, CodeLoadingSpecs::Method.new
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index b31c89e3bf..52f86f73e5 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -296,6 +296,16 @@ describe :kernel_require, shared: true do
$LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
@object.require("load_fixture").should be_false
end
+
+ it "stores the missing path in a LoadError object" do
+ path = "abcd1234"
+
+ -> {
+ @object.send(@method, path)
+ }.should raise_error(LoadError) { |e|
+ e.path.should == path
+ }
+ end
end
describe "(file extensions)" do
@@ -815,4 +825,24 @@ describe :kernel_require, shared: true do
e.path.should == path
}
end
+
+ platform_is :linux, :darwin do
+ it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path without extension" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture"
+ -> { @object.send(@method, path) }.should raise_error(LoadError) { |e|
+ e.path.should == nil
+ }
+ end
+ end
+
+ platform_is :darwin do
+ it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path with extension" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture.bundle"
+ -> { @object.send(@method, path) }.should raise_error(LoadError) { |e|
+ e.path.should == nil
+ }
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb
index 13dc6e97f0..2b2c6c9b63 100644
--- a/spec/ruby/core/kernel/shared/sprintf.rb
+++ b/spec/ruby/core/kernel/shared/sprintf.rb
@@ -22,6 +22,7 @@ describe :kernel_sprintf, shared: true do
@method.call("%d", "112").should == "112"
@method.call("%d", "0127").should == "87"
@method.call("%d", "0xc4").should == "196"
+ @method.call("%d", "0").should == "0"
end
it "raises TypeError exception if cannot convert to Integer" do
@@ -57,6 +58,11 @@ describe :kernel_sprintf, shared: true do
it "works well with large numbers" do
@method.call("%#{f}", 1234567890987654321).should == "1234567890987654321"
end
+
+ it "converts to the empty string if precision is 0 and value is 0" do
+ @method.call("%.#{f}", 0).should == ""
+ @method.call("%.0#{f}", 0).should == ""
+ end
end
end
@@ -289,28 +295,12 @@ describe :kernel_sprintf, shared: true do
@method.call("%c", "a").should == "a"
end
- ruby_version_is ""..."3.2" do
- it "raises ArgumentError if argument is a string of several characters" do
- -> {
- @method.call("%c", "abc")
- }.should raise_error(ArgumentError, /%c requires a character/)
- end
-
- it "raises ArgumentError if argument is an empty string" do
- -> {
- @method.call("%c", "")
- }.should raise_error(ArgumentError, /%c requires a character/)
- end
+ it "displays only the first character if argument is a string of several characters" do
+ @method.call("%c", "abc").should == "a"
end
- ruby_version_is "3.2" do
- it "displays only the first character if argument is a string of several characters" do
- @method.call("%c", "abc").should == "a"
- end
-
- it "displays no characters if argument is an empty string" do
- @method.call("%c", "").should == ""
- end
+ it "displays no characters if argument is an empty string" do
+ @method.call("%c", "").should == ""
end
it "raises TypeError if argument is not String or Integer and cannot be converted to them" do
@@ -372,6 +362,10 @@ describe :kernel_sprintf, shared: true do
obj.should_receive(:inspect).and_return("<inspect-result>")
@method.call("%p", obj).should == "<inspect-result>"
end
+
+ it "substitutes 'nil' for nil" do
+ @method.call("%p", nil).should == "nil"
+ end
end
describe "s" do
@@ -455,7 +449,7 @@ describe :kernel_sprintf, shared: true do
it "is escaped by %" do
@method.call("%%").should == "%"
- @method.call("%%d", 10).should == "%d"
+ @method.call("%%d").should == "%d"
end
end
end
diff --git a/spec/ruby/core/kernel/singleton_method_spec.rb b/spec/ruby/core/kernel/singleton_method_spec.rb
index 0bdf125ad8..7d63fa7cc6 100644
--- a/spec/ruby/core/kernel/singleton_method_spec.rb
+++ b/spec/ruby/core/kernel/singleton_method_spec.rb
@@ -1,7 +1,7 @@
require_relative '../../spec_helper'
describe "Kernel#singleton_method" do
- it "find a method defined on the singleton class" do
+ it "finds a method defined on the singleton class" do
obj = Object.new
def obj.foo; end
obj.singleton_method(:foo).should be_an_instance_of(Method)
@@ -38,4 +38,48 @@ describe "Kernel#singleton_method" do
e.class.should == NameError
}
end
+
+ ruby_bug "#20620", ""..."3.4" do
+ it "finds a method defined in a module included in the singleton class" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.singleton_class.include(m)
+
+ obj.singleton_method(:foo).should be_an_instance_of(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+
+ it "finds a method defined in a module prepended in the singleton class" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.singleton_class.prepend(m)
+
+ obj.singleton_method(:foo).should be_an_instance_of(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+
+ it "finds a method defined in a module that an object is extended with" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.extend(m)
+
+ obj.singleton_method(:foo).should be_an_instance_of(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/sleep_spec.rb b/spec/ruby/core/kernel/sleep_spec.rb
index 4401e54256..e9c600aac4 100644
--- a/spec/ruby/core/kernel/sleep_spec.rb
+++ b/spec/ruby/core/kernel/sleep_spec.rb
@@ -1,4 +1,5 @@
require_relative '../../spec_helper'
+require_relative '../fiber/fixtures/scheduler'
describe "Kernel#sleep" do
it "is a private method" do
@@ -84,6 +85,40 @@ describe "Kernel#sleep" do
t.value.should == 5
end
end
+
+ context "Kernel.sleep with Fiber scheduler" do
+ before :each do
+ Fiber.set_scheduler(FiberSpecs::LoggingScheduler.new)
+ end
+
+ after :each do
+ Fiber.set_scheduler(nil)
+ end
+
+ it "calls the scheduler without arguments when no duration is given" do
+ sleeper = Fiber.new(blocking: false) do
+ sleep
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == [{ event: :kernel_sleep, fiber: sleeper, args: [] }]
+ end
+
+ it "calls the scheduler with the given duration" do
+ sleeper = Fiber.new(blocking: false) do
+ sleep(0.01)
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == [{ event: :kernel_sleep, fiber: sleeper, args: [0.01] }]
+ end
+
+ it "does not call the scheduler if the fiber is blocking" do
+ sleeper = Fiber.new(blocking: true) do
+ sleep(0.01)
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == []
+ end
+ end
end
describe "Kernel.sleep" do
diff --git a/spec/ruby/core/kernel/sprintf_spec.rb b/spec/ruby/core/kernel/sprintf_spec.rb
index 9ef7f86f16..5a4a90ff7a 100644
--- a/spec/ruby/core/kernel/sprintf_spec.rb
+++ b/spec/ruby/core/kernel/sprintf_spec.rb
@@ -13,28 +13,52 @@ end
describe "Kernel#sprintf" do
it_behaves_like :kernel_sprintf, -> format, *args {
- sprintf(format, *args)
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
it_behaves_like :kernel_sprintf_encoding, -> format, *args {
- sprintf(format, *args)
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
it_behaves_like :kernel_sprintf_to_str, -> format, *args {
- sprintf(format, *args)
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
end
describe "Kernel.sprintf" do
it_behaves_like :kernel_sprintf, -> format, *args {
- Kernel.sprintf(format, *args)
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
it_behaves_like :kernel_sprintf_encoding, -> format, *args {
- Kernel.sprintf(format, *args)
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
it_behaves_like :kernel_sprintf_to_str, -> format, *args {
- Kernel.sprintf(format, *args)
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
}
end
diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb
index 0c16b1dbbf..9a2efbaea0 100644
--- a/spec/ruby/core/kernel/taint_spec.rb
+++ b/spec/ruby/core/kernel/taint_spec.rb
@@ -2,26 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#taint" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = Object.new
- o.taint
- o.should_not.tainted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- obj = mock("tainted")
- obj.taint
- }.should complain(/Object#taint is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:taint)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:taint)
end
end
diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb
index fcae433069..837eb1dafb 100644
--- a/spec/ruby/core/kernel/tainted_spec.rb
+++ b/spec/ruby/core/kernel/tainted_spec.rb
@@ -2,28 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#tainted?" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = mock('o')
- p = mock('p')
- p.taint
- o.should_not.tainted?
- p.should_not.tainted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- o = mock('o')
- o.tainted?
- }.should complain(/Object#tainted\? is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:tainted?)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:tainted?)
end
end
diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb
index db6f17e0fb..ef3fa9a3e1 100644
--- a/spec/ruby/core/kernel/trust_spec.rb
+++ b/spec/ruby/core/kernel/trust_spec.rb
@@ -2,27 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#trust" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = Object.new.untrust
- o.should_not.untrusted?
- o.trust
- o.should_not.untrusted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- o = Object.new.untrust
- o.trust
- }.should complain(/Object#trust is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:trust)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:trust)
end
end
diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb
index 26b2aabbe9..47e8544bd4 100644
--- a/spec/ruby/core/kernel/untaint_spec.rb
+++ b/spec/ruby/core/kernel/untaint_spec.rb
@@ -2,27 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untaint" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = Object.new.taint
- o.should_not.tainted?
- o.untaint
- o.should_not.tainted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- o = Object.new.taint
- o.untaint
- }.should complain(/Object#untaint is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:untaint)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untaint)
end
end
diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb
index 5310cd8eb4..8787ab3fc9 100644
--- a/spec/ruby/core/kernel/untrust_spec.rb
+++ b/spec/ruby/core/kernel/untrust_spec.rb
@@ -2,26 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untrust" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = Object.new
- o.untrust
- o.should_not.untrusted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- o = Object.new
- o.untrust
- }.should complain(/Object#untrust is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:untrust)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untrust)
end
end
diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb
index ea36d6c98c..29261be9c4 100644
--- a/spec/ruby/core/kernel/untrusted_spec.rb
+++ b/spec/ruby/core/kernel/untrusted_spec.rb
@@ -2,27 +2,7 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Kernel#untrusted?" do
- ruby_version_is ""..."3.2" do
- it "is a no-op" do
- suppress_warning do
- o = mock('o')
- o.should_not.untrusted?
- o.untrust
- o.should_not.untrusted?
- end
- end
-
- it "warns in verbose mode" do
- -> {
- o = mock('o')
- o.untrusted?
- }.should complain(/Object#untrusted\? is deprecated and will be removed in Ruby 3.2/, verbose: true)
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- Object.new.should_not.respond_to?(:untrusted?)
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untrusted?)
end
end
diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb
index 00164ad90b..e03498c6dc 100644
--- a/spec/ruby/core/kernel/warn_spec.rb
+++ b/spec/ruby/core/kernel/warn_spec.rb
@@ -112,6 +112,12 @@ describe "Kernel#warn" do
ruby_exe(file, options: "-rrubygems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
end
+ it "doesn't show the caller when the uplevel is `nil`" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4("foo", nil) }.should output(nil, "foo\n")
+ end
+
guard -> { Kernel.instance_method(:tap).source_location } do
it "skips <internal: core library methods defined in Ruby" do
file, line = Kernel.instance_method(:tap).source_location
diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb
index 8a23970c4b..5b9a751595 100644
--- a/spec/ruby/core/main/using_spec.rb
+++ b/spec/ruby/core/main/using_spec.rb
@@ -142,11 +142,9 @@ describe "main.using" do
end.should raise_error(RuntimeError)
end
- ruby_version_is "3.2" do
- it "does not raise error when wrapped with module" do
- -> do
- load File.expand_path('../fixtures/using.rb', __FILE__), true
- end.should_not raise_error
- end
+ it "does not raise error when wrapped with module" do
+ -> do
+ load File.expand_path('../fixtures/using.rb', __FILE__), true
+ end.should_not raise_error
end
end
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index c2a2b77999..ff9b9214fa 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'fixtures/marshal_data'
@@ -231,9 +231,12 @@ describe "Marshal.dump" do
Marshal.dump(MarshalSpec::ClassWithOverriddenName).should == "\x04\bc)MarshalSpec::ClassWithOverriddenName"
end
- it "dumps a class with multibyte characters in name" do
- source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Class".dup.force_encoding(Encoding::UTF_8))
- Marshal.dump(source_object).should == "\x04\bc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class"
+ ruby_version_is "4.0" do
+ it "dumps a class with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Class".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
+ end
end
it "uses object links for objects repeatedly dumped" do
@@ -258,9 +261,12 @@ describe "Marshal.dump" do
Marshal.dump(MarshalSpec::ModuleWithOverriddenName).should == "\x04\bc*MarshalSpec::ModuleWithOverriddenName"
end
- it "dumps a module with multibyte characters in name" do
- source_object = eval("MarshalSpec::Multibyteã‘ã’ã“ã”Module".dup.force_encoding(Encoding::UTF_8))
- Marshal.dump(source_object).should == "\x04\bm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module"
+ ruby_version_is "4.0" do
+ it "dumps a module with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteã‘ã’ã“ã”Module".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
+ end
end
it "uses object links for objects repeatedly dumped" do
@@ -361,30 +367,28 @@ describe "Marshal.dump" do
end
end
- ruby_version_is "3.2" do
- describe "with a Data" do
- it "dumps a Data" do
- Marshal.dump(MarshalSpec::DataSpec::Measure.new(100, 'km')).should == "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
- end
+ describe "with a Data" do
+ it "dumps a Data" do
+ Marshal.dump(MarshalSpec::DataSpec::Measure.new(100, 'km')).should == "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ end
- it "dumps an extended Data" do
- obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
- Marshal.dump(obj).should == "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
- end
+ it "dumps an extended Data" do
+ obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
+ Marshal.dump(obj).should == "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
+ end
- it "ignores overridden name method" do
- obj = MarshalSpec::DataSpec::MeasureWithOverriddenName.new(100, "km")
- Marshal.dump(obj).should == "\x04\bS:5MarshalSpec::DataSpec::MeasureWithOverriddenName\a:\vamountii:\tunit\"\akm"
- end
+ it "ignores overridden name method" do
+ obj = MarshalSpec::DataSpec::MeasureWithOverriddenName.new(100, "km")
+ Marshal.dump(obj).should == "\x04\bS:5MarshalSpec::DataSpec::MeasureWithOverriddenName\a:\vamountii:\tunit\"\akm"
+ end
- it "uses object links for objects repeatedly dumped" do
- d = MarshalSpec::DataSpec::Measure.new(100, 'km')
- Marshal.dump([d, d]).should == "\x04\b[\aS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm@\x06" # @\x06 is a link to the object
- end
+ it "uses object links for objects repeatedly dumped" do
+ d = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ Marshal.dump([d, d]).should == "\x04\b[\aS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm@\x06" # @\x06 is a link to the object
+ end
- it "raises TypeError with an anonymous Struct" do
- -> { Marshal.dump(Data.define(:a).new(1)) }.should raise_error(TypeError, /can't dump anonymous class/)
- end
+ it "raises TypeError with an anonymous Struct" do
+ -> { Marshal.dump(Data.define(:a).new(1)) }.should raise_error(TypeError, /can't dump anonymous class/)
end
end
@@ -876,9 +880,12 @@ describe "Marshal.dump" do
Marshal.dump(obj).should include("MarshalSpec::TimeWithOverriddenName")
end
- it "dumps a Time subclass with multibyte characters in name" do
- source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Time".dup.force_encoding(Encoding::UTF_8))
- Marshal.dump(source_object).should == "\x04\bc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time"
+ ruby_version_is "4.0" do
+ it "dumps a Time subclass with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Time".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
+ end
end
it "uses object links for objects repeatedly dumped" do
diff --git a/spec/ruby/core/marshal/fixtures/marshal_data.rb b/spec/ruby/core/marshal/fixtures/marshal_data.rb
index 3ba85aa6eb..c16d9e4bb6 100644
--- a/spec/ruby/core/marshal/fixtures/marshal_data.rb
+++ b/spec/ruby/core/marshal/fixtures/marshal_data.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative 'marshal_multibyte_data'
@@ -532,18 +532,16 @@ module MarshalSpec
"Random" => random_data,
}
- if defined? Data # TODO: remove the condition when minimal supported version is 3.2
- module DataSpec
- Measure = Data.define(:amount, :unit)
- Empty = Data.define
+ module DataSpec
+ Measure = Data.define(:amount, :unit)
+ Empty = Data.define
- MeasureExtended = Class.new(Measure)
- MeasureExtended.extend(Enumerable)
+ MeasureExtended = Class.new(Measure)
+ MeasureExtended.extend(Enumerable)
- class MeasureWithOverriddenName < Measure
- def self.name
- "Foo"
- end
+ class MeasureWithOverriddenName < Measure
+ def self.name
+ "Foo"
end
end
end
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
index f73fa67e9a..204a4d34e3 100644
--- a/spec/ruby/core/marshal/shared/load.rb
+++ b/spec/ruby/core/marshal/shared/load.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../fixtures/marshal_data'
describe :marshal_load, shared: true do
@@ -139,7 +139,7 @@ describe :marshal_load, shared: true do
end
end
- ruby_bug "#19427", "3.1"..."3.3" do
+ ruby_bug "#19427", ""..."3.3" do
it "returns frozen object having #_dump method" do
object = Marshal.send(@method, Marshal.dump(UserDefined.new), freeze: true)
object.should.frozen?
@@ -739,31 +739,29 @@ describe :marshal_load, shared: true do
end
end
- ruby_version_is "3.2" do
- describe "for a Data" do
- it "loads a Data" do
- obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
- dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
- Marshal.dump(obj).should == dumped
+ describe "for a Data" do
+ it "loads a Data" do
+ obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
- Marshal.send(@method, dumped).should == obj
- end
+ Marshal.send(@method, dumped).should == obj
+ end
- it "loads an extended Data" do
- obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
- dumped = "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
- Marshal.dump(obj).should == dumped
+ it "loads an extended Data" do
+ obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
+ dumped = "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
- Marshal.send(@method, dumped).should == obj
- end
+ Marshal.send(@method, dumped).should == obj
+ end
- it "returns a frozen object" do
- obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
- dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
- Marshal.dump(obj).should == dumped
+ it "returns a frozen object" do
+ obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
- Marshal.send(@method, dumped).should.frozen?
- end
+ Marshal.send(@method, dumped).should.frozen?
end
end
diff --git a/spec/ruby/core/matchdata/bytebegin_spec.rb b/spec/ruby/core/matchdata/bytebegin_spec.rb
new file mode 100644
index 0000000000..08c1fd6d1e
--- /dev/null
+++ b/spec/ruby/core/matchdata/bytebegin_spec.rb
@@ -0,0 +1,132 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "MatchData#bytebegin" do
+ context "when passed an integer argument" do
+ it "returns the byte-based offset of the start of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 2
+ end
+
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.bytebegin(1).should be_nil
+ end
+
+ it "returns the byte-based offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 3
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 3
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(obj).should == 2
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin(-1)
+ }.should raise_error(IndexError, "index -1 out of matches")
+
+ -> {
+ match_data.bytebegin(3)
+ }.should raise_error(IndexError, "index 3 out of matches")
+ end
+ end
+
+ context "when passed a String argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 3
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 4
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("a").should == 3
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("æ").should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin("y")
+ }.should raise_error(IndexError, "undefined group name reference: y")
+ end
+ end
+
+ context "when passed a Symbol argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 3
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 4
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:a).should == 3
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:æ).should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin(:y)
+ }.should raise_error(IndexError, "undefined group name reference: y")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/matchdata/byteend_spec.rb b/spec/ruby/core/matchdata/byteend_spec.rb
new file mode 100644
index 0000000000..98015e287d
--- /dev/null
+++ b/spec/ruby/core/matchdata/byteend_spec.rb
@@ -0,0 +1,104 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "MatchData#byteend" do
+ context "when passed an integer argument" do
+ it "returns the byte-based offset of the end of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.byteend(0).should == 7
+ match_data.byteend(2).should == 3
+ end
+
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.byteend(1).should be_nil
+ end
+
+ it "returns the byte-based offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.byteend(0).should == 8
+ match_data.byteend(2).should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend(0).should == 8
+ match_data.byteend(2).should == 4
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.byteend(obj).should == 3
+ end
+ end
+
+ context "when passed a String argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("a").should == 2
+ match_data.byteend("b").should == 6
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.byteend("a").should == 3
+ match_data.byteend("b").should == 7
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend("a").should == 3
+ match_data.byteend("b").should == 7
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("a").should == 6
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("æ").should == 2
+ end
+ end
+
+ context "when passed a Symbol argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:a).should == 2
+ match_data.byteend(:b).should == 6
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.byteend(:a).should == 3
+ match_data.byteend(:b).should == 7
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend(:a).should == 3
+ match_data.byteend(:b).should == 7
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:a).should == 6
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:æ).should == 2
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/matchdata/byteoffset_spec.rb b/spec/ruby/core/matchdata/byteoffset_spec.rb
index b27267fd0e..fb8f5fb67d 100644
--- a/spec/ruby/core/matchdata/byteoffset_spec.rb
+++ b/spec/ruby/core/matchdata/byteoffset_spec.rb
@@ -1,95 +1,93 @@
require_relative '../../spec_helper'
describe "MatchData#byteoffset" do
- ruby_version_is "3.2" do
- it "returns beginning and ending byte-based offset of whole matched substring for 0 element" do
- m = /(.)(.)(\d+)(\d)/.match("THX1138.")
- m.byteoffset(0).should == [1, 7]
- end
+ it "returns beginning and ending byte-based offset of whole matched substring for 0 element" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ m.byteoffset(0).should == [1, 7]
+ end
- it "returns beginning and ending byte-based offset of n-th match, all the subsequent elements are capturing groups" do
- m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ it "returns beginning and ending byte-based offset of n-th match, all the subsequent elements are capturing groups" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
- m.byteoffset(2).should == [2, 3]
- m.byteoffset(3).should == [3, 6]
- m.byteoffset(4).should == [6, 7]
- end
+ m.byteoffset(2).should == [2, 3]
+ m.byteoffset(3).should == [3, 6]
+ m.byteoffset(4).should == [6, 7]
+ end
- it "accepts String as a reference to a named capture" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "accepts String as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.byteoffset("f").should == [0, 3]
- m.byteoffset("b").should == [3, 6]
- end
+ m.byteoffset("f").should == [0, 3]
+ m.byteoffset("b").should == [3, 6]
+ end
- it "accepts Symbol as a reference to a named capture" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "accepts Symbol as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.byteoffset(:f).should == [0, 3]
- m.byteoffset(:b).should == [3, 6]
- end
+ m.byteoffset(:f).should == [0, 3]
+ m.byteoffset(:b).should == [3, 6]
+ end
- it "returns [nil, nil] if a capturing group is optional and doesn't match" do
- m = /(?<x>q..)?/.match("foobarbaz")
+ it "returns [nil, nil] if a capturing group is optional and doesn't match" do
+ m = /(?<x>q..)?/.match("foobarbaz")
- m.byteoffset("x").should == [nil, nil]
- m.byteoffset(1).should == [nil, nil]
- end
+ m.byteoffset("x").should == [nil, nil]
+ m.byteoffset(1).should == [nil, nil]
+ end
- it "returns correct beginning and ending byte-based offset for multi-byte strings" do
- m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+ it "returns correct beginning and ending byte-based offset for multi-byte strings" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
- m.byteoffset(1).should == [3, 6]
- m.byteoffset(3).should == [6, 9]
- end
+ m.byteoffset(1).should == [3, 6]
+ m.byteoffset(3).should == [6, 9]
+ end
- it "returns [nil, nil] if a capturing group is optional and doesn't match for multi-byte string" do
- m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+ it "returns [nil, nil] if a capturing group is optional and doesn't match for multi-byte string" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
- m.byteoffset(2).should == [nil, nil]
- end
+ m.byteoffset(2).should == [nil, nil]
+ end
- it "converts argument into integer if is not String nor Symbol" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "converts argument into integer if is not String nor Symbol" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- obj = Object.new
- def obj.to_int; 2; end
+ obj = Object.new
+ def obj.to_int; 2; end
- m.byteoffset(1r).should == [0, 3]
- m.byteoffset(1.1).should == [0, 3]
- m.byteoffset(obj).should == [3, 6]
- end
+ m.byteoffset(1r).should == [0, 3]
+ m.byteoffset(1.1).should == [0, 3]
+ m.byteoffset(obj).should == [3, 6]
+ end
- it "raises IndexError if there is no group with the provided name" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "raises IndexError if there is no group with the provided name" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- -> {
- m.byteoffset("y")
- }.should raise_error(IndexError, "undefined group name reference: y")
+ -> {
+ m.byteoffset("y")
+ }.should raise_error(IndexError, "undefined group name reference: y")
- -> {
- m.byteoffset(:y)
- }.should raise_error(IndexError, "undefined group name reference: y")
- end
+ -> {
+ m.byteoffset(:y)
+ }.should raise_error(IndexError, "undefined group name reference: y")
+ end
- it "raises IndexError if index is out of bounds" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "raises IndexError if index is out of bounds" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- -> {
- m.byteoffset(-1)
- }.should raise_error(IndexError, "index -1 out of matches")
+ -> {
+ m.byteoffset(-1)
+ }.should raise_error(IndexError, "index -1 out of matches")
- -> {
- m.byteoffset(3)
- }.should raise_error(IndexError, "index 3 out of matches")
- end
+ -> {
+ m.byteoffset(3)
+ }.should raise_error(IndexError, "index 3 out of matches")
+ end
- it "raises TypeError if can't convert argument into Integer" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "raises TypeError if can't convert argument into Integer" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- -> {
- m.byteoffset([])
- }.should raise_error(TypeError, "no implicit conversion of Array into Integer")
- end
+ -> {
+ m.byteoffset([])
+ }.should raise_error(TypeError, "no implicit conversion of Array into Integer")
end
end
diff --git a/spec/ruby/core/matchdata/deconstruct_keys_spec.rb b/spec/ruby/core/matchdata/deconstruct_keys_spec.rb
index 5b68f886c7..bf22bc33ff 100644
--- a/spec/ruby/core/matchdata/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/matchdata/deconstruct_keys_spec.rb
@@ -1,65 +1,63 @@
require_relative '../../spec_helper'
describe "MatchData#deconstruct_keys" do
- ruby_version_is "3.2" do
- it "returns whole hash for nil as an argument" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "returns whole hash for nil as an argument" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.deconstruct_keys(nil).should == { f: "foo", b: "bar" }
- end
+ m.deconstruct_keys(nil).should == { f: "foo", b: "bar" }
+ end
- it "returns only specified keys" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "returns only specified keys" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.deconstruct_keys([:f]).should == { f: "foo" }
- end
+ m.deconstruct_keys([:f]).should == { f: "foo" }
+ end
- it "requires one argument" do
- m = /l/.match("l")
+ it "requires one argument" do
+ m = /l/.match("l")
- -> {
- m.deconstruct_keys
- }.should raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1)")
- end
+ -> {
+ m.deconstruct_keys
+ }.should raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1)")
+ end
- it "it raises error when argument is neither nil nor array" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "it raises error when argument is neither nil nor array" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- -> { m.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array)")
- -> { m.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array)")
- -> { m.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array)")
- -> { m.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array)")
- end
+ -> { m.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array)")
+ -> { m.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array)")
+ -> { m.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array)")
+ -> { m.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array)")
+ end
- it "returns {} when passed []" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "returns {} when passed []" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.deconstruct_keys([]).should == {}
- end
+ m.deconstruct_keys([]).should == {}
+ end
- it "does not accept non-Symbol keys" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ it "does not accept non-Symbol keys" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
- -> {
- m.deconstruct_keys(['year', :foo])
- }.should raise_error(TypeError, "wrong argument type String (expected Symbol)")
- end
+ -> {
+ m.deconstruct_keys(['year', :foo])
+ }.should raise_error(TypeError, "wrong argument type String (expected Symbol)")
+ end
- it "process keys till the first non-existing one" do
- m = /(?<f>foo)(?<b>bar)(?<c>baz)/.match("foobarbaz")
+ it "process keys till the first non-existing one" do
+ m = /(?<f>foo)(?<b>bar)(?<c>baz)/.match("foobarbaz")
- m.deconstruct_keys([:f, :a, :b]).should == { f: "foo" }
- end
+ m.deconstruct_keys([:f, :a, :b]).should == { f: "foo" }
+ end
- it "returns {} when there are no named captured groups at all" do
- m = /foo.+/.match("foobar")
+ it "returns {} when there are no named captured groups at all" do
+ m = /foo.+/.match("foobar")
- m.deconstruct_keys(nil).should == {}
- end
+ m.deconstruct_keys(nil).should == {}
+ end
- it "returns {} when passed more keys than named captured groups" do
- m = /(?<f>foo)(?<b>bar)/.match("foobar")
- m.deconstruct_keys([:f, :b, :c]).should == {}
- end
+ it "returns {} when passed more keys than named captured groups" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ m.deconstruct_keys([:f, :b, :c]).should == {}
end
end
diff --git a/spec/ruby/core/matchdata/deconstruct_spec.rb b/spec/ruby/core/matchdata/deconstruct_spec.rb
index 6af55113b6..c55095665d 100644
--- a/spec/ruby/core/matchdata/deconstruct_spec.rb
+++ b/spec/ruby/core/matchdata/deconstruct_spec.rb
@@ -2,7 +2,5 @@ require_relative '../../spec_helper'
require_relative 'shared/captures'
describe "MatchData#deconstruct" do
- ruby_version_is "3.2" do
- it_behaves_like :matchdata_captures, :deconstruct
- end
+ it_behaves_like :matchdata_captures, :deconstruct
end
diff --git a/spec/ruby/core/matchdata/offset_spec.rb b/spec/ruby/core/matchdata/offset_spec.rb
index 1ccb54b7a7..a03d58aad1 100644
--- a/spec/ruby/core/matchdata/offset_spec.rb
+++ b/spec/ruby/core/matchdata/offset_spec.rb
@@ -1,30 +1,102 @@
-# -*- encoding: utf-8 -*-
-
require_relative '../../spec_helper'
describe "MatchData#offset" do
- it "returns a two element array with the begin and end of the nth match" do
- match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns beginning and ending character offset of whole matched substring for 0 element" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ m.offset(0).should == [1, 7]
+ end
+
+ it "returns beginning and ending character offset of n-th match, all the subsequent elements are capturing groups" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+
+ m.offset(2).should == [2, 3]
+ m.offset(3).should == [3, 6]
+ m.offset(4).should == [6, 7]
+ end
+
+ it "accepts String as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.offset("f").should == [0, 3]
+ m.offset("b").should == [3, 6]
+ end
+
+ it "accepts Symbol as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.offset(:f).should == [0, 3]
+ m.offset(:b).should == [3, 6]
end
- it "returns [nil, nil] when the nth match isn't found" do
- match_data = /something is( not)? (right)/.match("something is right")
- match_data.offset(1).should == [nil, nil]
+ it "returns [nil, nil] if a capturing group is optional and doesn't match" do
+ m = /(?<x>q..)?/.match("foobarbaz")
+
+ m.offset("x").should == [nil, nil]
+ m.offset(1).should == [nil, nil]
end
- it "returns the offset for multi byte strings" do
- match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns correct beginning and ending character offset for multi-byte strings" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.offset(1).should == [1, 2]
+ m.offset(3).should == [2, 3]
end
not_supported_on :opal do
- it "returns the offset for multi byte strings with unicode regexp" do
- match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns correct character offset for multi-byte strings with unicode regexp" do
+ m = /\A\u3042(.)(.)?(.)\z/u.match("\u3042\u3043\u3044")
+
+ m.offset(1).should == [1, 2]
+ m.offset(3).should == [2, 3]
end
end
+
+ it "returns [nil, nil] if a capturing group is optional and doesn't match for multi-byte string" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.offset(2).should == [nil, nil]
+ end
+
+ it "converts argument into integer if is not String nor Symbol" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ obj = Object.new
+ def obj.to_int; 2; end
+
+ m.offset(1r).should == [0, 3]
+ m.offset(1.1).should == [0, 3]
+ m.offset(obj).should == [3, 6]
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset("y")
+ }.should raise_error(IndexError, "undefined group name reference: y")
+
+ -> {
+ m.offset(:y)
+ }.should raise_error(IndexError, "undefined group name reference: y")
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset(-1)
+ }.should raise_error(IndexError, "index -1 out of matches")
+
+ -> {
+ m.offset(3)
+ }.should raise_error(IndexError, "index 3 out of matches")
+ end
+
+ it "raises TypeError if can't convert argument into Integer" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset([])
+ }.should raise_error(TypeError, "no implicit conversion of Array into Integer")
+ end
end
diff --git a/spec/ruby/core/math/expm1_spec.rb b/spec/ruby/core/math/expm1_spec.rb
new file mode 100644
index 0000000000..5725319abb
--- /dev/null
+++ b/spec/ruby/core/math/expm1_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.expm1" do
+ it "calculates Math.exp(arg) - 1" do
+ Math.expm1(3).should == Math.exp(3) - 1
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.expm1(1.0e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.expm1(1.0e-16).should != 0.0
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.expm1("test") }.should raise_error(TypeError, "can't convert String into Float")
+ end
+
+ it "returns NaN given NaN" do
+ Math.expm1(nan_value).nan?.should be_true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.expm1(nil) }.should raise_error(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.expm1(MathSpecs::Float.new).should be_close(Math::E - 1, TOLERANCE)
+ end
+ end
+
+ describe "Math#expm1" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:expm1, 23.1415).should be_close(11226018483.0012, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb
index 33e7836448..2bf350993e 100644
--- a/spec/ruby/core/math/lgamma_spec.rb
+++ b/spec/ruby/core/math/lgamma_spec.rb
@@ -5,10 +5,8 @@ describe "Math.lgamma" do
Math.lgamma(0).should == [infinity_value, 1]
end
- platform_is_not :windows do
- it "returns [Infinity, 1] when passed -1" do
- Math.lgamma(-1).should == [infinity_value, 1]
- end
+ it "returns [Infinity, ...] when passed -1" do
+ Math.lgamma(-1)[0].should == infinity_value
end
it "returns [Infinity, -1] when passed -0.0" do
@@ -47,8 +45,7 @@ describe "Math.lgamma" do
Math.lgamma(infinity_value).should == [infinity_value, 1]
end
- it "returns [NaN, 1] when passed NaN" do
- Math.lgamma(nan_value)[0].nan?.should be_true
- Math.lgamma(nan_value)[1].should == 1
+ it "returns [NaN, ...] when passed NaN" do
+ Math.lgamma(nan_value)[0].should.nan?
end
end
diff --git a/spec/ruby/core/math/log1p_spec.rb b/spec/ruby/core/math/log1p_spec.rb
new file mode 100644
index 0000000000..216358a3c4
--- /dev/null
+++ b/spec/ruby/core/math/log1p_spec.rb
@@ -0,0 +1,49 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.log1p" do
+ it "calculates Math.log(1 + arg)" do
+ Math.log1p(3).should == Math.log(1 + 3)
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.log1p(1e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.log1p(1e-16).should != 0.0
+ end
+
+ it "raises an Math::DomainError if the argument is less than 1" do
+ -> { Math.log1p(-1-1e-15) }.should raise_error(Math::DomainError, "Numerical argument is out of domain - log1p")
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.log1p("test") }.should raise_error(TypeError, "can't convert String into Float")
+ end
+
+ it "raises a TypeError for numerical values passed as string" do
+ -> { Math.log1p("10") }.should raise_error(TypeError, "can't convert String into Float")
+ end
+
+ it "does not accept a second argument for the base" do
+ -> { Math.log1p(9, 3) }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ end
+
+ it "returns NaN given NaN" do
+ Math.log1p(nan_value).nan?.should be_true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.log1p(nil) }.should raise_error(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.log1p(MathSpecs::Float.new).should be_close(0.6931471805599453, TOLERANCE)
+ end
+ end
+
+ describe "Math#log1p" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:log1p, 4.21).should be_close(1.65057985576528, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/method/owner_spec.rb b/spec/ruby/core/method/owner_spec.rb
index 05422f1697..1cdc4edfa7 100644
--- a/spec/ruby/core/method/owner_spec.rb
+++ b/spec/ruby/core/method/owner_spec.rb
@@ -24,9 +24,7 @@ describe "Method#owner" do
end
end
- ruby_version_is "3.2" do
- it "returns the class on which public was called for a private method in ancestor" do
- MethodSpecs::InheritedMethods::C.new.method(:derp).owner.should == MethodSpecs::InheritedMethods::C
- end
+ it "returns the class on which public was called for a private method in ancestor" do
+ MethodSpecs::InheritedMethods::C.new.method(:derp).owner.should == MethodSpecs::InheritedMethods::C
end
end
diff --git a/spec/ruby/core/method/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb
index 0178a61de6..f1c2523cf0 100644
--- a/spec/ruby/core/method/parameters_spec.rb
+++ b/spec/ruby/core/method/parameters_spec.rb
@@ -233,28 +233,14 @@ describe "Method#parameters" do
m.method(:handled_via_method_missing).parameters.should == [[:rest]]
end
- ruby_version_is '3.2' do
- it "adds rest arg with name * for \"star\" argument" do
- m = MethodSpecs::Methods.new
- m.method(:one_unnamed_splat).parameters.should == [[:rest, :*]]
- end
-
- it "adds keyrest arg with ** as a name for \"double star\" argument" do
- m = MethodSpecs::Methods.new
- m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest, :**]]
- end
+ it "adds rest arg with name * for \"star\" argument" do
+ m = MethodSpecs::Methods.new
+ m.method(:one_unnamed_splat).parameters.should == [[:rest, :*]]
end
- ruby_version_is ''...'3.2' do
- it "adds nameless rest arg for \"star\" argument" do
- m = MethodSpecs::Methods.new
- m.method(:one_unnamed_splat).parameters.should == [[:rest]]
- end
-
- it "adds nameless keyrest arg for \"double star\" argument" do
- m = MethodSpecs::Methods.new
- m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest]]
- end
+ it "adds keyrest arg with ** as a name for \"double star\" argument" do
+ m = MethodSpecs::Methods.new
+ m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest, :**]]
end
it "adds block arg with name & for anonymous block argument" do
diff --git a/spec/ruby/core/method/private_spec.rb b/spec/ruby/core/method/private_spec.rb
index 9b67a77243..e708542b2e 100644
--- a/spec/ruby/core/method/private_spec.rb
+++ b/spec/ruby/core/method/private_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Method#private?" do
- ruby_version_is ""..."3.2" do
- it "returns false when the method is public" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_public_method).private?.should == false
- end
-
- it "returns false when the method is protected" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_protected_method).private?.should == false
- end
-
- it "returns true when the method is private" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_private_method).private?.should == true
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_private_method).should_not.respond_to?(:private?)
- end
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_private_method).should_not.respond_to?(:private?)
end
end
diff --git a/spec/ruby/core/method/protected_spec.rb b/spec/ruby/core/method/protected_spec.rb
index 28c60c7536..f9e422ae3d 100644
--- a/spec/ruby/core/method/protected_spec.rb
+++ b/spec/ruby/core/method/protected_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Method#protected?" do
- ruby_version_is ""..."3.2" do
- it "returns false when the method is public" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_public_method).protected?.should == false
- end
-
- it "returns true when the method is protected" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_protected_method).protected?.should == true
- end
-
- it "returns false when the method is private" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_private_method).protected?.should == false
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_protected_method).should_not.respond_to?(:protected?)
- end
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_protected_method).should_not.respond_to?(:protected?)
end
end
diff --git a/spec/ruby/core/method/public_spec.rb b/spec/ruby/core/method/public_spec.rb
index 4844f4b90b..4cb23f4cf1 100644
--- a/spec/ruby/core/method/public_spec.rb
+++ b/spec/ruby/core/method/public_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Method#public?" do
- ruby_version_is ""..."3.2" do
- it "returns true when the method is public" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_public_method).public?.should == true
- end
-
- it "returns false when the method is protected" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_protected_method).public?.should == false
- end
-
- it "returns false when the method is private" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_private_method).public?.should == false
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = MethodSpecs::Methods.new
- obj.method(:my_public_method).should_not.respond_to?(:public?)
- end
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_public_method).should_not.respond_to?(:public?)
end
end
diff --git a/spec/ruby/core/method/source_location_spec.rb b/spec/ruby/core/method/source_location_spec.rb
index 23d956ebec..87413a2ab6 100644
--- a/spec/ruby/core/method/source_location_spec.rb
+++ b/spec/ruby/core/method/source_location_spec.rb
@@ -109,10 +109,10 @@ describe "Method#source_location" do
eval('def self.m; end', nil, "foo", 100)
end
location = c.method(:m).source_location
- ruby_version_is(""..."3.5") do
+ ruby_version_is(""..."4.1") do
location.should == ["foo", 100]
end
- ruby_version_is("3.5") do
+ ruby_version_is("4.1") do
location.should == ["foo", 100, 0, 100, 15]
end
end
diff --git a/spec/ruby/core/method/unbind_spec.rb b/spec/ruby/core/method/unbind_spec.rb
index bdedd513ce..0b630e4d88 100644
--- a/spec/ruby/core/method/unbind_spec.rb
+++ b/spec/ruby/core/method/unbind_spec.rb
@@ -27,16 +27,8 @@ describe "Method#unbind" do
@string.should =~ /MethodSpecs::MyMod/
end
- ruby_version_is ""..."3.2" do
- it "returns a String containing the Module the method is referenced from" do
- @string.should =~ /MethodSpecs::MySub/
- end
- end
-
- ruby_version_is "3.2" do
- it "returns a String containing the Module the method is referenced from" do
- @string.should =~ /MethodSpecs::MyMod/
- end
+ it "returns a String containing the Module the method is referenced from" do
+ @string.should =~ /MethodSpecs::MyMod/
end
end
diff --git a/spec/ruby/core/module/ancestors_spec.rb b/spec/ruby/core/module/ancestors_spec.rb
index 43ebdb864f..90c26941d1 100644
--- a/spec/ruby/core/module/ancestors_spec.rb
+++ b/spec/ruby/core/module/ancestors_spec.rb
@@ -7,10 +7,17 @@ describe "Module#ancestors" do
ModuleSpecs.ancestors.should == [ModuleSpecs]
ModuleSpecs::Basic.ancestors.should == [ModuleSpecs::Basic]
ModuleSpecs::Super.ancestors.should == [ModuleSpecs::Super, ModuleSpecs::Basic]
- ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
- [ModuleSpecs::Parent, Object, Kernel, BasicObject]
- ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
- [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ if defined?(Ruby::Box) && Ruby::Box.enabled?
+ ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
+ [ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
+ ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
+ [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
+ else
+ ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
+ [ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
+ [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ end
end
it "returns only modules and classes" do
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index 3cdc48f9ba..625d945686 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -603,32 +603,30 @@ describe "Module#autoload" do
end
end
- ruby_version_is "3.2" do
- it "warns once in verbose mode if the constant was defined in a parent scope" do
- ScratchPad.record -> {
- ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
- }
+ it "warns once in verbose mode if the constant was defined in a parent scope" do
+ ScratchPad.record -> {
+ ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
+ }
- module ModuleSpecs
- module Autoload
- autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
- self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb")
- const_defined?(:DeclaredInCurrentDefinedInParent).should == true
-
- -> {
- DeclaredInCurrentDefinedInParent
- }.should complain(
- /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/,
- verbose: true,
- )
-
- -> {
- DeclaredInCurrentDefinedInParent
- }.should_not complain(/.*/, verbose: true)
- self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
- const_defined?(:DeclaredInCurrentDefinedInParent).should == false
- ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
- end
+ module ModuleSpecs
+ module Autoload
+ autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
+ self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb")
+ const_defined?(:DeclaredInCurrentDefinedInParent).should == true
+
+ -> {
+ DeclaredInCurrentDefinedInParent
+ }.should complain(
+ /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/,
+ verbose: true,
+ )
+
+ -> {
+ DeclaredInCurrentDefinedInParent
+ }.should_not complain(/.*/, verbose: true)
+ self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
+ const_defined?(:DeclaredInCurrentDefinedInParent).should == false
+ ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
end
end
end
@@ -720,6 +718,21 @@ describe "Module#autoload" do
end
end
+ it "should trigger the autoload when using `private_constant`" do
+ @remove << :DynClass
+ module ModuleSpecs::Autoload
+ autoload :DynClass, fixture(__FILE__, "autoload_c.rb")
+ private_constant :DynClass
+
+ ScratchPad.recorded.should be_nil
+
+ DynClass::C.new.loaded.should == :dynclass_c
+ ScratchPad.recorded.should == :loaded
+ end
+
+ -> { ModuleSpecs::Autoload::DynClass }.should raise_error(NameError, /private constant/)
+ end
+
# [ruby-core:19127] [ruby-core:29941]
it "does NOT raise a NameError when the autoload file did not define the constant and a module is opened with the same name" do
module ModuleSpecs::Autoload
diff --git a/spec/ruby/core/module/const_added_spec.rb b/spec/ruby/core/module/const_added_spec.rb
index 1b3dad514b..90cd36551a 100644
--- a/spec/ruby/core/module/const_added_spec.rb
+++ b/spec/ruby/core/module/const_added_spec.rb
@@ -3,221 +3,236 @@ require_relative 'fixtures/classes'
require_relative 'fixtures/const_added'
describe "Module#const_added" do
- ruby_version_is "3.2" do
- it "is a private instance method" do
- Module.should have_private_instance_method(:const_added)
+ it "is a private instance method" do
+ Module.should have_private_instance_method(:const_added)
+ end
+
+ it "returns nil in the default implementation" do
+ Module.new do
+ const_added(:TEST).should == nil
end
+ end
+
+ it "for a class defined with the `class` keyword, const_added runs before inherited" do
+ ScratchPad.record []
- it "returns nil in the default implementation" do
- Module.new do
- const_added(:TEST).should == nil
+ mod = Module.new do
+ def self.const_added(_)
+ ScratchPad << :const_added
end
end
- it "is called when a new constant is assigned on self" do
- ScratchPad.record []
-
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
+ parent = Class.new do
+ def self.inherited(_)
+ ScratchPad << :inherited
end
+ end
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- TEST = 1
- RUBY
+ class mod::C < parent; end
- ScratchPad.recorded.should == [:TEST]
- end
+ ScratchPad.recorded.should == [:const_added, :inherited]
+ end
- it "is called when a new constant is assigned on self through const_set" do
- ScratchPad.record []
+ it "the superclass of a class assigned to a constant is set before const_added is called" do
+ ScratchPad.record []
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
+ parent = Class.new do
+ def self.const_added(name)
+ ScratchPad << name
+ ScratchPad << const_get(name).superclass
end
+ end
- mod.const_set(:TEST, 1)
+ class parent::C < parent; end
- ScratchPad.recorded.should == [:TEST]
- end
+ ScratchPad.recorded.should == [:C, parent]
+ end
- it "is called when a new module is defined under self" do
- ScratchPad.record []
+ it "is called when a new constant is assigned on self" do
+ ScratchPad.record []
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
end
+ end
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- module SubModule
- end
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 1
+ RUBY
- module SubModule
- end
- RUBY
+ ScratchPad.recorded.should == [:TEST]
+ end
+
+ it "is called when a new constant is assigned on self through const_set" do
+ ScratchPad.record []
- ScratchPad.recorded.should == [:SubModule]
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
end
- it "is called when a new module is defined under a named module (assigned to a constant)" do
- ScratchPad.record []
+ mod.const_set(:TEST, 1)
- ModuleSpecs::ConstAddedSpecs::NamedModule = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
+ ScratchPad.recorded.should == [:TEST]
+ end
- module self::A
- def self.const_added(name)
- ScratchPad << name
- end
+ it "is called when a new module is defined under self" do
+ ScratchPad.record []
- module self::B
- end
- end
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
end
-
- ScratchPad.recorded.should == [:A, :B]
end
- it "is called when a new class is defined under self" do
- ScratchPad.record []
-
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ module SubModule
end
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- class SubClass
- end
+ module SubModule
+ end
+ RUBY
- class SubClass
- end
- RUBY
+ ScratchPad.recorded.should == [:SubModule]
+ end
- ScratchPad.recorded.should == [:SubClass]
- end
+ it "is called when a new module is defined under a named module (assigned to a constant)" do
+ ScratchPad.record []
- it "is called when a new class is defined under a named module (assigned to a constant)" do
- ScratchPad.record []
+ ModuleSpecs::ConstAddedSpecs::NamedModule = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
- ModuleSpecs::ConstAddedSpecs::NamedModuleB = Module.new do
+ module self::A
def self.const_added(name)
ScratchPad << name
end
- class self::A
- def self.const_added(name)
- ScratchPad << name
- end
-
- class self::B
- end
+ module self::B
end
end
-
- ScratchPad.recorded.should == [:A, :B]
end
- it "is called when an autoload is defined" do
- ScratchPad.record []
+ ScratchPad.recorded.should == [:A, :B]
+ ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModule
+ end
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << name
- end
- end
+ it "is called when a new class is defined under self" do
+ ScratchPad.record []
- mod.autoload :Autoload, "foo"
- ScratchPad.recorded.should == [:Autoload]
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
end
- it "is called with a precise caller location with the line of definition" do
- ScratchPad.record []
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ class SubClass
+ end
- mod = Module.new do
- def self.const_added(name)
- location = caller_locations(1, 1)[0]
- ScratchPad << location.lineno
- end
+ class SubClass
end
+ RUBY
- line = __LINE__
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- TEST = 1
+ ScratchPad.recorded.should == [:SubClass]
+ end
- module SubModule
- end
+ it "is called when a new class is defined under a named module (assigned to a constant)" do
+ ScratchPad.record []
- class SubClass
- end
- RUBY
+ ModuleSpecs::ConstAddedSpecs::NamedModuleB = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
- mod.const_set(:CONST_SET, 1)
+ class self::A
+ def self.const_added(name)
+ ScratchPad << name
+ end
- ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11]
+ class self::B
+ end
+ end
end
- it "is called when the constant is already assigned a value" do
- ScratchPad.record []
+ ScratchPad.recorded.should == [:A, :B]
+ ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModuleB
+ end
- mod = Module.new do
- def self.const_added(name)
- ScratchPad.record const_get(name)
- end
+ it "is called when an autoload is defined" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
end
+ end
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- TEST = 123
- RUBY
+ mod.autoload :Autoload, "foo"
+ ScratchPad.recorded.should == [:Autoload]
+ end
+
+ it "is called with a precise caller location with the line of definition" do
+ ScratchPad.record []
- ScratchPad.recorded.should == 123
+ mod = Module.new do
+ def self.const_added(name)
+ location = caller_locations(1, 1)[0]
+ ScratchPad << location.lineno
+ end
end
- it "records re-definition of existing constants" do
- ScratchPad.record []
+ line = __LINE__
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 1
- mod = Module.new do
- def self.const_added(name)
- ScratchPad << const_get(name)
- end
+ module SubModule
end
- -> {
- mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
- TEST = 123
- TEST = 456
- RUBY
- }.should complain(/warning: already initialized constant .+::TEST/)
+ class SubClass
+ end
+ RUBY
- ScratchPad.recorded.should == [123, 456]
- end
+ mod.const_set(:CONST_SET, 1)
- it "for a class defined with the `class` keyword, const_added runs before inherited" do
- ScratchPad.record []
+ ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11]
+ end
- mod = Module.new do
- def self.const_added(_)
- ScratchPad << :const_added
- end
- end
+ it "is called when the constant is already assigned a value" do
+ ScratchPad.record []
- parent = Class.new do
- def self.inherited(_)
- ScratchPad << :inherited
- end
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad.record const_get(name)
end
+ end
+
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 123
+ RUBY
+
+ ScratchPad.recorded.should == 123
+ end
- class mod::C < parent; end
+ it "records re-definition of existing constants" do
+ ScratchPad.record []
- ScratchPad.recorded.should == [:const_added, :inherited]
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << const_get(name)
+ end
end
+
+ -> {
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 123
+ TEST = 456
+ RUBY
+ }.should complain(/warning: already initialized constant .+::TEST/)
+
+ ScratchPad.recorded.should == [123, 456]
end
end
diff --git a/spec/ruby/core/module/const_source_location_spec.rb b/spec/ruby/core/module/const_source_location_spec.rb
index 06b3b215c2..96649ea10b 100644
--- a/spec/ruby/core/module/const_source_location_spec.rb
+++ b/spec/ruby/core/module/const_source_location_spec.rb
@@ -245,6 +245,14 @@ describe "Module#const_source_location" do
@line = __LINE__ - 1
end
+ before :each do
+ @loaded_features = $".dup
+ end
+
+ after :each do
+ $".replace @loaded_features
+ end
+
it 'returns the autoload location while not resolved' do
ConstantSpecs.const_source_location('CSL_CONST1').should == [__FILE__, @line]
end
@@ -265,6 +273,8 @@ describe "Module#const_source_location" do
ConstantSpecs.const_source_location(:ConstSource).should == autoload_location
ConstantSpecs::ConstSource::LOCATION.should == ConstantSpecs.const_source_location(:ConstSource)
ConstantSpecs::BEFORE_DEFINE_LOCATION.should == autoload_location
+ ConstantSpecs.send :remove_const, :ConstSource
+ ConstantSpecs.send :remove_const, :BEFORE_DEFINE_LOCATION
end
end
end
diff --git a/spec/ruby/core/module/fixtures/classes.rb b/spec/ruby/core/module/fixtures/classes.rb
index a434e7b0b8..964f64c593 100644
--- a/spec/ruby/core/module/fixtures/classes.rb
+++ b/spec/ruby/core/module/fixtures/classes.rb
@@ -1,6 +1,6 @@
module ModuleSpecs
def self.without_test_modules(modules)
- ignore = %w[MSpecRSpecAdapter PP::ObjectMixin ModuleSpecs::IncludedInObject MainSpecs::Module ConstantSpecs::ModuleA]
+ ignore = %w[MSpecRSpecAdapter PP::ObjectMixin MainSpecs::Module ConstantSpecs::ModuleA]
modules.reject { |k| ignore.include?(k.name) }
end
diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb
index a1bfd3a6f5..210918b2e7 100644
--- a/spec/ruby/core/module/include_spec.rb
+++ b/spec/ruby/core/module/include_spec.rb
@@ -51,32 +51,16 @@ describe "Module#include" do
ModuleSpecs::SubclassSpec.send(:remove_const, :AClass)
end
- ruby_version_is ""..."3.2" do
- it "raises ArgumentError when the argument is a refinement" do
- refinement = nil
+ it "raises a TypeError when the argument is a refinement" do
+ refinement = nil
- Module.new do
- refine String do
- refinement = self
- end
+ Module.new do
+ refine String do
+ refinement = self
end
-
- -> { ModuleSpecs::Basic.include(refinement) }.should raise_error(ArgumentError, "refinement module is not allowed")
end
- end
-
- ruby_version_is "3.2" do
- it "raises a TypeError when the argument is a refinement" do
- refinement = nil
- Module.new do
- refine String do
- refinement = self
- end
- end
-
- -> { ModuleSpecs::Basic.include(refinement) }.should raise_error(TypeError, "Cannot include refinement")
- end
+ -> { ModuleSpecs::Basic.include(refinement) }.should raise_error(TypeError, "Cannot include refinement")
end
it "imports constants to modules and classes" do
diff --git a/spec/ruby/core/module/instance_method_spec.rb b/spec/ruby/core/module/instance_method_spec.rb
index 8d006e647e..182cdf5c54 100644
--- a/spec/ruby/core/module/instance_method_spec.rb
+++ b/spec/ruby/core/module/instance_method_spec.rb
@@ -48,11 +48,6 @@ describe "Module#instance_method" do
@mod_um.inspect.should =~ /\bbar\b/
@mod_um.inspect.should =~ /\bModuleSpecs::InstanceMethMod\b/
-
- ruby_version_is ""..."3.2" do
- @child_um.inspect.should =~ /\bModuleSpecs::InstanceMethChild\b/
- @mod_um.inspect.should =~ /\bModuleSpecs::InstanceMethChild\b/
- end
end
it "raises a TypeError if the given name is not a String/Symbol" do
diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb
index b5c1f771f8..d3318e1645 100644
--- a/spec/ruby/core/module/name_spec.rb
+++ b/spec/ruby/core/module/name_spec.rb
@@ -153,45 +153,44 @@ describe "Module#name" do
ModuleSpecs::Anonymous.send(:remove_const, :StoredInMultiplePlaces)
end
- ruby_version_is "3.2" do
- it "is set in #const_added callback when a module defined in the top-level scope" do
- ruby_exe(<<~RUBY, args: "2>&1").chomp.should == "TEST1\nTEST2"
- class Module
- def const_added(name)
- puts const_get(name).name
- end
+ it "is set in #const_added callback when a module defined in the top-level scope" do
+ ruby_exe(<<~RUBY, args: "2>&1").chomp.should == "TEST1\nTEST2"
+ class Module
+ def const_added(name)
+ puts const_get(name).name
end
+ end
- # module with name
- module TEST1
- end
+ # module with name
+ module TEST1
+ end
- # anonymous module
- TEST2 = Module.new
- RUBY
- end
+ # anonymous module
+ TEST2 = Module.new
+ RUBY
+ end
- it "is set in #const_added callback for a nested module when an outer module defined in the top-level scope" do
- ScratchPad.record []
+ it "is set in #const_added callback for a nested module when an outer module defined in the top-level scope" do
+ ScratchPad.record []
- ModuleSpecs::NameSpecs::NamedModule = Module.new do
+ ModuleSpecs::NameSpecs::NamedModule = Module.new do
+ def self.const_added(name)
+ ScratchPad << const_get(name).name
+ end
+
+ module self::A
def self.const_added(name)
ScratchPad << const_get(name).name
end
- module self::A
- def self.const_added(name)
- ScratchPad << const_get(name).name
- end
-
- module self::B
- end
+ module self::B
end
end
-
- ScratchPad.recorded.should.one?(/#<Module.+>::A$/)
- ScratchPad.recorded.should.one?(/#<Module.+>::A::B$/)
end
+
+ ScratchPad.recorded.should.one?(/#<Module.+>::A$/)
+ ScratchPad.recorded.should.one?(/#<Module.+>::A::B$/)
+ ModuleSpecs::NameSpecs.send :remove_const, :NamedModule
end
it "returns a frozen String" do
diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb
index 9508fbf182..71e82c513e 100644
--- a/spec/ruby/core/module/prepend_spec.rb
+++ b/spec/ruby/core/module/prepend_spec.rb
@@ -455,32 +455,16 @@ describe "Module#prepend" do
ModuleSpecs::SubclassSpec.send(:remove_const, :AClass)
end
- ruby_version_is ""..."3.2" do
- it "raises ArgumentError when the argument is a refinement" do
- refinement = nil
+ it "raises a TypeError when the argument is a refinement" do
+ refinement = nil
- Module.new do
- refine String do
- refinement = self
- end
+ Module.new do
+ refine String do
+ refinement = self
end
-
- -> { ModuleSpecs::Basic.prepend(refinement) }.should raise_error(ArgumentError, "refinement module is not allowed")
end
- end
-
- ruby_version_is "3.2" do
- it "raises a TypeError when the argument is a refinement" do
- refinement = nil
- Module.new do
- refine String do
- refinement = self
- end
- end
-
- -> { ModuleSpecs::Basic.prepend(refinement) }.should raise_error(TypeError, "Cannot prepend refinement")
- end
+ -> { ModuleSpecs::Basic.prepend(refinement) }.should raise_error(TypeError, "Cannot prepend refinement")
end
it "imports constants" do
diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb
index 7a5d607c4f..d219b98825 100644
--- a/spec/ruby/core/module/refine_spec.rb
+++ b/spec/ruby/core/module/refine_spec.rb
@@ -243,32 +243,6 @@ describe "Module#refine" do
result.should == "foo from singleton class"
end
- ruby_version_is ""..."3.2" do
- it "looks in the included modules for builtin methods" do
- result = ruby_exe(<<-RUBY)
- a = Module.new do
- def /(other) quo(other) end
- end
-
- refinement = Module.new do
- refine Integer do
- include a
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = 1 / 2
- end
-
- print result.class
- RUBY
-
- result.should == 'Rational'
- end
- end
-
it "looks in later included modules of the refined module first" do
a = Module.new do
def foo
diff --git a/spec/ruby/core/module/refinements_spec.rb b/spec/ruby/core/module/refinements_spec.rb
index 5648fcbd6f..05658a8b0e 100644
--- a/spec/ruby/core/module/refinements_spec.rb
+++ b/spec/ruby/core/module/refinements_spec.rb
@@ -1,45 +1,43 @@
require_relative '../../spec_helper'
describe "Module#refinements" do
- ruby_version_is "3.2" do
- it "returns refinements defined in a module" do
- ScratchPad.record []
-
- m = Module.new do
- refine String do
- ScratchPad << self
- end
-
- refine Array do
- ScratchPad << self
- end
+ it "returns refinements defined in a module" do
+ ScratchPad.record []
+
+ m = Module.new do
+ refine String do
+ ScratchPad << self
end
- m.refinements.sort_by(&:object_id).should == ScratchPad.recorded.sort_by(&:object_id)
+ refine Array do
+ ScratchPad << self
+ end
end
- it "does not return refinements defined in the included module" do
- ScratchPad.record []
+ m.refinements.sort_by(&:object_id).should == ScratchPad.recorded.sort_by(&:object_id)
+ end
- m1 = Module.new do
- refine Integer do
- nil
- end
+ it "does not return refinements defined in the included module" do
+ ScratchPad.record []
+
+ m1 = Module.new do
+ refine Integer do
+ nil
end
+ end
- m2 = Module.new do
- include m1
+ m2 = Module.new do
+ include m1
- refine String do
- ScratchPad << self
- end
+ refine String do
+ ScratchPad << self
end
-
- m2.refinements.should == ScratchPad.recorded
end
- it "returns an empty array if no refinements defined in a module" do
- Module.new.refinements.should == []
- end
+ m2.refinements.should == ScratchPad.recorded
+ end
+
+ it "returns an empty array if no refinements defined in a module" do
+ Module.new.refinements.should == []
end
end
diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb
index aca419f522..652f9f7083 100644
--- a/spec/ruby/core/module/ruby2_keywords_spec.rb
+++ b/spec/ruby/core/module/ruby2_keywords_spec.rb
@@ -76,122 +76,60 @@ describe "Module#ruby2_keywords" do
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
- def splat(*args)
- args.last
- end
-
- def splat1(arg, *args)
- args.last
- end
+ it "makes a copy and unmark the Hash when calling a method taking (*args)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def splat(*args)
+ args.last
+ end
- def proc_call(*args)
- -> *a { a.last }.call(*args)
- end
+ def splat1(arg, *args)
+ args.last
end
- h = { a: 1 }
- args = mark(**h)
- marked = args.last
- Hash.ruby2_keywords_hash?(marked).should == true
-
- 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
-
- 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)
- Hash.ruby2_keywords_hash?(after_usage).should == false
- Hash.ruby2_keywords_hash?(marked).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_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
+ def proc_call(*args)
+ -> *a { a.last }.call(*args)
+ end
end
- end
- 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 splat(*args)
- args.last
- end
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
- def splat1(arg, *args)
- args.last
- end
+ 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
- def proc_call(*args)
- -> *a { a.last }.call(*args)
- end
- end
+ 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)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
- h = { a: 1 }
- args = mark(**h)
- marked = args.last
- Hash.ruby2_keywords_hash?(marked).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
-
- 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
-
- 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
+ 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
it "applies to the underlying method and applies across aliasing" do
@@ -275,7 +213,7 @@ describe "Module#ruby2_keywords" do
it "prints warning when a method accepts keywords" do
obj = Object.new
- def obj.foo(a:, b:) end
+ def obj.foo(*a, b:) end
-> {
obj.singleton_class.class_exec do
@@ -286,7 +224,7 @@ describe "Module#ruby2_keywords" do
it "prints warning when a method accepts keyword splat" do
obj = Object.new
- def obj.foo(**a) end
+ def obj.foo(*a, **b) end
-> {
obj.singleton_class.class_exec do
@@ -294,4 +232,17 @@ describe "Module#ruby2_keywords" do
end
}.should complain(/Skipping set of ruby2_keywords flag for/)
end
+
+ ruby_version_is "4.0" do
+ it "prints warning when a method accepts post arguments" 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
+ end
end
diff --git a/spec/ruby/core/module/set_temporary_name_spec.rb b/spec/ruby/core/module/set_temporary_name_spec.rb
index 12c1c214dd..46605ed675 100644
--- a/spec/ruby/core/module/set_temporary_name_spec.rb
+++ b/spec/ruby/core/module/set_temporary_name_spec.rb
@@ -86,6 +86,7 @@ ruby_version_is "3.3" do
ModuleSpecs::SetTemporaryNameSpec::M = m
m::N.name.should == "ModuleSpecs::SetTemporaryNameSpec::M::N"
+ ModuleSpecs::SetTemporaryNameSpec.send :remove_const, :M
end
it "can update the name when assigned to a constant" do
@@ -108,7 +109,7 @@ ruby_version_is "3.3" do
m.name.should == "fake_name_2"
end
- ruby_bug "#21094", ""..."3.5" do
+ ruby_bug "#21094", ""..."4.0" do
it "also updates a name of a nested module" do
m = Module.new
m::N = Module.new
diff --git a/spec/ruby/core/module/undefined_instance_methods_spec.rb b/spec/ruby/core/module/undefined_instance_methods_spec.rb
index 3be860d053..d33ee93fc1 100644
--- a/spec/ruby/core/module/undefined_instance_methods_spec.rb
+++ b/spec/ruby/core/module/undefined_instance_methods_spec.rb
@@ -2,25 +2,23 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "Module#undefined_instance_methods" do
- ruby_version_is "3.2" do
- it "returns methods undefined in the class" do
- methods = ModuleSpecs::UndefinedInstanceMethods::Parent.undefined_instance_methods
- methods.should == [:undefed_method]
- end
+ it "returns methods undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Parent.undefined_instance_methods
+ methods.should == [:undefed_method]
+ end
- it "returns inherited methods undefined in the class" do
- methods = ModuleSpecs::UndefinedInstanceMethods::Child.undefined_instance_methods
- methods.should include(:parent_method, :another_parent_method)
- end
+ it "returns inherited methods undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Child.undefined_instance_methods
+ methods.should include(:parent_method, :another_parent_method)
+ end
- it "returns methods from an included module that are undefined in the class" do
- methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
- methods.should include(:super_included_method)
- end
+ it "returns methods from an included module that are undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
+ methods.should include(:super_included_method)
+ end
- it "does not returns ancestors undefined methods" do
- methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
- methods.should_not include(:parent_method, :another_parent_method)
- end
+ it "does not returns ancestors undefined methods" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
+ methods.should_not include(:parent_method, :another_parent_method)
end
end
diff --git a/spec/ruby/core/module/used_refinements_spec.rb b/spec/ruby/core/module/used_refinements_spec.rb
index c16cab0e3c..40dd4a444e 100644
--- a/spec/ruby/core/module/used_refinements_spec.rb
+++ b/spec/ruby/core/module/used_refinements_spec.rb
@@ -1,87 +1,85 @@
require_relative '../../spec_helper'
describe "Module.used_refinements" do
- ruby_version_is "3.2" do
- it "returns list of all refinements imported in the current scope" do
- refinement_int = nil
- refinement_str = nil
- ScratchPad.record []
-
- m1 = Module.new do
- refine Integer do
- refinement_int = self
- end
+ it "returns list of all refinements imported in the current scope" do
+ refinement_int = nil
+ refinement_str = nil
+ ScratchPad.record []
+
+ m1 = Module.new do
+ refine Integer do
+ refinement_int = self
end
+ end
- m2 = Module.new do
- refine String do
- refinement_str = self
- end
+ m2 = Module.new do
+ refine String do
+ refinement_str = self
end
+ end
- Module.new do
- using m1
- using m2
+ Module.new do
+ using m1
+ using m2
- Module.used_refinements.each { |r| ScratchPad << r }
- end
-
- ScratchPad.recorded.sort_by(&:object_id).should == [refinement_int, refinement_str].sort_by(&:object_id)
+ Module.used_refinements.each { |r| ScratchPad << r }
end
- it "returns empty array if does not have any refinements imported" do
- used_refinements = nil
+ ScratchPad.recorded.sort_by(&:object_id).should == [refinement_int, refinement_str].sort_by(&:object_id)
+ end
- Module.new do
- used_refinements = Module.used_refinements
- end
+ it "returns empty array if does not have any refinements imported" do
+ used_refinements = nil
- used_refinements.should == []
+ Module.new do
+ used_refinements = Module.used_refinements
end
- it "ignores refinements imported in a module that is included into the current one" do
- used_refinements = nil
+ used_refinements.should == []
+ end
- m1 = Module.new do
- refine Integer do
- nil
- end
- end
+ it "ignores refinements imported in a module that is included into the current one" do
+ used_refinements = nil
- m2 = Module.new do
- using m1
+ m1 = Module.new do
+ refine Integer do
+ nil
end
+ end
- Module.new do
- include m2
+ m2 = Module.new do
+ using m1
+ end
- used_refinements = Module.used_refinements
- end
+ Module.new do
+ include m2
- used_refinements.should == []
+ used_refinements = Module.used_refinements
end
- it "returns refinements even not defined directly in a module refinements are imported from" do
- used_refinements = nil
- ScratchPad.record []
+ used_refinements.should == []
+ end
- m1 = Module.new do
- refine Integer do
- ScratchPad << self
- end
- end
+ it "returns refinements even not defined directly in a module refinements are imported from" do
+ used_refinements = nil
+ ScratchPad.record []
- m2 = Module.new do
- include m1
+ m1 = Module.new do
+ refine Integer do
+ ScratchPad << self
end
+ end
- Module.new do
- using m2
+ m2 = Module.new do
+ include m1
+ end
- used_refinements = Module.used_refinements
- end
+ Module.new do
+ using m2
- used_refinements.should == ScratchPad.recorded
+ used_refinements = Module.used_refinements
end
+
+ used_refinements.should == ScratchPad.recorded
end
end
diff --git a/spec/ruby/core/objectspace/_id2ref_spec.rb b/spec/ruby/core/objectspace/_id2ref_spec.rb
index c088ae2743..1ae3230bdf 100644
--- a/spec/ruby/core/objectspace/_id2ref_spec.rb
+++ b/spec/ruby/core/objectspace/_id2ref_spec.rb
@@ -1,52 +1,65 @@
require_relative '../../spec_helper'
-describe "ObjectSpace._id2ref" do
- it "converts an object id to a reference to the object" do
- s = "I am a string"
- r = ObjectSpace._id2ref(s.object_id)
- r.should == s
+ruby_version_is "4.0" do
+ describe "ObjectSpace._id2ref" do
+ it "is deprecated" do
+ id = nil.object_id
+ -> {
+ ObjectSpace._id2ref(id)
+ }.should complain(/warning: ObjectSpace\._id2ref is deprecated/)
+ end
end
+end
- it "retrieves true by object_id" do
- ObjectSpace._id2ref(true.object_id).should == true
- end
+ruby_version_is ""..."4.0" do
+ describe "ObjectSpace._id2ref" do
+ it "converts an object id to a reference to the object" do
+ s = "I am a string"
+ r = ObjectSpace._id2ref(s.object_id)
+ r.should == s
+ end
- it "retrieves false by object_id" do
- ObjectSpace._id2ref(false.object_id).should == false
- end
+ it "retrieves true by object_id" do
+ ObjectSpace._id2ref(true.object_id).should == true
+ end
- it "retrieves nil by object_id" do
- ObjectSpace._id2ref(nil.object_id).should == nil
- end
+ it "retrieves false by object_id" do
+ ObjectSpace._id2ref(false.object_id).should == false
+ end
- it "retrieves a small Integer by object_id" do
- ObjectSpace._id2ref(1.object_id).should == 1
- ObjectSpace._id2ref((-42).object_id).should == -42
- end
+ it "retrieves nil by object_id" do
+ ObjectSpace._id2ref(nil.object_id).should == nil
+ end
- it "retrieves a large Integer by object_id" do
- obj = 1 << 88
- ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
- end
+ it "retrieves a small Integer by object_id" do
+ ObjectSpace._id2ref(1.object_id).should == 1
+ ObjectSpace._id2ref((-42).object_id).should == -42
+ end
- it "retrieves a Symbol by object_id" do
- ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
- end
+ it "retrieves a large Integer by object_id" do
+ obj = 1 << 88
+ ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
+ end
- it "retrieves a String by object_id" do
- obj = "str"
- ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
- end
+ it "retrieves a Symbol by object_id" do
+ ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
+ end
- it "retrieves a frozen literal String by object_id" do
- ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
- end
+ it "retrieves a String by object_id" do
+ obj = "str"
+ ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
+ end
- it "retrieves an Encoding by object_id" do
- ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
- end
+ it "retrieves a frozen literal String by object_id" do
+ ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
+ end
+
+ it "retrieves an Encoding by object_id" do
+ ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
+ end
- it 'raises RangeError when an object could not be found' do
- proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
+ it 'raises RangeError when an object could not be found' do
+ proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
+ end
end
end
diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb
index 9077e44c34..81ceb91af5 100644
--- a/spec/ruby/core/proc/element_reference_spec.rb
+++ b/spec/ruby/core/proc/element_reference_spec.rb
@@ -17,7 +17,7 @@ describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
it_behaves_like :proc_call_on_proc_or_lambda, :call
end
-describe "Proc#[] with frozen_string_literals" do
+describe "Proc#[] with frozen_string_literal: true/false" do
it "doesn't duplicate frozen strings" do
ProcArefSpecs.aref.frozen?.should be_false
ProcArefSpecs.aref_freeze.frozen?.should be_true
diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb
index 7a2723487d..cf8a8f5b12 100644
--- a/spec/ruby/core/proc/parameters_spec.rb
+++ b/spec/ruby/core/proc/parameters_spec.rb
@@ -20,29 +20,27 @@ describe "Proc#parameters" do
proc {|x| }.parameters.first.first.should == :opt
end
- ruby_version_is "3.2" do
- it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do
- proc {|x| }.parameters(lambda: true).first.first.should == :req
- proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
- end
+ it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do
+ proc {|x| }.parameters(lambda: true).first.first.should == :req
+ proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
+ end
- it "regards named parameters in procs as required if lambda keyword used" do
- proc {|x| }.parameters(lambda: true).first.first.should == :req
- end
+ it "regards named parameters in procs as required if lambda keyword used" do
+ proc {|x| }.parameters(lambda: true).first.first.should == :req
+ end
- it "regards named parameters in lambda as optional if lambda: false keyword used" do
- -> x { }.parameters(lambda: false).first.first.should == :opt
- end
+ it "regards named parameters in lambda as optional if lambda: false keyword used" do
+ -> x { }.parameters(lambda: false).first.first.should == :opt
+ end
- it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do
- proc {|x| }.parameters(lambda: 123).first.first.should == :req
- -> x { }.parameters(lambda: 123).first.first.should == :req
- end
+ it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do
+ proc {|x| }.parameters(lambda: 123).first.first.should == :req
+ -> x { }.parameters(lambda: 123).first.first.should == :req
+ end
- it "ignores the lambda keyword if it is nil" do
- proc {|x|}.parameters(lambda: nil).first.first.should == :opt
- -> x { }.parameters(lambda: nil).first.first.should == :req
- end
+ it "ignores the lambda keyword if it is nil" do
+ proc {|x|}.parameters(lambda: nil).first.first.should == :opt
+ -> x { }.parameters(lambda: nil).first.first.should == :req
end
it "regards optional keyword parameters in procs as optional" do
@@ -110,24 +108,12 @@ describe "Proc#parameters" do
-> x { }.parameters.should == [[:req, :x]]
end
- ruby_version_is '3.2' do
- it "adds rest arg with name * for \"star\" argument" do
- -> * {}.parameters.should == [[:rest, :*]]
- end
-
- it "adds keyrest arg with ** as a name for \"double star\" argument" do
- -> ** {}.parameters.should == [[:keyrest, :**]]
- end
+ it "adds rest arg with name * for \"star\" argument" do
+ -> * {}.parameters.should == [[:rest, :*]]
end
- ruby_version_is ''...'3.2' do
- it "adds nameless rest arg for \"star\" argument" do
- -> * {}.parameters.should == [[:rest]]
- end
-
- it "adds nameless keyrest arg for \"double star\" argument" do
- -> ** {}.parameters.should == [[:keyrest]]
- end
+ it "adds keyrest arg with ** as a name for \"double star\" argument" do
+ -> ** {}.parameters.should == [[:keyrest, :**]]
end
it "adds block arg with name & for anonymous block argument" do
@@ -172,4 +158,18 @@ describe "Proc#parameters" do
it "returns :nokey for **nil parameter" do
proc { |**nil| }.parameters.should == [[:nokey]]
end
+
+ ruby_version_is "3.4"..."4.0" do
+ it "handles the usage of `it` as a parameter" do
+ eval("proc { it }").parameters.should == [[:opt, nil]]
+ eval("lambda { it }").parameters.should == [[:req]]
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "handles the usage of `it` as a parameter" do
+ eval("proc { it }").parameters.should == [[:opt]]
+ eval("lambda { it }").parameters.should == [[:req]]
+ end
+ end
end
diff --git a/spec/ruby/core/proc/ruby2_keywords_spec.rb b/spec/ruby/core/proc/ruby2_keywords_spec.rb
index ab67302231..d7f8f592e1 100644
--- a/spec/ruby/core/proc/ruby2_keywords_spec.rb
+++ b/spec/ruby/core/proc/ruby2_keywords_spec.rb
@@ -39,7 +39,7 @@ describe "Proc#ruby2_keywords" do
end
it "prints warning when a proc accepts keywords" do
- f = -> a:, b: { }
+ f = -> *a, b: { }
-> {
f.ruby2_keywords
@@ -47,10 +47,20 @@ describe "Proc#ruby2_keywords" do
end
it "prints warning when a proc accepts keyword splat" do
- f = -> **a { }
+ f = -> *a, **b { }
-> {
f.ruby2_keywords
}.should complain(/Skipping set of ruby2_keywords flag for/)
end
+
+ ruby_version_is "4.0" do
+ it "prints warning when a proc accepts post arguments" do
+ f = -> *a, b { }
+
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+ end
end
diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb
index 818f5b858e..1266337f94 100644
--- a/spec/ruby/core/proc/shared/dup.rb
+++ b/spec/ruby/core/proc/shared/dup.rb
@@ -8,12 +8,10 @@ describe :proc_dup, shared: true do
a.call.should == b.call
end
- ruby_version_is "3.2" do
- it "returns an instance of subclass" do
- cl = Class.new(Proc)
+ it "returns an instance of subclass" do
+ cl = Class.new(Proc)
- cl.new{}.send(@method).class.should == cl
- end
+ cl.new{}.send(@method).class.should == cl
end
ruby_version_is "3.4" do
diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb
index 484466f577..fd33f21a26 100644
--- a/spec/ruby/core/proc/source_location_spec.rb
+++ b/spec/ruby/core/proc/source_location_spec.rb
@@ -53,15 +53,15 @@ describe "Proc#source_location" do
end
it "works even if the proc was created on the same line" do
- ruby_version_is(""..."3.5") do
+ ruby_version_is(""..."4.1") do
proc { true }.source_location.should == [__FILE__, __LINE__]
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
-> { true }.source_location.should == [__FILE__, __LINE__]
end
- ruby_version_is("3.5") do
+ ruby_version_is("4.1") do
proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19]
Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23]
- -> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17]
+ -> { true }.source_location.should == [__FILE__, __LINE__, 6, __LINE__, 17]
end
end
@@ -94,11 +94,11 @@ describe "Proc#source_location" do
it "works for eval with a given line" do
proc = eval('-> {}', nil, "foo", 100)
location = proc.source_location
- ruby_version_is(""..."3.5") do
+ ruby_version_is(""..."4.1") do
location.should == ["foo", 100]
end
- ruby_version_is("3.5") do
- location.should == ["foo", 100, 2, 100, 5]
+ ruby_version_is("4.1") do
+ location.should == ["foo", 100, 0, 100, 5]
end
end
end
diff --git a/spec/ruby/core/process/_fork_spec.rb b/spec/ruby/core/process/_fork_spec.rb
index 8e907f54bb..e1f45e2656 100644
--- a/spec/ruby/core/process/_fork_spec.rb
+++ b/spec/ruby/core/process/_fork_spec.rb
@@ -5,6 +5,8 @@ describe "Process._fork" do
Process.respond_to?(:_fork).should == Process.respond_to?(:fork)
end
+ # Using respond_to? in a guard here is OK because the correct semantics
+ # are that _fork is implemented if and only if fork is (see above).
guard_not -> { Process.respond_to?(:fork) } do
it "raises a NotImplementedError when called" do
-> { Process._fork }.should raise_error(NotImplementedError)
diff --git a/spec/ruby/core/process/status/bit_and_spec.rb b/spec/ruby/core/process/status/bit_and_spec.rb
index 0e0edb0afa..a805364629 100644
--- a/spec/ruby/core/process/status/bit_and_spec.rb
+++ b/spec/ruby/core/process/status/bit_and_spec.rb
@@ -1,6 +1,6 @@
require_relative '../../../spec_helper'
-ruby_version_is ""..."3.5" do
+ruby_version_is ""..."4.0" do
describe "Process::Status#&" do
it "returns a bitwise and of the integer status of an exited child" do
@@ -17,7 +17,7 @@ ruby_version_is ""..."3.5" do
end
end
- ruby_version_is "3.3"..."3.5" do
+ ruby_version_is "3.3"..."4.0" do
it "raises an ArgumentError if mask is negative" do
suppress_warning do
ruby_exe("exit(0)")
diff --git a/spec/ruby/core/process/status/right_shift_spec.rb b/spec/ruby/core/process/status/right_shift_spec.rb
index a1ab75141a..355aaf4c95 100644
--- a/spec/ruby/core/process/status/right_shift_spec.rb
+++ b/spec/ruby/core/process/status/right_shift_spec.rb
@@ -1,6 +1,6 @@
require_relative '../../../spec_helper'
-ruby_version_is ""..."3.5" do
+ruby_version_is ""..."4.0" do
describe "Process::Status#>>" do
it "returns a right shift of the integer status of an exited child" do
@@ -16,7 +16,7 @@ ruby_version_is ""..."3.5" do
end
end
- ruby_version_is "3.3"..."3.5" do
+ ruby_version_is "3.3"..."4.0" do
it "raises an ArgumentError if shift value is negative" do
suppress_warning do
ruby_exe("exit(0)")
diff --git a/spec/ruby/core/queue/deq_spec.rb b/spec/ruby/core/queue/deq_spec.rb
index f84d4220ea..a2784e6a63 100644
--- a/spec/ruby/core/queue/deq_spec.rb
+++ b/spec/ruby/core/queue/deq_spec.rb
@@ -7,7 +7,5 @@ describe "Queue#deq" do
end
describe "Queue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.deq(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.deq(timeout: v) }
end
diff --git a/spec/ruby/core/queue/pop_spec.rb b/spec/ruby/core/queue/pop_spec.rb
index d344740834..3dff7db242 100644
--- a/spec/ruby/core/queue/pop_spec.rb
+++ b/spec/ruby/core/queue/pop_spec.rb
@@ -7,7 +7,5 @@ describe "Queue#pop" do
end
describe "Queue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.pop(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.pop(timeout: v) }
end
diff --git a/spec/ruby/core/queue/shift_spec.rb b/spec/ruby/core/queue/shift_spec.rb
index 64165e0b61..c105da74b2 100644
--- a/spec/ruby/core/queue/shift_spec.rb
+++ b/spec/ruby/core/queue/shift_spec.rb
@@ -7,7 +7,5 @@ describe "Queue#shift" do
end
describe "Queue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.shift(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.shift(timeout: v) }
end
diff --git a/spec/ruby/core/random/bytes_spec.rb b/spec/ruby/core/random/bytes_spec.rb
index b42dc61234..c9be07cd3f 100644
--- a/spec/ruby/core/random/bytes_spec.rb
+++ b/spec/ruby/core/random/bytes_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/bytes'
diff --git a/spec/ruby/core/random/default_spec.rb b/spec/ruby/core/random/default_spec.rb
index 01d7430df8..9e4845986d 100644
--- a/spec/ruby/core/random/default_spec.rb
+++ b/spec/ruby/core/random/default_spec.rb
@@ -1,35 +1,7 @@
require_relative '../../spec_helper'
describe "Random::DEFAULT" do
- ruby_version_is ''...'3.2' do
- it "returns a random number generator" do
- suppress_warning do
- Random::DEFAULT.should respond_to(:rand)
- end
- end
-
- it "changes seed on reboot" do
- seed1 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
- seed2 = ruby_exe('p Random::DEFAULT.seed', options: '--disable-gems')
- seed1.should != seed2
- end
-
- it "refers to the Random class" do
- suppress_warning do
- Random::DEFAULT.should.equal?(Random)
- end
- end
-
- it "is deprecated" do
- -> {
- Random::DEFAULT.should.equal?(Random)
- }.should complain(/constant Random::DEFAULT is deprecated/)
- end
- end
-
- ruby_version_is '3.2' do
- it "is no longer defined" do
- Random.should_not.const_defined?(:DEFAULT)
- end
+ it "is no longer defined" do
+ Random.should_not.const_defined?(:DEFAULT)
end
end
diff --git a/spec/ruby/core/random/new_spec.rb b/spec/ruby/core/random/new_spec.rb
index 90e2a9d6f2..69210cef03 100644
--- a/spec/ruby/core/random/new_spec.rb
+++ b/spec/ruby/core/random/new_spec.rb
@@ -11,7 +11,7 @@ describe "Random.new" do
it "returns Random instances initialized with different seeds" do
first = Random.new
second = Random.new
- (0..20).map { first.rand } .should_not == (0..20).map { second.rand }
+ (0..20).map { first.rand }.should_not == (0..20).map { second.rand }
end
it "accepts an Integer seed value as an argument" do
diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb
index 65878aaabe..c9b253f0a5 100644
--- a/spec/ruby/core/range/case_compare_spec.rb
+++ b/spec/ruby/core/range/case_compare_spec.rb
@@ -11,7 +11,7 @@ describe "Range#===" do
it_behaves_like :range_cover_and_include, :===
it_behaves_like :range_cover, :===
- ruby_bug "#19533", "3.2"..."3.3" do
+ ruby_bug "#19533", ""..."3.3" do
it "returns true on any value if begin and end are both nil" do
(nil..nil).should === 1
end
diff --git a/spec/ruby/core/range/cover_spec.rb b/spec/ruby/core/range/cover_spec.rb
index eb7cddc967..c05bb50614 100644
--- a/spec/ruby/core/range/cover_spec.rb
+++ b/spec/ruby/core/range/cover_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/cover_and_include'
require_relative 'shared/cover'
diff --git a/spec/ruby/core/range/include_spec.rb b/spec/ruby/core/range/include_spec.rb
index 277de205d1..449e18985b 100644
--- a/spec/ruby/core/range/include_spec.rb
+++ b/spec/ruby/core/range/include_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/cover_and_include'
require_relative 'shared/include'
diff --git a/spec/ruby/core/range/last_spec.rb b/spec/ruby/core/range/last_spec.rb
index 6698686dd5..82b3e2ff53 100644
--- a/spec/ruby/core/range/last_spec.rb
+++ b/spec/ruby/core/range/last_spec.rb
@@ -8,10 +8,8 @@ describe "Range#last" do
(1..5).last(3).should == [3, 4, 5]
end
- ruby_bug '#18994', '2.7'...'3.2' do
- it "returns the specified number if elements for single element inclusive range" do
- (1..1).last(1).should == [1]
- end
+ it "returns the specified number if elements for single element inclusive range" do
+ (1..1).last(1).should == [1]
end
it "returns an empty array for an empty Range" do
diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb
index 8b83f69a5a..09371f5298 100644
--- a/spec/ruby/core/range/max_spec.rb
+++ b/spec/ruby/core/range/max_spec.rb
@@ -55,7 +55,7 @@ describe "Range#max" do
(..1.0).max.should == 1.0
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "raises for an exclusive beginless Integer range" do
-> {
(...1).max
@@ -63,7 +63,7 @@ describe "Range#max" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "returns the end point for exclusive beginless Integer ranges" do
(...1).max.should == 0
end
diff --git a/spec/ruby/core/range/member_spec.rb b/spec/ruby/core/range/member_spec.rb
index ab61f92951..78299ae9e5 100644
--- a/spec/ruby/core/range/member_spec.rb
+++ b/spec/ruby/core/range/member_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/cover_and_include'
require_relative 'shared/include'
diff --git a/spec/ruby/core/range/reverse_each_spec.rb b/spec/ruby/core/range/reverse_each_spec.rb
index b51e04c3ff..56390cc0da 100644
--- a/spec/ruby/core/range/reverse_each_spec.rb
+++ b/spec/ruby/core/range/reverse_each_spec.rb
@@ -88,7 +88,7 @@ ruby_version_is "3.3" do
(1..3).reverse_each.size.should == 3
end
- ruby_bug "#20936", "3.4"..."3.5" do
+ ruby_bug "#20936", "3.4"..."4.0" do
it "returns Infinity when Range size is infinite" do
(..3).reverse_each.size.should == Float::INFINITY
end
diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb
index 0b41a26455..eaefb45942 100644
--- a/spec/ruby/core/range/shared/cover.rb
+++ b/spec/ruby/core/range/shared/cover.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb
index cd2b3621bb..13fc5e1790 100644
--- a/spec/ruby/core/range/shared/cover_and_include.rb
+++ b/spec/ruby/core/range/shared/cover_and_include.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
describe :range_cover_and_include, shared: true do
diff --git a/spec/ruby/core/range/shared/include.rb b/spec/ruby/core/range/shared/include.rb
index c6c5c2becf..15a0e5fb9f 100644
--- a/spec/ruby/core/range/shared/include.rb
+++ b/spec/ruby/core/range/shared/include.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/range/size_spec.rb b/spec/ruby/core/range/size_spec.rb
index a1fe3ce17d..1a3ddd197e 100644
--- a/spec/ruby/core/range/size_spec.rb
+++ b/spec/ruby/core/range/size_spec.rb
@@ -22,16 +22,7 @@ describe "Range#size" do
eval("('z'..)").size.should == nil
end
- ruby_version_is ""..."3.2" do
- 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
- end
-
- ruby_version_is "3.2"..."3.4" do
+ ruby_version_is ""..."3.4" do
it 'returns Float::INFINITY for all beginless ranges if the end is numeric' do
(..1).size.should == Float::INFINITY
(...0.5).size.should == Float::INFINITY
diff --git a/spec/ruby/core/range/to_set_spec.rb b/spec/ruby/core/range/to_set_spec.rb
new file mode 100644
index 0000000000..589c0e9aed
--- /dev/null
+++ b/spec/ruby/core/range/to_set_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+require_relative '../enumerable/fixtures/classes'
+
+describe "Enumerable#to_set" do
+ it "returns a new Set created from self" do
+ (1..4).to_set.should == Set[1, 2, 3, 4]
+ (1...4).to_set.should == Set[1, 2, 3]
+ end
+
+ it "passes down passed blocks" do
+ (1..3).to_set { |x| x * x }.should == Set[1, 4, 9]
+ end
+
+ ruby_version_is "4.0" do
+ it "raises a RangeError if the range is infinite" do
+ -> { (1..).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
+ -> { (1...).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "instantiates an object of provided as the first argument set class" do
+ set = (1..3).to_set(EnumerableSpecs::SetSubclass)
+ set.should be_kind_of(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
+ end
+
+ ruby_version_is "4.0"..."4.1" do
+ it "instantiates an object of provided as the first argument set class and warns" do
+ set = nil
+ proc {
+ set = (1..3).to_set(EnumerableSpecs::SetSubclass)
+ }.should complain(/Enumerable#to_set/)
+ set.should be_kind_of(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
+ end
+
+ ruby_version_is "4.1" do
+ it "does not accept any positional argument" do
+ -> {
+ (1..3).to_set(EnumerableSpecs::SetSubclass)
+ }.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 0)')
+ end
+ end
+
+ it "does not need explicit `require 'set'`" do
+ output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
+ puts (1..3).to_set.to_a.inspect
+ RUBY
+
+ output.chomp.should == "[1, 2, 3]"
+ end
+end
diff --git a/spec/ruby/core/refinement/append_features_spec.rb b/spec/ruby/core/refinement/append_features_spec.rb
index fb84f245bd..f7e5f32bc1 100644
--- a/spec/ruby/core/refinement/append_features_spec.rb
+++ b/spec/ruby/core/refinement/append_features_spec.rb
@@ -1,20 +1,18 @@
require_relative '../../spec_helper'
describe "Refinement#append_features" do
- ruby_version_is "3.2" do
- it "is not defined" do
- Refinement.should_not have_private_instance_method(:append_features)
- end
+ it "is not defined" do
+ Refinement.should_not have_private_instance_method(:append_features)
+ end
- it "is not called by Module#include" do
- c = Class.new
- Module.new do
- refine c do
- called = false
- define_method(:append_features){called = true}
- proc{c.include(self)}.should raise_error(TypeError)
- called.should == false
- end
+ it "is not called by Module#include" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:append_features){called = true}
+ proc{c.include(self)}.should raise_error(TypeError)
+ called.should == false
end
end
end
diff --git a/spec/ruby/core/refinement/extend_object_spec.rb b/spec/ruby/core/refinement/extend_object_spec.rb
index 6c2a0af4f3..4da8b359cc 100644
--- a/spec/ruby/core/refinement/extend_object_spec.rb
+++ b/spec/ruby/core/refinement/extend_object_spec.rb
@@ -1,22 +1,20 @@
require_relative '../../spec_helper'
describe "Refinement#extend_object" do
- ruby_version_is "3.2" do
- it "is not defined" do
- Refinement.should_not have_private_instance_method(:extend_object)
- end
+ it "is not defined" do
+ Refinement.should_not have_private_instance_method(:extend_object)
+ end
- it "is not called by Object#extend" do
- c = Class.new
- Module.new do
- refine c do
- called = false
- define_method(:extend_object) { called = true }
- -> {
- c.extend(self)
- }.should raise_error(TypeError)
- called.should == false
- end
+ it "is not called by Object#extend" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:extend_object) { called = true }
+ -> {
+ c.extend(self)
+ }.should raise_error(TypeError)
+ called.should == false
end
end
end
diff --git a/spec/ruby/core/refinement/include_spec.rb b/spec/ruby/core/refinement/include_spec.rb
index d20ab47e33..57451bd9bc 100644
--- a/spec/ruby/core/refinement/include_spec.rb
+++ b/spec/ruby/core/refinement/include_spec.rb
@@ -1,26 +1,12 @@
require_relative '../../spec_helper'
describe "Refinement#include" do
- ruby_version_is ""..."3.2" do
- it "warns about deprecation" do
- Module.new do
- refine String do
- -> {
- include Module.new
- }.should complain(/warning: Refinement#include is deprecated and will be removed in Ruby 3.2/)
- end
- end
- end
- end
-
- ruby_version_is "3.2" do
- it "raises a TypeError" do
- Module.new do
- refine String do
- -> {
- include Module.new
- }.should raise_error(TypeError, "Refinement#include has been removed")
- end
+ it "raises a TypeError" do
+ Module.new do
+ refine String do
+ -> {
+ include Module.new
+ }.should raise_error(TypeError, "Refinement#include has been removed")
end
end
end
diff --git a/spec/ruby/core/refinement/prepend_features_spec.rb b/spec/ruby/core/refinement/prepend_features_spec.rb
index 9fdea199a2..fbc431bbd2 100644
--- a/spec/ruby/core/refinement/prepend_features_spec.rb
+++ b/spec/ruby/core/refinement/prepend_features_spec.rb
@@ -1,20 +1,18 @@
require_relative '../../spec_helper'
describe "Refinement#prepend_features" do
- ruby_version_is "3.2" do
- it "is not defined" do
- Refinement.should_not have_private_instance_method(:prepend_features)
- end
+ it "is not defined" do
+ Refinement.should_not have_private_instance_method(:prepend_features)
+ end
- it "is not called by Module#prepend" do
- c = Class.new
- Module.new do
- refine c do
- called = false
- define_method(:prepend_features){called = true}
- proc{c.prepend(self)}.should raise_error(TypeError)
- called.should == false
- end
+ it "is not called by Module#prepend" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:prepend_features){called = true}
+ proc{c.prepend(self)}.should raise_error(TypeError)
+ called.should == false
end
end
end
diff --git a/spec/ruby/core/refinement/prepend_spec.rb b/spec/ruby/core/refinement/prepend_spec.rb
index 5d66766689..64cf7cd17f 100644
--- a/spec/ruby/core/refinement/prepend_spec.rb
+++ b/spec/ruby/core/refinement/prepend_spec.rb
@@ -1,26 +1,12 @@
require_relative '../../spec_helper'
describe "Refinement#prepend" do
- ruby_version_is ""..."3.2" do
- it "warns about deprecation" do
- Module.new do
- refine String do
- -> {
- prepend Module.new
- }.should complain(/warning: Refinement#prepend is deprecated and will be removed in Ruby 3.2/)
- end
- end
- end
- end
-
- ruby_version_is "3.2" do
- it "raises a TypeError" do
- Module.new do
- refine String do
- -> {
- prepend Module.new
- }.should raise_error(TypeError, "Refinement#prepend has been removed")
- end
+ it "raises a TypeError" do
+ Module.new do
+ refine String do
+ -> {
+ prepend Module.new
+ }.should raise_error(TypeError, "Refinement#prepend has been removed")
end
end
end
diff --git a/spec/ruby/core/refinement/refined_class_spec.rb b/spec/ruby/core/refinement/refined_class_spec.rb
index acc6e2cb2b..60a58380cc 100644
--- a/spec/ruby/core/refinement/refined_class_spec.rb
+++ b/spec/ruby/core/refinement/refined_class_spec.rb
@@ -2,7 +2,7 @@ require_relative "../../spec_helper"
require_relative 'shared/target'
describe "Refinement#refined_class" do
- ruby_version_is "3.2"..."3.3" do
+ ruby_version_is ""..."3.3" do
it_behaves_like :refinement_target, :refined_class
end
diff --git a/spec/ruby/core/regexp/compile_spec.rb b/spec/ruby/core/regexp/compile_spec.rb
index c41399cfbb..887c8d77dc 100644
--- a/spec/ruby/core/regexp/compile_spec.rb
+++ b/spec/ruby/core/regexp/compile_spec.rb
@@ -14,6 +14,6 @@ describe "Regexp.compile given a Regexp" do
it_behaves_like :regexp_new_regexp, :compile
end
-describe "Regexp.new given a non-String/Regexp" do
+describe "Regexp.compile given a non-String/Regexp" do
it_behaves_like :regexp_new_non_string_or_regexp, :compile
end
diff --git a/spec/ruby/core/regexp/linear_time_spec.rb b/spec/ruby/core/regexp/linear_time_spec.rb
index 4dc436264f..cf9e73c37c 100644
--- a/spec/ruby/core/regexp/linear_time_spec.rb
+++ b/spec/ruby/core/regexp/linear_time_spec.rb
@@ -1,25 +1,33 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Regexp.linear_time?" do
- it "returns true if matching can be done in linear time" do
- Regexp.linear_time?(/a/).should == true
- Regexp.linear_time?('a').should == true
- end
+describe "Regexp.linear_time?" do
+ it "returns true if matching can be done in linear time" do
+ Regexp.linear_time?(/a/).should == true
+ Regexp.linear_time?('a').should == true
+ end
- it "return false if matching can't be done in linear time" do
- Regexp.linear_time?(/(a)\1/).should == false
- Regexp.linear_time?("(a)\\1").should == false
- end
+ it "returns true if matching can be done in linear time for a binary Regexp" do
+ Regexp.linear_time?(/[\x80-\xff]/n).should == true
+ end
- it "accepts flags for string argument" do
- Regexp.linear_time?('a', Regexp::IGNORECASE).should == true
- end
+ it "return false if matching can't be done in linear time" do
+ Regexp.linear_time?(/(a)\1/).should == false
+ Regexp.linear_time?("(a)\\1").should == false
+ end
+
+ it "accepts flags for string argument" do
+ Regexp.linear_time?('a', Regexp::IGNORECASE).should == true
+ end
+
+ it "warns about flags being ignored for regexp arguments" do
+ -> {
+ Regexp.linear_time?(/a/, Regexp::IGNORECASE)
+ }.should complain(/warning: flags ignored/)
+ end
- it "warns about flags being ignored for regexp arguments" do
- -> {
- Regexp.linear_time?(/a/, Regexp::IGNORECASE)
- }.should complain(/warning: flags ignored/)
+ ruby_version_is "3.3" do
+ it "returns true for positive lookarounds" do
+ Regexp.linear_time?(/(?:(?=a*)a)*/).should == true
end
end
end
diff --git a/spec/ruby/core/regexp/new_spec.rb b/spec/ruby/core/regexp/new_spec.rb
index 65f612df55..79210e9a23 100644
--- a/spec/ruby/core/regexp/new_spec.rb
+++ b/spec/ruby/core/regexp/new_spec.rb
@@ -7,11 +7,11 @@ end
describe "Regexp.new given a String" do
it_behaves_like :regexp_new_string, :new
+ it_behaves_like :regexp_new_string_binary, :new
end
describe "Regexp.new given a Regexp" do
it_behaves_like :regexp_new_regexp, :new
- it_behaves_like :regexp_new_string_binary, :new
end
describe "Regexp.new given a non-String/Regexp" do
diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb
index 3ca50d5a47..12c3d7c9c2 100644
--- a/spec/ruby/core/regexp/shared/new.rb
+++ b/spec/ruby/core/regexp/shared/new.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :regexp_new, shared: true do
it "requires one argument and creates a new regular expression object" do
@@ -123,140 +123,67 @@ describe :regexp_new_string, shared: true do
(r.options & Regexp::EXTENDED).should_not == 0
end
- ruby_version_is ""..."3.2" do
- it "does not try to convert the second argument to Integer with #to_int method call" do
- ScratchPad.clear
- obj = Object.new
- def obj.to_int() ScratchPad.record(:called) end
+ it "does not try to convert the second argument to Integer with #to_int method call" do
+ ScratchPad.clear
+ obj = Object.new
+ def obj.to_int() ScratchPad.record(:called) end
+ -> {
Regexp.send(@method, "Hi", obj)
+ }.should complain(/expected true or false as ignorecase/, {verbose: true})
- ScratchPad.recorded.should == nil
- end
- end
-
- ruby_version_is "3.2" do
- it "does not try to convert the second argument to Integer with #to_int method call" do
- ScratchPad.clear
- obj = Object.new
- def obj.to_int() ScratchPad.record(:called) end
-
- -> {
- Regexp.send(@method, "Hi", obj)
- }.should complain(/expected true or false as ignorecase/, {verbose: true})
-
- ScratchPad.recorded.should == nil
- end
+ ScratchPad.recorded.should == nil
end
- ruby_version_is ""..."3.2" do
- it "treats any non-Integer, non-nil, non-false second argument as IGNORECASE" do
+ it "warns any non-Integer, non-nil, non-false second argument" do
+ r = nil
+ -> {
r = Regexp.send(@method, 'Hi', Object.new)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
- end
-
- ruby_version_is "3.2" do
- it "warns any non-Integer, non-nil, non-false second argument" do
- r = nil
- -> {
- r = Regexp.send(@method, 'Hi', Object.new)
- }.should complain(/expected true or false as ignorecase/, {verbose: true})
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "accepts a String of supported flags as the second argument" do
- r = Regexp.send(@method, 'Hi', 'i')
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', 'imx')
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should_not == 0
- end
-
- r = Regexp.send(@method, 'Hi', 'mimi')
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', '')
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "raises an Argument error if the second argument contains unsupported chars" do
- -> { Regexp.send(@method, 'Hi', 'e') }.should raise_error(ArgumentError, "unknown regexp option: e")
- -> { Regexp.send(@method, 'Hi', 'n') }.should raise_error(ArgumentError, "unknown regexp option: n")
- -> { Regexp.send(@method, 'Hi', 's') }.should raise_error(ArgumentError, "unknown regexp option: s")
- -> { Regexp.send(@method, 'Hi', 'u') }.should raise_error(ArgumentError, "unknown regexp option: u")
- -> { Regexp.send(@method, 'Hi', 'j') }.should raise_error(ArgumentError, "unknown regexp option: j")
- -> { Regexp.send(@method, 'Hi', 'mjx') }.should raise_error(ArgumentError, /unknown regexp option: mjx\b/)
+ }.should complain(/expected true or false as ignorecase/, {verbose: true})
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
end
end
- ruby_version_is ""..."3.2" do
- it "ignores the third argument if it is 'e' or 'euc' (case-insensitive)" do
- -> {
- Regexp.send(@method, 'Hi', nil, 'e').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'euc').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'E').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'EUC').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
+ it "accepts a String of supported flags as the second argument" do
+ r = Regexp.send(@method, 'Hi', 'i')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
end
- it "ignores the third argument if it is 's' or 'sjis' (case-insensitive)" do
- -> {
- Regexp.send(@method, 'Hi', nil, 's').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'sjis').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'S').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'SJIS').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
+ r = Regexp.send(@method, 'Hi', 'imx')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should_not == 0
end
- it "ignores the third argument if it is 'u' or 'utf8' (case-insensitive)" do
- -> {
- Regexp.send(@method, 'Hi', nil, 'u').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'utf8').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'U').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'UTF8').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
+ r = Regexp.send(@method, 'Hi', 'mimi')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
end
- it "uses US_ASCII encoding if third argument is 'n' or 'none' (case insensitive) and only ascii characters" do
- Regexp.send(@method, 'Hi', nil, 'n').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'none').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'N').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'NONE').encoding.should == Encoding::US_ASCII
+ r = Regexp.send(@method, 'Hi', '')
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
end
+ end
- it "uses ASCII_8BIT encoding if third argument is 'n' or 'none' (case insensitive) and non-ascii characters" do
- a = "(?:[\x8E\xA1-\xFE])"
- str = "\A(?:#{a}|x*)\z"
-
- Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::BINARY
- Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::BINARY
- Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::BINARY
- Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::BINARY
- end
+ it "raises an Argument error if the second argument contains unsupported chars" do
+ -> { Regexp.send(@method, 'Hi', 'e') }.should raise_error(ArgumentError, "unknown regexp option: e")
+ -> { Regexp.send(@method, 'Hi', 'n') }.should raise_error(ArgumentError, "unknown regexp option: n")
+ -> { Regexp.send(@method, 'Hi', 's') }.should raise_error(ArgumentError, "unknown regexp option: s")
+ -> { Regexp.send(@method, 'Hi', 'u') }.should raise_error(ArgumentError, "unknown regexp option: u")
+ -> { Regexp.send(@method, 'Hi', 'j') }.should raise_error(ArgumentError, "unknown regexp option: j")
+ -> { Regexp.send(@method, 'Hi', 'mjx') }.should raise_error(ArgumentError, /unknown regexp option: mjx\b/)
end
describe "with escaped characters" do
@@ -268,190 +195,14 @@ describe :regexp_new_string, shared: true do
-> { Regexp.send(@method, "\\\\") }.should_not raise_error(RegexpError)
end
- it "accepts a backspace followed by a character" do
+ it "accepts a backspace followed by a non-special character" do
Regexp.send(@method, "\\N").should == /#{"\x5c"+"N"}/
end
- it "accepts a one-digit octal value" do
- Regexp.send(@method, "\0").should == /#{"\x00"}/
- end
-
- it "accepts a two-digit octal value" do
- Regexp.send(@method, "\11").should == /#{"\x09"}/
- end
-
- it "accepts a one-digit hexadecimal value" do
- Regexp.send(@method, "\x9n").should == /#{"\x09n"}/
- end
-
- it "accepts a two-digit hexadecimal value" do
- Regexp.send(@method, "\x23").should == /#{"\x23"}/
- end
-
- it "interprets a digit following a two-digit hexadecimal value as a character" do
- Regexp.send(@method, "\x420").should == /#{"\x420"}/
- end
-
it "raises a RegexpError if \\x is not followed by any hexadecimal digits" do
-> { Regexp.send(@method, "\\" + "xn") }.should raise_error(RegexpError, Regexp.new(Regexp.escape("invalid hex escape: /\\xn/")))
end
- it "accepts an escaped string interpolation" do
- Regexp.send(@method, "\#{abc}").should == /#{"\#{abc}"}/
- end
-
- it "accepts '\\n'" do
- Regexp.send(@method, "\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\t'" do
- Regexp.send(@method, "\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\r'" do
- Regexp.send(@method, "\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\f'" do
- Regexp.send(@method, "\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\v'" do
- Regexp.send(@method, "\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\a'" do
- Regexp.send(@method, "\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\e'" do
- Regexp.send(@method, "\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\C-\\n'" do
- Regexp.send(@method, "\C-\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\C-\\t'" do
- Regexp.send(@method, "\C-\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\C-\\r'" do
- Regexp.send(@method, "\C-\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\C-\\f'" do
- Regexp.send(@method, "\C-\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\C-\\v'" do
- Regexp.send(@method, "\C-\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\C-\\a'" do
- Regexp.send(@method, "\C-\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\C-\\e'" do
- Regexp.send(@method, "\C-\e").should == /#{"\x1b"}/
- end
-
- it "accepts multiple consecutive '\\' characters" do
- Regexp.send(@method, "\\\\\\N").should == /#{"\\\\\\"+"N"}/
- end
-
- it "accepts characters and escaped octal digits" do
- Regexp.send(@method, "abc\076").should == /#{"abc\x3e"}/
- end
-
- it "accepts escaped octal digits and characters" do
- Regexp.send(@method, "\076abc").should == /#{"\x3eabc"}/
- end
-
- it "accepts characters and escaped hexadecimal digits" do
- Regexp.send(@method, "abc\x42").should == /#{"abc\x42"}/
- end
-
- it "accepts escaped hexadecimal digits and characters" do
- Regexp.send(@method, "\x3eabc").should == /#{"\x3eabc"}/
- end
-
- it "accepts escaped hexadecimal and octal digits" do
- Regexp.send(@method, "\061\x42").should == /#{"\x31\x42"}/
- end
-
- it "accepts \\u{H} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{f}").should == /#{"\x0f"}/
- end
-
- it "accepts \\u{HH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{7f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{07f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{0000}").should == /#{"\x00"}/
- end
-
- it "accepts \\u{HHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{00001}").should == /#{"\x01"}/
- end
-
- it "accepts \\u{HHHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{000000}").should == /#{"\x00"}/
- end
-
- it "accepts characters followed by \\u{HHHH}" do
- Regexp.send(@method, "abc\u{3042}").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\u{HHHH} followed by characters" do
- Regexp.send(@method, "\u{3042}abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\x42\u{3042}").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\056\u{3042}").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\u{HHHH}" do
- Regexp.send(@method, "\056\x42\u{3042}\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "accepts \\uHHHH for a single Unicode codepoint" do
- Regexp.send(@method, "\u3042").should == /#{"\u3042"}/
- end
-
- it "accepts characters followed by \\uHHHH" do
- Regexp.send(@method, "abc\u3042").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\uHHHH followed by characters" do
- Regexp.send(@method, "\u3042abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\uHHHH" do
- Regexp.send(@method, "\x42\u3042").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\uHHHH" do
- Regexp.send(@method, "\056\u3042").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\uHHHH" do
- Regexp.send(@method, "\056\x42\u3042\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "accepts a multiple byte character which need not be escaped" do
- Regexp.send(@method, "\§").should == /#{"§"}/
- end
-
it "raises a RegexpError if less than four digits are given for \\uHHHH" do
-> { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError, Regexp.new(Regexp.escape("invalid Unicode escape: /\\u304/")))
end
@@ -506,69 +257,6 @@ end
describe :regexp_new_string_binary, shared: true do
describe "with escaped characters" do
- it "accepts a three-digit octal value" do
- Regexp.send(@method, "\315").should == /#{"\xcd"}/
- end
-
- it "interprets a digit following a three-digit octal value as a character" do
- Regexp.send(@method, "\3762").should == /#{"\xfe2"}/
- end
-
- it "accepts '\\M-\\n'" do
- Regexp.send(@method, "\M-\n").should == /#{"\x8a"}/
- end
-
- it "accepts '\\M-\\t'" do
- Regexp.send(@method, "\M-\t").should == /#{"\x89"}/
- end
-
- it "accepts '\\M-\\r'" do
- Regexp.send(@method, "\M-\r").should == /#{"\x8d"}/
- end
-
- it "accepts '\\M-\\f'" do
- Regexp.send(@method, "\M-\f").should == /#{"\x8c"}/
- end
-
- it "accepts '\\M-\\v'" do
- Regexp.send(@method, "\M-\v").should == /#{"\x8b"}/
- end
-
- it "accepts '\\M-\\a'" do
- Regexp.send(@method, "\M-\a").should == /#{"\x87"}/
- end
-
- it "accepts '\\M-\\e'" do
- Regexp.send(@method, "\M-\e").should == /#{"\x9b"}/
- end
-
- it "accepts '\\M-\\C-\\n'" do
- Regexp.send(@method, "\M-\C-\n").should == /#{"\x8a"}/
- end
-
- it "accepts '\\M-\\C-\\t'" do
- Regexp.send(@method, "\M-\C-\t").should == /#{"\x89"}/
- end
-
- it "accepts '\\M-\\C-\\r'" do
- Regexp.send(@method, "\M-\C-\r").should == /#{"\x8d"}/
- end
-
- it "accepts '\\M-\\C-\\f'" do
- Regexp.send(@method, "\M-\C-\f").should == /#{"\x8c"}/
- end
-
- it "accepts '\\M-\\C-\\v'" do
- Regexp.send(@method, "\M-\C-\v").should == /#{"\x8b"}/
- end
-
- it "accepts '\\M-\\C-\\a'" do
- Regexp.send(@method, "\M-\C-\a").should == /#{"\x87"}/
- end
-
- it "accepts '\\M-\\C-\\e'" do
- Regexp.send(@method, "\M-\C-\e").should == /#{"\x9b"}/
- end
end
end
@@ -623,11 +311,5 @@ describe :regexp_new_regexp, shared: true do
it "sets the encoding to US-ASCII if the Regexp literal has the 'n' option and the source String is ASCII only" do
Regexp.send(@method, /Hi/n).encoding.should == Encoding::US_ASCII
end
-
- ruby_version_is ''...'3.2' do
- it "sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only" do
- Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::BINARY
- end
- end
end
end
diff --git a/spec/ruby/core/regexp/shared/quote.rb b/spec/ruby/core/regexp/shared/quote.rb
index 48179444f0..3f46a18b5b 100644
--- a/spec/ruby/core/regexp/shared/quote.rb
+++ b/spec/ruby/core/regexp/shared/quote.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :regexp_quote, shared: true do
it "escapes any characters with special meaning in a regular expression" do
diff --git a/spec/ruby/core/regexp/timeout_spec.rb b/spec/ruby/core/regexp/timeout_spec.rb
index 6fce261814..c64103c82c 100644
--- a/spec/ruby/core/regexp/timeout_spec.rb
+++ b/spec/ruby/core/regexp/timeout_spec.rb
@@ -1,35 +1,33 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Regexp.timeout" do
- after :each do
- Regexp.timeout = nil
- end
+describe "Regexp.timeout" do
+ after :each do
+ Regexp.timeout = nil
+ end
- it "returns global timeout" do
- Regexp.timeout = 3
- Regexp.timeout.should == 3
- end
+ it "returns global timeout" do
+ Regexp.timeout = 3
+ Regexp.timeout.should == 3
+ end
- it "raises Regexp::TimeoutError after global timeout elapsed" do
- Regexp.timeout = 0.001
- Regexp.timeout.should == 0.001
+ it "raises Regexp::TimeoutError after global timeout elapsed" do
+ Regexp.timeout = 0.001
+ Regexp.timeout.should == 0.001
- -> {
- # A typical ReDoS case
- /^(a*)*$/ =~ "a" * 1000000 + "x"
- }.should raise_error(Regexp::TimeoutError, "regexp match timeout")
- end
+ -> {
+ # A typical ReDoS case
+ /^(a*)*$/ =~ "a" * 1000000 + "x"
+ }.should raise_error(Regexp::TimeoutError, "regexp match timeout")
+ end
- it "raises Regexp::TimeoutError after timeout keyword value elapsed" do
- Regexp.timeout = 3 # This should be ignored
- Regexp.timeout.should == 3
+ it "raises Regexp::TimeoutError after timeout keyword value elapsed" do
+ Regexp.timeout = 3 # This should be ignored
+ Regexp.timeout.should == 3
- re = Regexp.new("^a*b?a*$", timeout: 0.001)
+ re = Regexp.new("^a*b?a*$", timeout: 0.001)
- -> {
- re =~ "a" * 1000000 + "x"
- }.should raise_error(Regexp::TimeoutError, "regexp match timeout")
- end
+ -> {
+ re =~ "a" * 1000000 + "x"
+ }.should raise_error(Regexp::TimeoutError, "regexp match timeout")
end
end
diff --git a/spec/ruby/library/set/add_spec.rb b/spec/ruby/core/set/add_spec.rb
index 68356cc111..0fe1a0926c 100644
--- a/spec/ruby/library/set/add_spec.rb
+++ b/spec/ruby/core/set/add_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/add'
describe "Set#add" do
@@ -24,4 +23,12 @@ describe "Set#add?" do
@set.add?("cat")
@set.add?("cat").should be_nil
end
+
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b, :c, :d, :e, :f]
+ set.each do |_m|
+ -> { set << 1 }.should raise_error(RuntimeError, /iteration/)
+ end
+ set.should == Set[:a, :b, :c, :d, :e, :f]
+ end
end
diff --git a/spec/ruby/library/set/append_spec.rb b/spec/ruby/core/set/append_spec.rb
index 8b3498b779..82d34d9130 100644
--- a/spec/ruby/library/set/append_spec.rb
+++ b/spec/ruby/core/set/append_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/add'
describe "Set#<<" do
diff --git a/spec/ruby/library/set/case_compare_spec.rb b/spec/ruby/core/set/case_compare_spec.rb
index 70d392a27d..3781b1b963 100644
--- a/spec/ruby/library/set/case_compare_spec.rb
+++ b/spec/ruby/core/set/case_compare_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/include'
-require 'set'
describe "Set#===" do
it_behaves_like :set_include, :===
diff --git a/spec/ruby/library/set/case_equality_spec.rb b/spec/ruby/core/set/case_equality_spec.rb
index 10cbfd380a..19c1fb6b9c 100644
--- a/spec/ruby/library/set/case_equality_spec.rb
+++ b/spec/ruby/core/set/case_equality_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/include'
-require 'set'
describe "Set#===" do
it_behaves_like :set_include, :===
diff --git a/spec/ruby/library/set/classify_spec.rb b/spec/ruby/core/set/classify_spec.rb
index ec600c91d6..d86ea2722d 100644
--- a/spec/ruby/library/set/classify_spec.rb
+++ b/spec/ruby/core/set/classify_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#classify" do
before :each do
diff --git a/spec/ruby/library/set/clear_spec.rb b/spec/ruby/core/set/clear_spec.rb
index 2b1c9c5b5a..ebeac211d3 100644
--- a/spec/ruby/library/set/clear_spec.rb
+++ b/spec/ruby/core/set/clear_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#clear" do
before :each do
diff --git a/spec/ruby/library/set/collect_spec.rb b/spec/ruby/core/set/collect_spec.rb
index f8813a9331..d186f1a0d9 100644
--- a/spec/ruby/library/set/collect_spec.rb
+++ b/spec/ruby/core/set/collect_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/collect'
describe "Set#collect!" do
diff --git a/spec/ruby/library/set/compare_by_identity_spec.rb b/spec/ruby/core/set/compare_by_identity_spec.rb
index 602d1e758e..238dc117a6 100644
--- a/spec/ruby/library/set/compare_by_identity_spec.rb
+++ b/spec/ruby/core/set/compare_by_identity_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#compare_by_identity" do
it "compares its members by identity" do
@@ -91,11 +90,22 @@ describe "Set#compare_by_identity" do
set.to_a.sort.should == [a1, a2].sort
end
- it "raises a FrozenError on frozen sets" do
- set = Set.new.freeze
- -> {
- set.compare_by_identity
- }.should raise_error(FrozenError, /frozen Hash/)
+ ruby_version_is "4.0" do
+ it "raises a FrozenError on frozen sets" do
+ set = Set.new.freeze
+ -> {
+ set.compare_by_identity
+ }.should raise_error(FrozenError, /can't modify frozen Set: (#<)?Set(\[|: {)[\]}]>?/)
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "raises a FrozenError on frozen sets" do
+ set = Set.new.freeze
+ -> {
+ set.compare_by_identity
+ }.should raise_error(FrozenError, /frozen Hash/)
+ end
end
it "persists over #dups" do
diff --git a/spec/ruby/library/set/comparison_spec.rb b/spec/ruby/core/set/comparison_spec.rb
index ddcfbae0af..62059b70b3 100644
--- a/spec/ruby/library/set/comparison_spec.rb
+++ b/spec/ruby/core/set/comparison_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#<=>" do
it "returns 0 if the sets are equal" do
diff --git a/spec/ruby/library/set/constructor_spec.rb b/spec/ruby/core/set/constructor_spec.rb
index bb84861514..365081ad39 100644
--- a/spec/ruby/library/set/constructor_spec.rb
+++ b/spec/ruby/core/set/constructor_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set[]" do
it "returns a new Set populated with the passed Objects" do
diff --git a/spec/ruby/library/set/delete_if_spec.rb b/spec/ruby/core/set/delete_if_spec.rb
index 33caeeaab7..beda73a5e5 100644
--- a/spec/ruby/library/set/delete_if_spec.rb
+++ b/spec/ruby/core/set/delete_if_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#delete_if" do
before :each do
diff --git a/spec/ruby/library/set/delete_spec.rb b/spec/ruby/core/set/delete_spec.rb
index b12524384a..a2543ecbee 100644
--- a/spec/ruby/library/set/delete_spec.rb
+++ b/spec/ruby/core/set/delete_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#delete" do
before :each do
diff --git a/spec/ruby/library/set/difference_spec.rb b/spec/ruby/core/set/difference_spec.rb
index 422f2ed3c7..149f946592 100644
--- a/spec/ruby/library/set/difference_spec.rb
+++ b/spec/ruby/core/set/difference_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/difference'
describe "Set#difference" do
diff --git a/spec/ruby/library/set/disjoint_spec.rb b/spec/ruby/core/set/disjoint_spec.rb
index ea3b141455..89a3c4b157 100644
--- a/spec/ruby/library/set/disjoint_spec.rb
+++ b/spec/ruby/core/set/disjoint_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
describe "Set#disjoint?" do
it "returns false when two Sets have at least one element in common" do
diff --git a/spec/ruby/library/set/divide_spec.rb b/spec/ruby/core/set/divide_spec.rb
index 998a1b292c..c6c6003e99 100644
--- a/spec/ruby/library/set/divide_spec.rb
+++ b/spec/ruby/core/set/divide_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#divide" do
it "divides self into a set of subsets based on the blocks return values" do
@@ -26,10 +25,20 @@ describe "Set#divide when passed a block with an arity of 2" do
set.map{ |x| x.to_a.sort }.sort.should == [[1], [3, 4], [6], [9, 10, 11]]
end
- it "yields each two Object to the block" do
- ret = []
- Set[1, 2].divide { |x, y| ret << [x, y] }
- ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]]
+ ruby_version_is "4.0" do
+ it "yields each two Object to the block" do
+ ret = []
+ Set[1, 2].divide { |x, y| ret << [x, y] }
+ ret.sort.should == [[1, 2], [2, 1]]
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "yields each two Object to the block" do
+ ret = []
+ Set[1, 2].divide { |x, y| ret << [x, y] }
+ ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]]
+ end
end
it "returns an enumerator when not passed a block" do
diff --git a/spec/ruby/library/set/each_spec.rb b/spec/ruby/core/set/each_spec.rb
index 44e185a4da..3d9cdc2d46 100644
--- a/spec/ruby/library/set/each_spec.rb
+++ b/spec/ruby/core/set/each_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#each" do
before :each do
diff --git a/spec/ruby/library/set/empty_spec.rb b/spec/ruby/core/set/empty_spec.rb
index 1789a664c7..4b55658e20 100644
--- a/spec/ruby/library/set/empty_spec.rb
+++ b/spec/ruby/core/set/empty_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#empty?" do
it "returns true if self is empty" do
diff --git a/spec/ruby/library/set/enumerable/to_set_spec.rb b/spec/ruby/core/set/enumerable/to_set_spec.rb
index b2d850515b..f139e1c025 100644
--- a/spec/ruby/library/set/enumerable/to_set_spec.rb
+++ b/spec/ruby/core/set/enumerable/to_set_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../../spec_helper'
-require 'set'
describe "Enumerable#to_set" do
it "returns a new Set created from self" do
diff --git a/spec/ruby/library/set/eql_spec.rb b/spec/ruby/core/set/eql_spec.rb
index dd8e633775..4ad5c3aa5a 100644
--- a/spec/ruby/library/set/eql_spec.rb
+++ b/spec/ruby/core/set/eql_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#eql?" do
it "returns true when the passed argument is a Set and contains the same elements" do
diff --git a/spec/ruby/library/set/equal_value_spec.rb b/spec/ruby/core/set/equal_value_spec.rb
index f5b5f790c0..721a79a3f1 100644
--- a/spec/ruby/library/set/equal_value_spec.rb
+++ b/spec/ruby/core/set/equal_value_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
describe "Set#==" do
it "returns true when the passed Object is a Set and self and the Object contain the same elements" do
@@ -25,9 +24,11 @@ describe "Set#==" do
set1.should == set2
end
- context "when comparing to a Set-like object" do
- it "returns true when a Set and a Set-like object contain the same elements" do
- Set[1, 2, 3].should == SetSpecs::SetLike.new([1, 2, 3])
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true when a Set and a Set-like object contain the same elements" do
+ Set[1, 2, 3].should == SetSpecs::SetLike.new([1, 2, 3])
+ end
end
end
end
diff --git a/spec/ruby/library/set/exclusion_spec.rb b/spec/ruby/core/set/exclusion_spec.rb
index 5bc4b5a2bf..bbc29afa95 100644
--- a/spec/ruby/library/set/exclusion_spec.rb
+++ b/spec/ruby/core/set/exclusion_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#^" do
before :each do
diff --git a/spec/ruby/library/set/filter_spec.rb b/spec/ruby/core/set/filter_spec.rb
index 779254ad68..779254ad68 100644
--- a/spec/ruby/library/set/filter_spec.rb
+++ b/spec/ruby/core/set/filter_spec.rb
diff --git a/spec/ruby/library/set/fixtures/set_like.rb b/spec/ruby/core/set/fixtures/set_like.rb
index 46f61a451e..86dec2ed52 100644
--- a/spec/ruby/library/set/fixtures/set_like.rb
+++ b/spec/ruby/core/set/fixtures/set_like.rb
@@ -1,4 +1,3 @@
-require 'set'
module SetSpecs
# This class is used to test the interaction of "Set-like" objects with real Sets
diff --git a/spec/ruby/core/set/flatten_merge_spec.rb b/spec/ruby/core/set/flatten_merge_spec.rb
new file mode 100644
index 0000000000..13cedeead9
--- /dev/null
+++ b/spec/ruby/core/set/flatten_merge_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+describe "Set#flatten_merge" do
+ ruby_version_is ""..."4.0" do
+ it "is protected" do
+ Set.should have_protected_instance_method("flatten_merge")
+ end
+
+ it "flattens the passed Set and merges it into self" do
+ set1 = Set[1, 2]
+ set2 = Set[3, 4, Set[5, 6]]
+
+ set1.send(:flatten_merge, set2).should == Set[1, 2, 3, 4, 5, 6]
+ end
+
+ it "raises an ArgumentError when trying to flatten a recursive Set" do
+ set1 = Set[1, 2, 3]
+ set2 = Set[5, 6, 7]
+ set2 << set2
+
+ -> { set1.send(:flatten_merge, set2) }.should raise_error(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/library/set/flatten_spec.rb b/spec/ruby/core/set/flatten_spec.rb
index 51b58d6439..f2cb3dfa52 100644
--- a/spec/ruby/library/set/flatten_spec.rb
+++ b/spec/ruby/core/set/flatten_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
describe "Set#flatten" do
@@ -17,9 +16,11 @@ describe "Set#flatten" do
-> { set.flatten }.should raise_error(ArgumentError)
end
- context "when Set contains a Set-like object" do
- it "returns a copy of self with each included Set-like object flattened" do
- Set[SetSpecs::SetLike.new([1])].flatten.should == Set[1]
+ ruby_version_is ""..."4.0" do
+ context "when Set contains a Set-like object" do
+ it "returns a copy of self with each included Set-like object flattened" do
+ Set[SetSpecs::SetLike.new([1])].flatten.should == Set[1]
+ end
end
end
end
@@ -47,9 +48,11 @@ describe "Set#flatten!" do
end
version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do
- context "when Set contains a Set-like object" do
- it "flattens self, including Set-like objects" do
- Set[SetSpecs::SetLike.new([1])].flatten!.should == Set[1]
+ ruby_version_is ""..."4.0" do
+ context "when Set contains a Set-like object" do
+ it "flattens self, including Set-like objects" do
+ Set[SetSpecs::SetLike.new([1])].flatten!.should == Set[1]
+ end
end
end
end
diff --git a/spec/ruby/library/set/hash_spec.rb b/spec/ruby/core/set/hash_spec.rb
index c5bab73931..63a0aa66a5 100644
--- a/spec/ruby/library/set/hash_spec.rb
+++ b/spec/ruby/core/set/hash_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#hash" do
it "is static" do
@@ -11,8 +10,10 @@ describe "Set#hash" do
Set[1, 2, 3].hash.should_not == Set[:a, "b", ?c].hash
end
- # see https://github.com/jruby/jruby/issues/8393
- it "is equal to nil.hash for an uninitialized Set" do
- Set.allocate.hash.should == nil.hash
+ ruby_version_is ""..."4.0" do
+ # see https://github.com/jruby/jruby/issues/8393
+ it "is equal to nil.hash for an uninitialized Set" do
+ Set.allocate.hash.should == nil.hash
+ end
end
end
diff --git a/spec/ruby/library/set/include_spec.rb b/spec/ruby/core/set/include_spec.rb
index 68532d9a04..dd33bbc3bd 100644
--- a/spec/ruby/library/set/include_spec.rb
+++ b/spec/ruby/core/set/include_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/include'
-require 'set'
describe "Set#include?" do
it_behaves_like :set_include, :include?
diff --git a/spec/ruby/library/set/initialize_clone_spec.rb b/spec/ruby/core/set/initialize_clone_spec.rb
index bda42cd6e8..13abb7ee4e 100644
--- a/spec/ruby/library/set/initialize_clone_spec.rb
+++ b/spec/ruby/core/set/initialize_clone_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#initialize_clone" do
# See https://bugs.ruby-lang.org/issues/14266
diff --git a/spec/ruby/library/set/initialize_spec.rb b/spec/ruby/core/set/initialize_spec.rb
index 76ebc0a20a..ad9e1bd8c9 100644
--- a/spec/ruby/library/set/initialize_spec.rb
+++ b/spec/ruby/core/set/initialize_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#initialize" do
it "is private" do
diff --git a/spec/ruby/library/set/inspect_spec.rb b/spec/ruby/core/set/inspect_spec.rb
index 4060c63b95..0dcce83eb6 100644
--- a/spec/ruby/library/set/inspect_spec.rb
+++ b/spec/ruby/core/set/inspect_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/inspect'
-require 'set'
describe "Set#inspect" do
it_behaves_like :set_inspect, :inspect
diff --git a/spec/ruby/library/set/intersect_spec.rb b/spec/ruby/core/set/intersect_spec.rb
index e60f06db94..0736dea5fd 100644
--- a/spec/ruby/library/set/intersect_spec.rb
+++ b/spec/ruby/core/set/intersect_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
describe "Set#intersect?" do
it "returns true when two Sets have at least one element in common" do
diff --git a/spec/ruby/library/set/intersection_spec.rb b/spec/ruby/core/set/intersection_spec.rb
index 792c2d8f07..136b886775 100644
--- a/spec/ruby/library/set/intersection_spec.rb
+++ b/spec/ruby/core/set/intersection_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/intersection'
-require 'set'
describe "Set#intersection" do
it_behaves_like :set_intersection, :intersection
diff --git a/spec/ruby/library/set/join_spec.rb b/spec/ruby/core/set/join_spec.rb
index 3f511a84e4..1c1e8a8af8 100644
--- a/spec/ruby/library/set/join_spec.rb
+++ b/spec/ruby/core/set/join_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#join" do
it "returns an empty string if the Set is empty" do
@@ -21,9 +20,11 @@ describe "Set#join" do
set.join(' | ').should == "a | b | c"
end
- it "calls #to_a to convert the Set in to an Array" do
- set = Set[:a, :b, :c]
- set.should_receive(:to_a).and_return([:a, :b, :c])
- set.join.should == "abc"
+ ruby_version_is ""..."4.0" do
+ it "calls #to_a to convert the Set in to an Array" do
+ set = Set[:a, :b, :c]
+ set.should_receive(:to_a).and_return([:a, :b, :c])
+ set.join.should == "abc"
+ end
end
end
diff --git a/spec/ruby/library/set/keep_if_spec.rb b/spec/ruby/core/set/keep_if_spec.rb
index 7edc80769f..d6abdd6adc 100644
--- a/spec/ruby/library/set/keep_if_spec.rb
+++ b/spec/ruby/core/set/keep_if_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#keep_if" do
before :each do
diff --git a/spec/ruby/library/set/length_spec.rb b/spec/ruby/core/set/length_spec.rb
index fef63d25a7..6bb697b4ca 100644
--- a/spec/ruby/library/set/length_spec.rb
+++ b/spec/ruby/core/set/length_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/length'
-require 'set'
describe "Set#length" do
it_behaves_like :set_length, :length
diff --git a/spec/ruby/library/set/map_spec.rb b/spec/ruby/core/set/map_spec.rb
index e60e98b179..996191b0a8 100644
--- a/spec/ruby/library/set/map_spec.rb
+++ b/spec/ruby/core/set/map_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/collect'
describe "Set#map!" do
diff --git a/spec/ruby/library/set/member_spec.rb b/spec/ruby/core/set/member_spec.rb
index 5b56a38ab9..5c82e8f826 100644
--- a/spec/ruby/library/set/member_spec.rb
+++ b/spec/ruby/core/set/member_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/include'
-require 'set'
describe "Set#member?" do
it_behaves_like :set_include, :member?
diff --git a/spec/ruby/library/set/merge_spec.rb b/spec/ruby/core/set/merge_spec.rb
index 3ae0da827c..0c6ed27670 100644
--- a/spec/ruby/library/set/merge_spec.rb
+++ b/spec/ruby/core/set/merge_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#merge" do
it "adds the elements of the passed Enumerable to self" do
@@ -17,6 +16,13 @@ describe "Set#merge" do
-> { Set[1, 2].merge(Object.new) }.should raise_error(ArgumentError)
end
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b]
+ set.each do |_m|
+ -> { set.merge([1, 2]) }.should raise_error(RuntimeError, /iteration/)
+ end
+ end
+
ruby_version_is ""..."3.3" do
it "accepts only a single argument" do
-> { Set[].merge([], []) }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 1)")
diff --git a/spec/ruby/library/set/minus_spec.rb b/spec/ruby/core/set/minus_spec.rb
index 3fe0b6a2cc..72f98f985e 100644
--- a/spec/ruby/library/set/minus_spec.rb
+++ b/spec/ruby/core/set/minus_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
require_relative 'shared/difference'
describe "Set#-" do
diff --git a/spec/ruby/library/set/plus_spec.rb b/spec/ruby/core/set/plus_spec.rb
index 3e70d3269d..7e44ff0b7e 100644
--- a/spec/ruby/library/set/plus_spec.rb
+++ b/spec/ruby/core/set/plus_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/union'
-require 'set'
describe "Set#+" do
it_behaves_like :set_union, :+
diff --git a/spec/ruby/library/set/pretty_print_cycle_spec.rb b/spec/ruby/core/set/pretty_print_cycle_spec.rb
index 4f440353e5..7e6017c112 100644
--- a/spec/ruby/library/set/pretty_print_cycle_spec.rb
+++ b/spec/ruby/core/set/pretty_print_cycle_spec.rb
@@ -1,10 +1,14 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#pretty_print_cycle" do
it "passes the 'pretty print' representation of a self-referencing Set to the pretty print writer" do
pp = mock("PrettyPrint")
- pp.should_receive(:text).with("#<Set: {...}>")
+ ruby_version_is(""..."4.0") do
+ pp.should_receive(:text).with("#<Set: {...}>")
+ end
+ ruby_version_is("4.0") do
+ pp.should_receive(:text).with("Set[...]")
+ end
Set[1, 2, 3].pretty_print_cycle(pp)
end
end
diff --git a/spec/ruby/library/set/proper_subset_spec.rb b/spec/ruby/core/set/proper_subset_spec.rb
index 6b51dedc9f..fb7848c001 100644
--- a/spec/ruby/library/set/proper_subset_spec.rb
+++ b/spec/ruby/core/set/proper_subset_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
describe "Set#proper_subset?" do
@@ -35,9 +34,11 @@ describe "Set#proper_subset?" do
end
version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do
- context "when comparing to a Set-like object" do
- it "returns true if passed a Set-like object that self is a proper subset of" do
- Set[1, 2, 3].proper_subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a proper subset of" do
+ Set[1, 2, 3].proper_subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true
+ end
end
end
end
diff --git a/spec/ruby/library/set/proper_superset_spec.rb b/spec/ruby/core/set/proper_superset_spec.rb
index a386c8c097..dc1e87e230 100644
--- a/spec/ruby/library/set/proper_superset_spec.rb
+++ b/spec/ruby/core/set/proper_superset_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
describe "Set#proper_superset?" do
before :each do
@@ -33,9 +32,11 @@ describe "Set#proper_superset?" do
-> { Set[].proper_superset?(Object.new) }.should raise_error(ArgumentError)
end
- context "when comparing to a Set-like object" do
- it "returns true if passed a Set-like object that self is a proper superset of" do
- Set[1, 2, 3, 4].proper_superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a proper superset of" do
+ Set[1, 2, 3, 4].proper_superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true
+ end
end
end
end
diff --git a/spec/ruby/library/set/reject_spec.rb b/spec/ruby/core/set/reject_spec.rb
index 9131f960ad..91d0293415 100644
--- a/spec/ruby/library/set/reject_spec.rb
+++ b/spec/ruby/core/set/reject_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#reject!" do
before :each do
diff --git a/spec/ruby/library/set/replace_spec.rb b/spec/ruby/core/set/replace_spec.rb
index 7511066c9c..c66a2d0ec3 100644
--- a/spec/ruby/library/set/replace_spec.rb
+++ b/spec/ruby/core/set/replace_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#replace" do
before :each do
@@ -11,6 +10,14 @@ describe "Set#replace" do
@set.should == Set[1, 2, 3]
end
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b, :c, :d, :e, :f]
+ set.each do |_m|
+ -> { set.replace(Set[1, 2, 3]) }.should raise_error(RuntimeError, /iteration/)
+ end
+ set.should == Set[:a, :b, :c, :d, :e, :f]
+ end
+
it "accepts any enumerable as other" do
@set.replace([1, 2, 3]).should == Set[1, 2, 3]
end
diff --git a/spec/ruby/library/set/select_spec.rb b/spec/ruby/core/set/select_spec.rb
index b458ffacaa..b458ffacaa 100644
--- a/spec/ruby/library/set/select_spec.rb
+++ b/spec/ruby/core/set/select_spec.rb
diff --git a/spec/ruby/core/set/set_spec.rb b/spec/ruby/core/set/set_spec.rb
new file mode 100644
index 0000000000..fd1d2072e3
--- /dev/null
+++ b/spec/ruby/core/set/set_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+describe 'Set' do
+ it 'is available without explicit requiring' do
+ output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
+ puts Set.new([1, 2, 3]).to_a.inspect
+ RUBY
+ output.chomp.should == "[1, 2, 3]"
+ end
+end
diff --git a/spec/ruby/library/set/shared/add.rb b/spec/ruby/core/set/shared/add.rb
index 9e797f5df9..9e797f5df9 100644
--- a/spec/ruby/library/set/shared/add.rb
+++ b/spec/ruby/core/set/shared/add.rb
diff --git a/spec/ruby/library/set/shared/collect.rb b/spec/ruby/core/set/shared/collect.rb
index bc58c231be..bc58c231be 100644
--- a/spec/ruby/library/set/shared/collect.rb
+++ b/spec/ruby/core/set/shared/collect.rb
diff --git a/spec/ruby/library/set/shared/difference.rb b/spec/ruby/core/set/shared/difference.rb
index f88987ed2a..f88987ed2a 100644
--- a/spec/ruby/library/set/shared/difference.rb
+++ b/spec/ruby/core/set/shared/difference.rb
diff --git a/spec/ruby/library/set/shared/include.rb b/spec/ruby/core/set/shared/include.rb
index b4d95cde24..b4d95cde24 100644
--- a/spec/ruby/library/set/shared/include.rb
+++ b/spec/ruby/core/set/shared/include.rb
diff --git a/spec/ruby/core/set/shared/inspect.rb b/spec/ruby/core/set/shared/inspect.rb
new file mode 100644
index 0000000000..a90af66c98
--- /dev/null
+++ b/spec/ruby/core/set/shared/inspect.rb
@@ -0,0 +1,45 @@
+describe :set_inspect, shared: true do
+ it "returns a String representation of self" do
+ Set[].send(@method).should be_kind_of(String)
+ Set[nil, false, true].send(@method).should be_kind_of(String)
+ Set[1, 2, 3].send(@method).should be_kind_of(String)
+ Set["1", "2", "3"].send(@method).should be_kind_of(String)
+ Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String)
+ end
+
+ ruby_version_is "4.0" do
+ it "does include the elements of the set" do
+ Set["1"].send(@method).should == 'Set["1"]'
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "does include the elements of the set" do
+ Set["1"].send(@method).should == '#<Set: {"1"}>'
+ end
+ end
+
+ it "puts spaces between the elements" do
+ Set["1", "2"].send(@method).should include('", "')
+ end
+
+ ruby_version_is "4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.send(@method).should be_kind_of(String)
+ set1.send(@method).should include("Set[...]")
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.send(@method).should be_kind_of(String)
+ set1.send(@method).should include("#<Set: {...}>")
+ end
+ end
+end
diff --git a/spec/ruby/library/set/shared/intersection.rb b/spec/ruby/core/set/shared/intersection.rb
index 5ae4199c94..5ae4199c94 100644
--- a/spec/ruby/library/set/shared/intersection.rb
+++ b/spec/ruby/core/set/shared/intersection.rb
diff --git a/spec/ruby/library/set/shared/length.rb b/spec/ruby/core/set/shared/length.rb
index a8fcee9f39..a8fcee9f39 100644
--- a/spec/ruby/library/set/shared/length.rb
+++ b/spec/ruby/core/set/shared/length.rb
diff --git a/spec/ruby/library/set/shared/select.rb b/spec/ruby/core/set/shared/select.rb
index 2108d398b4..467b236ed3 100644
--- a/spec/ruby/library/set/shared/select.rb
+++ b/spec/ruby/core/set/shared/select.rb
@@ -1,5 +1,4 @@
require_relative '../../../spec_helper'
-require 'set'
describe :set_select_bang, shared: true do
before :each do
diff --git a/spec/ruby/library/set/shared/union.rb b/spec/ruby/core/set/shared/union.rb
index 314f0e852d..314f0e852d 100644
--- a/spec/ruby/library/set/shared/union.rb
+++ b/spec/ruby/core/set/shared/union.rb
diff --git a/spec/ruby/library/set/size_spec.rb b/spec/ruby/core/set/size_spec.rb
index 3c8cb38517..4ae22c5f0a 100644
--- a/spec/ruby/library/set/size_spec.rb
+++ b/spec/ruby/core/set/size_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/length'
-require 'set'
describe "Set#size" do
it_behaves_like :set_length, :size
diff --git a/spec/ruby/core/set/sortedset/sortedset_spec.rb b/spec/ruby/core/set/sortedset/sortedset_spec.rb
new file mode 100644
index 0000000000..f3c1ec058d
--- /dev/null
+++ b/spec/ruby/core/set/sortedset/sortedset_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../../spec_helper'
+
+describe "SortedSet" do
+ ruby_version_is ""..."4.0" do
+ it "raises error including message that it has been extracted from the set stdlib" do
+ -> {
+ SortedSet
+ }.should raise_error(RuntimeError) { |e|
+ e.message.should.include?("The `SortedSet` class has been extracted from the `set` library")
+ }
+ end
+ end
+end
diff --git a/spec/ruby/library/set/subset_spec.rb b/spec/ruby/core/set/subset_spec.rb
index 85666d633f..112bd9b38a 100644
--- a/spec/ruby/library/set/subset_spec.rb
+++ b/spec/ruby/core/set/subset_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
describe "Set#subset?" do
@@ -35,9 +34,11 @@ describe "Set#subset?" do
end
version_is(set_version, ""..."1.1.0") do #ruby_version_is ""..."3.3" do
- context "when comparing to a Set-like object" do
- it "returns true if passed a Set-like object that self is a subset of" do
- Set[1, 2, 3].subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a subset of" do
+ Set[1, 2, 3].subset?(SetSpecs::SetLike.new([1, 2, 3, 4])).should be_true
+ end
end
end
end
diff --git a/spec/ruby/library/set/subtract_spec.rb b/spec/ruby/core/set/subtract_spec.rb
index 56713de8b3..ae4bc73d41 100644
--- a/spec/ruby/library/set/subtract_spec.rb
+++ b/spec/ruby/core/set/subtract_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#subtract" do
before :each do
diff --git a/spec/ruby/library/set/superset_spec.rb b/spec/ruby/core/set/superset_spec.rb
index bd9d2f3eee..9b3df2d047 100644
--- a/spec/ruby/library/set/superset_spec.rb
+++ b/spec/ruby/core/set/superset_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'fixtures/set_like'
-require 'set'
describe "Set#superset?" do
before :each do
@@ -33,9 +32,11 @@ describe "Set#superset?" do
-> { Set[].superset?(Object.new) }.should raise_error(ArgumentError)
end
- context "when comparing to a Set-like object" do
- it "returns true if passed a Set-like object that self is a superset of" do
- Set[1, 2, 3, 4].superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a superset of" do
+ Set[1, 2, 3, 4].superset?(SetSpecs::SetLike.new([1, 2, 3])).should be_true
+ end
end
end
end
diff --git a/spec/ruby/library/set/to_a_spec.rb b/spec/ruby/core/set/to_a_spec.rb
index 689e44f38a..1e9800167a 100644
--- a/spec/ruby/library/set/to_a_spec.rb
+++ b/spec/ruby/core/set/to_a_spec.rb
@@ -1,5 +1,4 @@
require_relative '../../spec_helper'
-require 'set'
describe "Set#to_a" do
it "returns an array containing elements of self" do
diff --git a/spec/ruby/library/set/to_s_spec.rb b/spec/ruby/core/set/to_s_spec.rb
index 3c26ae9346..55b8bfd9b2 100644
--- a/spec/ruby/library/set/to_s_spec.rb
+++ b/spec/ruby/core/set/to_s_spec.rb
@@ -1,6 +1,5 @@
require_relative "../../spec_helper"
require_relative 'shared/inspect'
-require 'set'
describe "Set#to_s" do
it_behaves_like :set_inspect, :to_s
diff --git a/spec/ruby/library/set/union_spec.rb b/spec/ruby/core/set/union_spec.rb
index 20fe0ddca3..3e77022d4b 100644
--- a/spec/ruby/library/set/union_spec.rb
+++ b/spec/ruby/core/set/union_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
require_relative 'shared/union'
-require 'set'
describe "Set#union" do
it_behaves_like :set_union, :union
diff --git a/spec/ruby/core/sizedqueue/append_spec.rb b/spec/ruby/core/sizedqueue/append_spec.rb
index 6fffe2f272..c52baa3802 100644
--- a/spec/ruby/core/sizedqueue/append_spec.rb
+++ b/spec/ruby/core/sizedqueue/append_spec.rb
@@ -12,7 +12,5 @@ describe "SizedQueue#<<" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.send(:<<, 1, timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.send(:<<, 1, timeout: v) }
end
diff --git a/spec/ruby/core/sizedqueue/deq_spec.rb b/spec/ruby/core/sizedqueue/deq_spec.rb
index 985d654bb3..2aeb52f8a6 100644
--- a/spec/ruby/core/sizedqueue/deq_spec.rb
+++ b/spec/ruby/core/sizedqueue/deq_spec.rb
@@ -7,7 +7,5 @@ describe "SizedQueue#deq" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.deq(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.deq(timeout: v) }
end
diff --git a/spec/ruby/core/sizedqueue/enq_spec.rb b/spec/ruby/core/sizedqueue/enq_spec.rb
index 619373e46b..b955909475 100644
--- a/spec/ruby/core/sizedqueue/enq_spec.rb
+++ b/spec/ruby/core/sizedqueue/enq_spec.rb
@@ -12,7 +12,5 @@ describe "SizedQueue#enq" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.enq(1, timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.enq(1, timeout: v) }
end
diff --git a/spec/ruby/core/sizedqueue/pop_spec.rb b/spec/ruby/core/sizedqueue/pop_spec.rb
index 5e7cfea8fb..6338ddbaa0 100644
--- a/spec/ruby/core/sizedqueue/pop_spec.rb
+++ b/spec/ruby/core/sizedqueue/pop_spec.rb
@@ -7,7 +7,5 @@ describe "SizedQueue#pop" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.pop(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.pop(timeout: v) }
end
diff --git a/spec/ruby/core/sizedqueue/push_spec.rb b/spec/ruby/core/sizedqueue/push_spec.rb
index ce61e89b53..9eaa6beca0 100644
--- a/spec/ruby/core/sizedqueue/push_spec.rb
+++ b/spec/ruby/core/sizedqueue/push_spec.rb
@@ -12,7 +12,5 @@ describe "SizedQueue#push" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.push(1, timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.push(1, timeout: v) }
end
diff --git a/spec/ruby/core/sizedqueue/shift_spec.rb b/spec/ruby/core/sizedqueue/shift_spec.rb
index 3220801f3a..52974c1d99 100644
--- a/spec/ruby/core/sizedqueue/shift_spec.rb
+++ b/spec/ruby/core/sizedqueue/shift_spec.rb
@@ -7,7 +7,5 @@ describe "SizedQueue#shift" do
end
describe "SizedQueue operations with timeout" do
- ruby_version_is "3.2" do
- it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.shift(timeout: v) }
- end
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.shift(timeout: v) }
end
diff --git a/spec/ruby/core/string/byteindex_spec.rb b/spec/ruby/core/string/byteindex_spec.rb
index 47c7be1029..d420f3f683 100644
--- a/spec/ruby/core/string/byteindex_spec.rb
+++ b/spec/ruby/core/string/byteindex_spec.rb
@@ -4,301 +4,295 @@ require_relative 'fixtures/classes'
require_relative 'shared/byte_index_common.rb'
describe "String#byteindex" do
- ruby_version_is "3.2" do
- it "calls #to_str to convert the first argument" do
- char = mock("string index char")
- char.should_receive(:to_str).and_return("b")
- "abc".byteindex(char).should == 1
- end
-
- it "calls #to_int to convert the second argument" do
- offset = mock("string index offset")
- offset.should_receive(:to_int).and_return(1)
- "abc".byteindex("c", offset).should == 2
- end
+ it "calls #to_str to convert the first argument" do
+ char = mock("string index char")
+ char.should_receive(:to_str).and_return("b")
+ "abc".byteindex(char).should == 1
+ end
- it "does not raise IndexError when byte offset is correct or on string boundary" do
- "ã‚".byteindex("").should == 0
- "ã‚".byteindex("", 0).should == 0
- "ã‚".byteindex("", 3).should == 3
- end
+ it "calls #to_int to convert the second argument" do
+ offset = mock("string index offset")
+ offset.should_receive(:to_int).and_return(1)
+ "abc".byteindex("c", offset).should == 2
+ end
- it_behaves_like :byte_index_common, :byteindex
+ it "does not raise IndexError when byte offset is correct or on string boundary" do
+ "ã‚".byteindex("").should == 0
+ "ã‚".byteindex("", 0).should == 0
+ "ã‚".byteindex("", 3).should == 3
end
+
+ it_behaves_like :byte_index_common, :byteindex
end
describe "String#byteindex with String" do
- ruby_version_is "3.2" do
- it "behaves the same as String#byteindex(char) for one-character strings" do
- "blablabla hello cruel world...!".split("").uniq.each do |str|
- chr = str[0]
- str.byteindex(str).should == str.byteindex(chr)
+ it "behaves the same as String#byteindex(char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0]
+ str.byteindex(str).should == str.byteindex(chr)
- 0.upto(str.size + 1) do |start|
- str.byteindex(str, start).should == str.byteindex(chr, start)
- end
+ 0.upto(str.size + 1) do |start|
+ str.byteindex(str, start).should == str.byteindex(chr, start)
+ end
- (-str.size - 1).upto(-1) do |start|
- str.byteindex(str, start).should == str.byteindex(chr, start)
- end
+ (-str.size - 1).upto(-1) do |start|
+ str.byteindex(str, start).should == str.byteindex(chr, start)
end
end
+ end
- it "returns the byteindex of the first occurrence of the given substring" do
- "blablabla".byteindex("").should == 0
- "blablabla".byteindex("b").should == 0
- "blablabla".byteindex("bla").should == 0
- "blablabla".byteindex("blabla").should == 0
- "blablabla".byteindex("blablabla").should == 0
-
- "blablabla".byteindex("l").should == 1
- "blablabla".byteindex("la").should == 1
- "blablabla".byteindex("labla").should == 1
- "blablabla".byteindex("lablabla").should == 1
-
- "blablabla".byteindex("a").should == 2
- "blablabla".byteindex("abla").should == 2
- "blablabla".byteindex("ablabla").should == 2
- end
+ it "returns the byteindex of the first occurrence of the given substring" do
+ "blablabla".byteindex("").should == 0
+ "blablabla".byteindex("b").should == 0
+ "blablabla".byteindex("bla").should == 0
+ "blablabla".byteindex("blabla").should == 0
+ "blablabla".byteindex("blablabla").should == 0
+
+ "blablabla".byteindex("l").should == 1
+ "blablabla".byteindex("la").should == 1
+ "blablabla".byteindex("labla").should == 1
+ "blablabla".byteindex("lablabla").should == 1
+
+ "blablabla".byteindex("a").should == 2
+ "blablabla".byteindex("abla").should == 2
+ "blablabla".byteindex("ablabla").should == 2
+ end
- it "treats the offset as a byteindex" do
- "aaaaa".byteindex("a", 0).should == 0
- "aaaaa".byteindex("a", 2).should == 2
- "aaaaa".byteindex("a", 4).should == 4
- end
+ it "treats the offset as a byteindex" do
+ "aaaaa".byteindex("a", 0).should == 0
+ "aaaaa".byteindex("a", 2).should == 2
+ "aaaaa".byteindex("a", 4).should == 4
+ end
- it "ignores string subclasses" do
- "blablabla".byteindex(StringSpecs::MyString.new("bla")).should == 0
- StringSpecs::MyString.new("blablabla").byteindex("bla").should == 0
- StringSpecs::MyString.new("blablabla").byteindex(StringSpecs::MyString.new("bla")).should == 0
- end
+ it "ignores string subclasses" do
+ "blablabla".byteindex(StringSpecs::MyString.new("bla")).should == 0
+ StringSpecs::MyString.new("blablabla").byteindex("bla").should == 0
+ StringSpecs::MyString.new("blablabla").byteindex(StringSpecs::MyString.new("bla")).should == 0
+ end
- it "starts the search at the given offset" do
- "blablabla".byteindex("bl", 0).should == 0
- "blablabla".byteindex("bl", 1).should == 3
- "blablabla".byteindex("bl", 2).should == 3
- "blablabla".byteindex("bl", 3).should == 3
-
- "blablabla".byteindex("bla", 0).should == 0
- "blablabla".byteindex("bla", 1).should == 3
- "blablabla".byteindex("bla", 2).should == 3
- "blablabla".byteindex("bla", 3).should == 3
-
- "blablabla".byteindex("blab", 0).should == 0
- "blablabla".byteindex("blab", 1).should == 3
- "blablabla".byteindex("blab", 2).should == 3
- "blablabla".byteindex("blab", 3).should == 3
-
- "blablabla".byteindex("la", 1).should == 1
- "blablabla".byteindex("la", 2).should == 4
- "blablabla".byteindex("la", 3).should == 4
- "blablabla".byteindex("la", 4).should == 4
-
- "blablabla".byteindex("lab", 1).should == 1
- "blablabla".byteindex("lab", 2).should == 4
- "blablabla".byteindex("lab", 3).should == 4
- "blablabla".byteindex("lab", 4).should == 4
-
- "blablabla".byteindex("ab", 2).should == 2
- "blablabla".byteindex("ab", 3).should == 5
- "blablabla".byteindex("ab", 4).should == 5
- "blablabla".byteindex("ab", 5).should == 5
-
- "blablabla".byteindex("", 0).should == 0
- "blablabla".byteindex("", 1).should == 1
- "blablabla".byteindex("", 2).should == 2
- "blablabla".byteindex("", 7).should == 7
- "blablabla".byteindex("", 8).should == 8
- "blablabla".byteindex("", 9).should == 9
- end
+ it "starts the search at the given offset" do
+ "blablabla".byteindex("bl", 0).should == 0
+ "blablabla".byteindex("bl", 1).should == 3
+ "blablabla".byteindex("bl", 2).should == 3
+ "blablabla".byteindex("bl", 3).should == 3
+
+ "blablabla".byteindex("bla", 0).should == 0
+ "blablabla".byteindex("bla", 1).should == 3
+ "blablabla".byteindex("bla", 2).should == 3
+ "blablabla".byteindex("bla", 3).should == 3
+
+ "blablabla".byteindex("blab", 0).should == 0
+ "blablabla".byteindex("blab", 1).should == 3
+ "blablabla".byteindex("blab", 2).should == 3
+ "blablabla".byteindex("blab", 3).should == 3
+
+ "blablabla".byteindex("la", 1).should == 1
+ "blablabla".byteindex("la", 2).should == 4
+ "blablabla".byteindex("la", 3).should == 4
+ "blablabla".byteindex("la", 4).should == 4
+
+ "blablabla".byteindex("lab", 1).should == 1
+ "blablabla".byteindex("lab", 2).should == 4
+ "blablabla".byteindex("lab", 3).should == 4
+ "blablabla".byteindex("lab", 4).should == 4
+
+ "blablabla".byteindex("ab", 2).should == 2
+ "blablabla".byteindex("ab", 3).should == 5
+ "blablabla".byteindex("ab", 4).should == 5
+ "blablabla".byteindex("ab", 5).should == 5
+
+ "blablabla".byteindex("", 0).should == 0
+ "blablabla".byteindex("", 1).should == 1
+ "blablabla".byteindex("", 2).should == 2
+ "blablabla".byteindex("", 7).should == 7
+ "blablabla".byteindex("", 8).should == 8
+ "blablabla".byteindex("", 9).should == 9
+ end
- it "starts the search at offset + self.length if offset is negative" do
- str = "blablabla"
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
- ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
- (-str.length .. -1).each do |offset|
- str.byteindex(needle, offset).should ==
- str.byteindex(needle, offset + str.length)
- end
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byteindex(needle, offset).should ==
+ str.byteindex(needle, offset + str.length)
end
end
+ end
- it "returns nil if the substring isn't found" do
- "blablabla".byteindex("B").should == nil
- "blablabla".byteindex("z").should == nil
- "blablabla".byteindex("BLA").should == nil
- "blablabla".byteindex("blablablabla").should == nil
- "blablabla".byteindex("", 10).should == nil
+ it "returns nil if the substring isn't found" do
+ "blablabla".byteindex("B").should == nil
+ "blablabla".byteindex("z").should == nil
+ "blablabla".byteindex("BLA").should == nil
+ "blablabla".byteindex("blablablabla").should == nil
+ "blablabla".byteindex("", 10).should == nil
- "hello".byteindex("he", 1).should == nil
- "hello".byteindex("he", 2).should == nil
- "I’ve got a multibyte character.\n".byteindex("\n\n").should == nil
- end
+ "hello".byteindex("he", 1).should == nil
+ "hello".byteindex("he", 2).should == nil
+ "I’ve got a multibyte character.\n".byteindex("\n\n").should == nil
+ end
- it "returns the character byteindex of a multibyte character" do
- "ã‚りãŒã¨ã†".byteindex("ãŒ").should == 6
- end
+ it "returns the character byteindex of a multibyte character" do
+ "ã‚りãŒã¨ã†".byteindex("ãŒ").should == 6
+ end
- it "returns the character byteindex after offset" do
- "ã‚れã‚れ".byteindex("ã‚", 3).should == 6
- "ã‚りãŒã¨ã†ã‚りãŒã¨ã†".byteindex("ãŒ", 9).should == 21
- end
+ it "returns the character byteindex after offset" do
+ "ã‚れã‚れ".byteindex("ã‚", 3).should == 6
+ "ã‚りãŒã¨ã†ã‚りãŒã¨ã†".byteindex("ãŒ", 9).should == 21
+ end
- it "returns the character byteindex after a partial first match" do
- "</</h".byteindex("</h").should == 2
- end
+ it "returns the character byteindex after a partial first match" do
+ "</</h".byteindex("</h").should == 2
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- char = "れ".encode Encoding::EUC_JP
- -> do
- "ã‚れ".byteindex(char)
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ char = "れ".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".byteindex(char)
+ end.should raise_error(Encoding::CompatibilityError)
+ end
- it "handles a substring in a superset encoding" do
- 'abc'.dup.force_encoding(Encoding::US_ASCII).byteindex('é').should == nil
- end
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).byteindex('é').should == nil
+ end
- it "handles a substring in a subset encoding" do
- 'été'.byteindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
- end
+ it "handles a substring in a subset encoding" do
+ 'été'.byteindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
end
end
describe "String#byteindex with Regexp" do
- ruby_version_is "3.2" do
- it "behaves the same as String#byteindex(string) for escaped string regexps" do
- ["blablabla", "hello cruel world...!"].each do |str|
- ["", "b", "bla", "lab", "o c", "d."].each do |needle|
- regexp = Regexp.new(Regexp.escape(needle))
- str.byteindex(regexp).should == str.byteindex(needle)
-
- 0.upto(str.size + 1) do |start|
- str.byteindex(regexp, start).should == str.byteindex(needle, start)
- end
-
- (-str.size - 1).upto(-1) do |start|
- str.byteindex(regexp, start).should == str.byteindex(needle, start)
- end
+ it "behaves the same as String#byteindex(string) for escaped string regexps" do
+ ["blablabla", "hello cruel world...!"].each do |str|
+ ["", "b", "bla", "lab", "o c", "d."].each do |needle|
+ regexp = Regexp.new(Regexp.escape(needle))
+ str.byteindex(regexp).should == str.byteindex(needle)
+
+ 0.upto(str.size + 1) do |start|
+ str.byteindex(regexp, start).should == str.byteindex(needle, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byteindex(regexp, start).should == str.byteindex(needle, start)
end
end
end
+ end
- it "returns the byteindex of the first match of regexp" do
- "blablabla".byteindex(/bla/).should == 0
- "blablabla".byteindex(/BLA/i).should == 0
+ it "returns the byteindex of the first match of regexp" do
+ "blablabla".byteindex(/bla/).should == 0
+ "blablabla".byteindex(/BLA/i).should == 0
- "blablabla".byteindex(/.{0}/).should == 0
- "blablabla".byteindex(/.{6}/).should == 0
- "blablabla".byteindex(/.{9}/).should == 0
+ "blablabla".byteindex(/.{0}/).should == 0
+ "blablabla".byteindex(/.{6}/).should == 0
+ "blablabla".byteindex(/.{9}/).should == 0
- "blablabla".byteindex(/.*/).should == 0
- "blablabla".byteindex(/.+/).should == 0
+ "blablabla".byteindex(/.*/).should == 0
+ "blablabla".byteindex(/.+/).should == 0
- "blablabla".byteindex(/lab|b/).should == 0
+ "blablabla".byteindex(/lab|b/).should == 0
- not_supported_on :opal do
- "blablabla".byteindex(/\A/).should == 0
- "blablabla".byteindex(/\Z/).should == 9
- "blablabla".byteindex(/\z/).should == 9
- "blablabla\n".byteindex(/\Z/).should == 9
- "blablabla\n".byteindex(/\z/).should == 10
- end
+ not_supported_on :opal do
+ "blablabla".byteindex(/\A/).should == 0
+ "blablabla".byteindex(/\Z/).should == 9
+ "blablabla".byteindex(/\z/).should == 9
+ "blablabla\n".byteindex(/\Z/).should == 9
+ "blablabla\n".byteindex(/\z/).should == 10
+ end
- "blablabla".byteindex(/^/).should == 0
- "\nblablabla".byteindex(/^/).should == 0
- "b\nablabla".byteindex(/$/).should == 1
- "bl\nablabla".byteindex(/$/).should == 2
+ "blablabla".byteindex(/^/).should == 0
+ "\nblablabla".byteindex(/^/).should == 0
+ "b\nablabla".byteindex(/$/).should == 1
+ "bl\nablabla".byteindex(/$/).should == 2
- "blablabla".byteindex(/.l./).should == 0
- end
+ "blablabla".byteindex(/.l./).should == 0
+ end
- it "starts the search at the given offset" do
- "blablabla".byteindex(/.{0}/, 5).should == 5
- "blablabla".byteindex(/.{1}/, 5).should == 5
- "blablabla".byteindex(/.{2}/, 5).should == 5
- "blablabla".byteindex(/.{3}/, 5).should == 5
- "blablabla".byteindex(/.{4}/, 5).should == 5
-
- "blablabla".byteindex(/.{0}/, 3).should == 3
- "blablabla".byteindex(/.{1}/, 3).should == 3
- "blablabla".byteindex(/.{2}/, 3).should == 3
- "blablabla".byteindex(/.{5}/, 3).should == 3
- "blablabla".byteindex(/.{6}/, 3).should == 3
-
- "blablabla".byteindex(/.l./, 0).should == 0
- "blablabla".byteindex(/.l./, 1).should == 3
- "blablabla".byteindex(/.l./, 2).should == 3
- "blablabla".byteindex(/.l./, 3).should == 3
-
- "xblaxbla".byteindex(/x./, 0).should == 0
- "xblaxbla".byteindex(/x./, 1).should == 4
- "xblaxbla".byteindex(/x./, 2).should == 4
-
- not_supported_on :opal do
- "blablabla\n".byteindex(/\Z/, 9).should == 9
- end
+ it "starts the search at the given offset" do
+ "blablabla".byteindex(/.{0}/, 5).should == 5
+ "blablabla".byteindex(/.{1}/, 5).should == 5
+ "blablabla".byteindex(/.{2}/, 5).should == 5
+ "blablabla".byteindex(/.{3}/, 5).should == 5
+ "blablabla".byteindex(/.{4}/, 5).should == 5
+
+ "blablabla".byteindex(/.{0}/, 3).should == 3
+ "blablabla".byteindex(/.{1}/, 3).should == 3
+ "blablabla".byteindex(/.{2}/, 3).should == 3
+ "blablabla".byteindex(/.{5}/, 3).should == 3
+ "blablabla".byteindex(/.{6}/, 3).should == 3
+
+ "blablabla".byteindex(/.l./, 0).should == 0
+ "blablabla".byteindex(/.l./, 1).should == 3
+ "blablabla".byteindex(/.l./, 2).should == 3
+ "blablabla".byteindex(/.l./, 3).should == 3
+
+ "xblaxbla".byteindex(/x./, 0).should == 0
+ "xblaxbla".byteindex(/x./, 1).should == 4
+ "xblaxbla".byteindex(/x./, 2).should == 4
+
+ not_supported_on :opal do
+ "blablabla\n".byteindex(/\Z/, 9).should == 9
end
+ end
- it "starts the search at offset + self.length if offset is negative" do
- str = "blablabla"
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
- ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
- (-str.length .. -1).each do |offset|
- str.byteindex(needle, offset).should ==
- str.byteindex(needle, offset + str.length)
- end
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byteindex(needle, offset).should ==
+ str.byteindex(needle, offset + str.length)
end
end
+ end
- it "returns nil if the substring isn't found" do
- "blablabla".byteindex(/BLA/).should == nil
+ it "returns nil if the substring isn't found" do
+ "blablabla".byteindex(/BLA/).should == nil
- "blablabla".byteindex(/.{10}/).should == nil
- "blaxbla".byteindex(/.x/, 3).should == nil
- "blaxbla".byteindex(/..x/, 2).should == nil
- end
+ "blablabla".byteindex(/.{10}/).should == nil
+ "blaxbla".byteindex(/.x/, 3).should == nil
+ "blaxbla".byteindex(/..x/, 2).should == nil
+ end
- it "returns nil if the Regexp matches the empty string and the offset is out of range" do
- "ruby".byteindex(//, 12).should be_nil
- end
+ it "returns nil if the Regexp matches the empty string and the offset is out of range" do
+ "ruby".byteindex(//, 12).should be_nil
+ end
- it "supports \\G which matches at the given start offset" do
- "helloYOU.".byteindex(/\GYOU/, 5).should == 5
- "helloYOU.".byteindex(/\GYOU/).should == nil
+ it "supports \\G which matches at the given start offset" do
+ "helloYOU.".byteindex(/\GYOU/, 5).should == 5
+ "helloYOU.".byteindex(/\GYOU/).should == nil
- re = /\G.+YOU/
- # The # marks where \G will match.
- [
- ["#hi!YOUall.", 0],
- ["h#i!YOUall.", 1],
- ["hi#!YOUall.", 2],
- ["hi!#YOUall.", nil]
- ].each do |spec|
+ re = /\G.+YOU/
+ # The # marks where \G will match.
+ [
+ ["#hi!YOUall.", 0],
+ ["h#i!YOUall.", 1],
+ ["hi#!YOUall.", 2],
+ ["hi!#YOUall.", nil]
+ ].each do |spec|
- start = spec[0].byteindex("#")
- str = spec[0].delete("#")
+ start = spec[0].byteindex("#")
+ str = spec[0].delete("#")
- str.byteindex(re, start).should == spec[1]
- end
+ str.byteindex(re, start).should == spec[1]
end
+ end
- it "converts start_offset to an integer via to_int" do
- obj = mock('1')
- obj.should_receive(:to_int).and_return(1)
- "RWOARW".byteindex(/R./, obj).should == 4
- end
+ it "converts start_offset to an integer via to_int" do
+ obj = mock('1')
+ obj.should_receive(:to_int).and_return(1)
+ "RWOARW".byteindex(/R./, obj).should == 4
+ end
- it "returns the character byteindex of a multibyte character" do
- "ã‚りãŒã¨ã†".byteindex(/ãŒ/).should == 6
- end
+ it "returns the character byteindex of a multibyte character" do
+ "ã‚りãŒã¨ã†".byteindex(/ãŒ/).should == 6
+ end
- it "returns the character byteindex after offset" do
- "ã‚れã‚れ".byteindex(/ã‚/, 3).should == 6
- end
+ it "returns the character byteindex after offset" do
+ "ã‚れã‚れ".byteindex(/ã‚/, 3).should == 6
+ end
- it "treats the offset as a byteindex" do
- "ã‚れã‚ã‚れ".byteindex(/ã‚/, 6).should == 6
- end
+ it "treats the offset as a byteindex" do
+ "ã‚れã‚ã‚れ".byteindex(/ã‚/, 6).should == 6
end
end
diff --git a/spec/ruby/core/string/byterindex_spec.rb b/spec/ruby/core/string/byterindex_spec.rb
index 34ecbfbd21..983222e35d 100644
--- a/spec/ruby/core/string/byterindex_spec.rb
+++ b/spec/ruby/core/string/byterindex_spec.rb
@@ -4,356 +4,350 @@ require_relative 'fixtures/classes'
require_relative 'shared/byte_index_common.rb'
describe "String#byterindex with object" do
- ruby_version_is "3.2" do
- it "tries to convert obj to a string via to_str" do
- obj = mock('lo')
- def obj.to_str() "lo" end
- "hello".byterindex(obj).should == "hello".byterindex("lo")
-
- obj = mock('o')
- def obj.respond_to?(arg, *) true end
- def obj.method_missing(*args) "o" end
- "hello".byterindex(obj).should == "hello".byterindex("o")
- end
-
- it "calls #to_int to convert the second argument" do
- offset = mock("string index offset")
- offset.should_receive(:to_int).and_return(3)
- "abc".byterindex("c", offset).should == 2
- end
+ it "tries to convert obj to a string via to_str" do
+ obj = mock('lo')
+ def obj.to_str() "lo" end
+ "hello".byterindex(obj).should == "hello".byterindex("lo")
+
+ obj = mock('o')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args) "o" end
+ "hello".byterindex(obj).should == "hello".byterindex("o")
+ end
- it "does not raise IndexError when byte offset is correct or on string boundary" do
- "ã‚".byterindex("", 0).should == 0
- "ã‚".byterindex("", 3).should == 3
- "ã‚".byterindex("").should == 3
- end
+ it "calls #to_int to convert the second argument" do
+ offset = mock("string index offset")
+ offset.should_receive(:to_int).and_return(3)
+ "abc".byterindex("c", offset).should == 2
+ end
- it_behaves_like :byte_index_common, :byterindex
+ it "does not raise IndexError when byte offset is correct or on string boundary" do
+ "ã‚".byterindex("", 0).should == 0
+ "ã‚".byterindex("", 3).should == 3
+ "ã‚".byterindex("").should == 3
end
+
+ it_behaves_like :byte_index_common, :byterindex
end
describe "String#byterindex with String" do
- ruby_version_is "3.2" do
- it "behaves the same as String#byterindex(char) for one-character strings" do
- "blablabla hello cruel world...!".split("").uniq.each do |str|
- chr = str[0]
- str.byterindex(str).should == str.byterindex(chr)
+ it "behaves the same as String#byterindex(char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0]
+ str.byterindex(str).should == str.byterindex(chr)
- 0.upto(str.size + 1) do |start|
- str.byterindex(str, start).should == str.byterindex(chr, start)
- end
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
- (-str.size - 1).upto(-1) do |start|
- str.byterindex(str, start).should == str.byterindex(chr, start)
- end
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
end
end
+ end
- it "behaves the same as String#byterindex(?char) for one-character strings" do
- "blablabla hello cruel world...!".split("").uniq.each do |str|
- chr = str[0] =~ / / ? str[0] : eval("?#{str[0]}")
- str.byterindex(str).should == str.byterindex(chr)
+ it "behaves the same as String#byterindex(?char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0] =~ / / ? str[0] : eval("?#{str[0]}")
+ str.byterindex(str).should == str.byterindex(chr)
- 0.upto(str.size + 1) do |start|
- str.byterindex(str, start).should == str.byterindex(chr, start)
- end
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
- (-str.size - 1).upto(-1) do |start|
- str.byterindex(str, start).should == str.byterindex(chr, start)
- end
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
end
end
+ end
- it "returns the index of the last occurrence of the given substring" do
- "blablabla".byterindex("").should == 9
- "blablabla".byterindex("a").should == 8
- "blablabla".byterindex("la").should == 7
- "blablabla".byterindex("bla").should == 6
- "blablabla".byterindex("abla").should == 5
- "blablabla".byterindex("labla").should == 4
- "blablabla".byterindex("blabla").should == 3
- "blablabla".byterindex("ablabla").should == 2
- "blablabla".byterindex("lablabla").should == 1
- "blablabla".byterindex("blablabla").should == 0
-
- "blablabla".byterindex("l").should == 7
- "blablabla".byterindex("bl").should == 6
- "blablabla".byterindex("abl").should == 5
- "blablabla".byterindex("labl").should == 4
- "blablabla".byterindex("blabl").should == 3
- "blablabla".byterindex("ablabl").should == 2
- "blablabla".byterindex("lablabl").should == 1
- "blablabla".byterindex("blablabl").should == 0
-
- "blablabla".byterindex("b").should == 6
- "blablabla".byterindex("ab").should == 5
- "blablabla".byterindex("lab").should == 4
- "blablabla".byterindex("blab").should == 3
- "blablabla".byterindex("ablab").should == 2
- "blablabla".byterindex("lablab").should == 1
- "blablabla".byterindex("blablab").should == 0
- end
+ it "returns the index of the last occurrence of the given substring" do
+ "blablabla".byterindex("").should == 9
+ "blablabla".byterindex("a").should == 8
+ "blablabla".byterindex("la").should == 7
+ "blablabla".byterindex("bla").should == 6
+ "blablabla".byterindex("abla").should == 5
+ "blablabla".byterindex("labla").should == 4
+ "blablabla".byterindex("blabla").should == 3
+ "blablabla".byterindex("ablabla").should == 2
+ "blablabla".byterindex("lablabla").should == 1
+ "blablabla".byterindex("blablabla").should == 0
+
+ "blablabla".byterindex("l").should == 7
+ "blablabla".byterindex("bl").should == 6
+ "blablabla".byterindex("abl").should == 5
+ "blablabla".byterindex("labl").should == 4
+ "blablabla".byterindex("blabl").should == 3
+ "blablabla".byterindex("ablabl").should == 2
+ "blablabla".byterindex("lablabl").should == 1
+ "blablabla".byterindex("blablabl").should == 0
+
+ "blablabla".byterindex("b").should == 6
+ "blablabla".byterindex("ab").should == 5
+ "blablabla".byterindex("lab").should == 4
+ "blablabla".byterindex("blab").should == 3
+ "blablabla".byterindex("ablab").should == 2
+ "blablabla".byterindex("lablab").should == 1
+ "blablabla".byterindex("blablab").should == 0
+ end
- it "ignores string subclasses" do
- "blablabla".byterindex(StringSpecs::MyString.new("bla")).should == 6
- StringSpecs::MyString.new("blablabla").byterindex("bla").should == 6
- StringSpecs::MyString.new("blablabla").byterindex(StringSpecs::MyString.new("bla")).should == 6
- end
+ it "ignores string subclasses" do
+ "blablabla".byterindex(StringSpecs::MyString.new("bla")).should == 6
+ StringSpecs::MyString.new("blablabla").byterindex("bla").should == 6
+ StringSpecs::MyString.new("blablabla").byterindex(StringSpecs::MyString.new("bla")).should == 6
+ end
- it "starts the search at the given offset" do
- "blablabla".byterindex("bl", 0).should == 0
- "blablabla".byterindex("bl", 1).should == 0
- "blablabla".byterindex("bl", 2).should == 0
- "blablabla".byterindex("bl", 3).should == 3
-
- "blablabla".byterindex("bla", 0).should == 0
- "blablabla".byterindex("bla", 1).should == 0
- "blablabla".byterindex("bla", 2).should == 0
- "blablabla".byterindex("bla", 3).should == 3
-
- "blablabla".byterindex("blab", 0).should == 0
- "blablabla".byterindex("blab", 1).should == 0
- "blablabla".byterindex("blab", 2).should == 0
- "blablabla".byterindex("blab", 3).should == 3
- "blablabla".byterindex("blab", 6).should == 3
- "blablablax".byterindex("blab", 6).should == 3
-
- "blablabla".byterindex("la", 1).should == 1
- "blablabla".byterindex("la", 2).should == 1
- "blablabla".byterindex("la", 3).should == 1
- "blablabla".byterindex("la", 4).should == 4
-
- "blablabla".byterindex("lab", 1).should == 1
- "blablabla".byterindex("lab", 2).should == 1
- "blablabla".byterindex("lab", 3).should == 1
- "blablabla".byterindex("lab", 4).should == 4
-
- "blablabla".byterindex("ab", 2).should == 2
- "blablabla".byterindex("ab", 3).should == 2
- "blablabla".byterindex("ab", 4).should == 2
- "blablabla".byterindex("ab", 5).should == 5
-
- "blablabla".byterindex("", 0).should == 0
- "blablabla".byterindex("", 1).should == 1
- "blablabla".byterindex("", 2).should == 2
- "blablabla".byterindex("", 7).should == 7
- "blablabla".byterindex("", 8).should == 8
- "blablabla".byterindex("", 9).should == 9
- "blablabla".byterindex("", 10).should == 9
- end
+ it "starts the search at the given offset" do
+ "blablabla".byterindex("bl", 0).should == 0
+ "blablabla".byterindex("bl", 1).should == 0
+ "blablabla".byterindex("bl", 2).should == 0
+ "blablabla".byterindex("bl", 3).should == 3
+
+ "blablabla".byterindex("bla", 0).should == 0
+ "blablabla".byterindex("bla", 1).should == 0
+ "blablabla".byterindex("bla", 2).should == 0
+ "blablabla".byterindex("bla", 3).should == 3
+
+ "blablabla".byterindex("blab", 0).should == 0
+ "blablabla".byterindex("blab", 1).should == 0
+ "blablabla".byterindex("blab", 2).should == 0
+ "blablabla".byterindex("blab", 3).should == 3
+ "blablabla".byterindex("blab", 6).should == 3
+ "blablablax".byterindex("blab", 6).should == 3
+
+ "blablabla".byterindex("la", 1).should == 1
+ "blablabla".byterindex("la", 2).should == 1
+ "blablabla".byterindex("la", 3).should == 1
+ "blablabla".byterindex("la", 4).should == 4
+
+ "blablabla".byterindex("lab", 1).should == 1
+ "blablabla".byterindex("lab", 2).should == 1
+ "blablabla".byterindex("lab", 3).should == 1
+ "blablabla".byterindex("lab", 4).should == 4
+
+ "blablabla".byterindex("ab", 2).should == 2
+ "blablabla".byterindex("ab", 3).should == 2
+ "blablabla".byterindex("ab", 4).should == 2
+ "blablabla".byterindex("ab", 5).should == 5
+
+ "blablabla".byterindex("", 0).should == 0
+ "blablabla".byterindex("", 1).should == 1
+ "blablabla".byterindex("", 2).should == 2
+ "blablabla".byterindex("", 7).should == 7
+ "blablabla".byterindex("", 8).should == 8
+ "blablabla".byterindex("", 9).should == 9
+ "blablabla".byterindex("", 10).should == 9
+ end
- it "starts the search at offset + self.length if offset is negative" do
- str = "blablabla"
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
- ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
- (-str.length .. -1).each do |offset|
- str.byterindex(needle, offset).should ==
- str.byterindex(needle, offset + str.length)
- end
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byterindex(needle, offset).should ==
+ str.byterindex(needle, offset + str.length)
end
end
+ end
- it "returns nil if the substring isn't found" do
- "blablabla".byterindex("B").should == nil
- "blablabla".byterindex("z").should == nil
- "blablabla".byterindex("BLA").should == nil
- "blablabla".byterindex("blablablabla").should == nil
+ it "returns nil if the substring isn't found" do
+ "blablabla".byterindex("B").should == nil
+ "blablabla".byterindex("z").should == nil
+ "blablabla".byterindex("BLA").should == nil
+ "blablabla".byterindex("blablablabla").should == nil
- "hello".byterindex("lo", 0).should == nil
- "hello".byterindex("lo", 1).should == nil
- "hello".byterindex("lo", 2).should == nil
+ "hello".byterindex("lo", 0).should == nil
+ "hello".byterindex("lo", 1).should == nil
+ "hello".byterindex("lo", 2).should == nil
- "hello".byterindex("llo", 0).should == nil
- "hello".byterindex("llo", 1).should == nil
+ "hello".byterindex("llo", 0).should == nil
+ "hello".byterindex("llo", 1).should == nil
- "hello".byterindex("el", 0).should == nil
- "hello".byterindex("ello", 0).should == nil
+ "hello".byterindex("el", 0).should == nil
+ "hello".byterindex("ello", 0).should == nil
- "hello".byterindex("", -6).should == nil
- "hello".byterindex("", -7).should == nil
+ "hello".byterindex("", -6).should == nil
+ "hello".byterindex("", -7).should == nil
- "hello".byterindex("h", -6).should == nil
- end
+ "hello".byterindex("h", -6).should == nil
+ end
- it "tries to convert start_offset to an integer via to_int" do
- obj = mock('5')
- def obj.to_int() 5 end
- "str".byterindex("st", obj).should == 0
+ it "tries to convert start_offset to an integer via to_int" do
+ obj = mock('5')
+ def obj.to_int() 5 end
+ "str".byterindex("st", obj).should == 0
- obj = mock('5')
- def obj.respond_to?(arg, *) true end
- def obj.method_missing(*args) 5 end
- "str".byterindex("st", obj).should == 0
- end
+ obj = mock('5')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args) 5 end
+ "str".byterindex("st", obj).should == 0
+ end
- it "raises a TypeError when given offset is nil" do
- -> { "str".byterindex("st", nil) }.should raise_error(TypeError)
- end
+ it "raises a TypeError when given offset is nil" do
+ -> { "str".byterindex("st", nil) }.should raise_error(TypeError)
+ end
- it "handles a substring in a superset encoding" do
- 'abc'.dup.force_encoding(Encoding::US_ASCII).byterindex('é').should == nil
- end
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).byterindex('é').should == nil
+ end
- it "handles a substring in a subset encoding" do
- 'été'.byterindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
- end
+ it "handles a substring in a subset encoding" do
+ 'été'.byterindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
end
end
describe "String#byterindex with Regexp" do
- ruby_version_is "3.2" do
- it "behaves the same as String#byterindex(string) for escaped string regexps" do
- ["blablabla", "hello cruel world...!"].each do |str|
- ["", "b", "bla", "lab", "o c", "d."].each do |needle|
- regexp = Regexp.new(Regexp.escape(needle))
- str.byterindex(regexp).should == str.byterindex(needle)
-
- 0.upto(str.size + 1) do |start|
- str.byterindex(regexp, start).should == str.byterindex(needle, start)
- end
-
- (-str.size - 1).upto(-1) do |start|
- str.byterindex(regexp, start).should == str.byterindex(needle, start)
- end
+ it "behaves the same as String#byterindex(string) for escaped string regexps" do
+ ["blablabla", "hello cruel world...!"].each do |str|
+ ["", "b", "bla", "lab", "o c", "d."].each do |needle|
+ regexp = Regexp.new(Regexp.escape(needle))
+ str.byterindex(regexp).should == str.byterindex(needle)
+
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(regexp, start).should == str.byterindex(needle, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(regexp, start).should == str.byterindex(needle, start)
end
end
end
+ end
- it "returns the index of the first match from the end of string of regexp" do
- "blablabla".byterindex(/bla/).should == 6
- "blablabla".byterindex(/BLA/i).should == 6
-
- "blablabla".byterindex(/.{0}/).should == 9
- "blablabla".byterindex(/.{1}/).should == 8
- "blablabla".byterindex(/.{2}/).should == 7
- "blablabla".byterindex(/.{6}/).should == 3
- "blablabla".byterindex(/.{9}/).should == 0
+ it "returns the index of the first match from the end of string of regexp" do
+ "blablabla".byterindex(/bla/).should == 6
+ "blablabla".byterindex(/BLA/i).should == 6
- "blablabla".byterindex(/.*/).should == 9
- "blablabla".byterindex(/.+/).should == 8
+ "blablabla".byterindex(/.{0}/).should == 9
+ "blablabla".byterindex(/.{1}/).should == 8
+ "blablabla".byterindex(/.{2}/).should == 7
+ "blablabla".byterindex(/.{6}/).should == 3
+ "blablabla".byterindex(/.{9}/).should == 0
- "blablabla".byterindex(/bla|a/).should == 8
+ "blablabla".byterindex(/.*/).should == 9
+ "blablabla".byterindex(/.+/).should == 8
- not_supported_on :opal do
- "blablabla".byterindex(/\A/).should == 0
- "blablabla".byterindex(/\Z/).should == 9
- "blablabla".byterindex(/\z/).should == 9
- "blablabla\n".byterindex(/\Z/).should == 10
- "blablabla\n".byterindex(/\z/).should == 10
- end
+ "blablabla".byterindex(/bla|a/).should == 8
- "blablabla".byterindex(/^/).should == 0
- not_supported_on :opal do
- "\nblablabla".byterindex(/^/).should == 1
- "b\nlablabla".byterindex(/^/).should == 2
- end
- "blablabla".byterindex(/$/).should == 9
-
- "blablabla".byterindex(/.l./).should == 6
+ not_supported_on :opal do
+ "blablabla".byterindex(/\A/).should == 0
+ "blablabla".byterindex(/\Z/).should == 9
+ "blablabla".byterindex(/\z/).should == 9
+ "blablabla\n".byterindex(/\Z/).should == 10
+ "blablabla\n".byterindex(/\z/).should == 10
end
- it "starts the search at the given offset" do
- "blablabla".byterindex(/.{0}/, 5).should == 5
- "blablabla".byterindex(/.{1}/, 5).should == 5
- "blablabla".byterindex(/.{2}/, 5).should == 5
- "blablabla".byterindex(/.{3}/, 5).should == 5
- "blablabla".byterindex(/.{4}/, 5).should == 5
-
- "blablabla".byterindex(/.{0}/, 3).should == 3
- "blablabla".byterindex(/.{1}/, 3).should == 3
- "blablabla".byterindex(/.{2}/, 3).should == 3
- "blablabla".byterindex(/.{5}/, 3).should == 3
- "blablabla".byterindex(/.{6}/, 3).should == 3
-
- "blablabla".byterindex(/.l./, 0).should == 0
- "blablabla".byterindex(/.l./, 1).should == 0
- "blablabla".byterindex(/.l./, 2).should == 0
- "blablabla".byterindex(/.l./, 3).should == 3
-
- "blablablax".byterindex(/.x/, 10).should == 8
- "blablablax".byterindex(/.x/, 9).should == 8
- "blablablax".byterindex(/.x/, 8).should == 8
-
- "blablablax".byterindex(/..x/, 10).should == 7
- "blablablax".byterindex(/..x/, 9).should == 7
- "blablablax".byterindex(/..x/, 8).should == 7
- "blablablax".byterindex(/..x/, 7).should == 7
-
- not_supported_on :opal do
- "blablabla\n".byterindex(/\Z/, 9).should == 9
- end
+ "blablabla".byterindex(/^/).should == 0
+ not_supported_on :opal do
+ "\nblablabla".byterindex(/^/).should == 1
+ "b\nlablabla".byterindex(/^/).should == 2
end
+ "blablabla".byterindex(/$/).should == 9
- it "starts the search at offset + self.length if offset is negative" do
- str = "blablabla"
+ "blablabla".byterindex(/.l./).should == 6
+ end
- ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
- (-str.length .. -1).each do |offset|
- str.byterindex(needle, offset).should ==
- str.byterindex(needle, offset + str.length)
- end
- end
+ it "starts the search at the given offset" do
+ "blablabla".byterindex(/.{0}/, 5).should == 5
+ "blablabla".byterindex(/.{1}/, 5).should == 5
+ "blablabla".byterindex(/.{2}/, 5).should == 5
+ "blablabla".byterindex(/.{3}/, 5).should == 5
+ "blablabla".byterindex(/.{4}/, 5).should == 5
+
+ "blablabla".byterindex(/.{0}/, 3).should == 3
+ "blablabla".byterindex(/.{1}/, 3).should == 3
+ "blablabla".byterindex(/.{2}/, 3).should == 3
+ "blablabla".byterindex(/.{5}/, 3).should == 3
+ "blablabla".byterindex(/.{6}/, 3).should == 3
+
+ "blablabla".byterindex(/.l./, 0).should == 0
+ "blablabla".byterindex(/.l./, 1).should == 0
+ "blablabla".byterindex(/.l./, 2).should == 0
+ "blablabla".byterindex(/.l./, 3).should == 3
+
+ "blablablax".byterindex(/.x/, 10).should == 8
+ "blablablax".byterindex(/.x/, 9).should == 8
+ "blablablax".byterindex(/.x/, 8).should == 8
+
+ "blablablax".byterindex(/..x/, 10).should == 7
+ "blablablax".byterindex(/..x/, 9).should == 7
+ "blablablax".byterindex(/..x/, 8).should == 7
+ "blablablax".byterindex(/..x/, 7).should == 7
+
+ not_supported_on :opal do
+ "blablabla\n".byterindex(/\Z/, 9).should == 9
end
+ end
- it "returns nil if the substring isn't found" do
- "blablabla".byterindex(/BLA/).should == nil
- "blablabla".byterindex(/.{10}/).should == nil
- "blablablax".byterindex(/.x/, 7).should == nil
- "blablablax".byterindex(/..x/, 6).should == nil
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
- not_supported_on :opal do
- "blablabla".byterindex(/\Z/, 5).should == nil
- "blablabla".byterindex(/\z/, 5).should == nil
- "blablabla\n".byterindex(/\z/, 9).should == nil
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byterindex(needle, offset).should ==
+ str.byterindex(needle, offset + str.length)
end
end
+ end
+
+ it "returns nil if the substring isn't found" do
+ "blablabla".byterindex(/BLA/).should == nil
+ "blablabla".byterindex(/.{10}/).should == nil
+ "blablablax".byterindex(/.x/, 7).should == nil
+ "blablablax".byterindex(/..x/, 6).should == nil
not_supported_on :opal do
- it "supports \\G which matches at the given start offset" do
- "helloYOU.".byterindex(/YOU\G/, 8).should == 5
- "helloYOU.".byterindex(/YOU\G/).should == nil
-
- idx = "helloYOUall!".index("YOU")
- re = /YOU.+\G.+/
- # The # marks where \G will match.
- [
- ["helloYOU#all.", nil],
- ["helloYOUa#ll.", idx],
- ["helloYOUal#l.", idx],
- ["helloYOUall#.", idx],
- ["helloYOUall.#", nil]
- ].each do |i|
- start = i[0].index("#")
- str = i[0].delete("#")
-
- str.byterindex(re, start).should == i[1]
- end
+ "blablabla".byterindex(/\Z/, 5).should == nil
+ "blablabla".byterindex(/\z/, 5).should == nil
+ "blablabla\n".byterindex(/\z/, 9).should == nil
+ end
+ end
+
+ not_supported_on :opal do
+ it "supports \\G which matches at the given start offset" do
+ "helloYOU.".byterindex(/YOU\G/, 8).should == 5
+ "helloYOU.".byterindex(/YOU\G/).should == nil
+
+ idx = "helloYOUall!".index("YOU")
+ re = /YOU.+\G.+/
+ # The # marks where \G will match.
+ [
+ ["helloYOU#all.", nil],
+ ["helloYOUa#ll.", idx],
+ ["helloYOUal#l.", idx],
+ ["helloYOUall#.", idx],
+ ["helloYOUall.#", nil]
+ ].each do |i|
+ start = i[0].index("#")
+ str = i[0].delete("#")
+
+ str.byterindex(re, start).should == i[1]
end
end
+ end
- it "tries to convert start_offset to an integer" do
- obj = mock('5')
- def obj.to_int() 5 end
- "str".byterindex(/../, obj).should == 1
+ it "tries to convert start_offset to an integer" do
+ obj = mock('5')
+ def obj.to_int() 5 end
+ "str".byterindex(/../, obj).should == 1
- obj = mock('5')
- def obj.respond_to?(arg, *) true end
- def obj.method_missing(*args); 5; end
- "str".byterindex(/../, obj).should == 1
- end
+ obj = mock('5')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args); 5; end
+ "str".byterindex(/../, obj).should == 1
+ end
- it "raises a TypeError when given offset is nil" do
- -> { "str".byterindex(/../, nil) }.should raise_error(TypeError)
- end
+ it "raises a TypeError when given offset is nil" do
+ -> { "str".byterindex(/../, nil) }.should raise_error(TypeError)
+ end
- it "returns the reverse byte index of a multibyte character" do
- "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ").should == 12
- "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/).should == 12
- end
+ it "returns the reverse byte index of a multibyte character" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ").should == 12
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/).should == 12
+ end
- it "returns the character index before the finish" do
- "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ", 9).should == 6
- "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/, 9).should == 6
- end
+ it "returns the character index before the finish" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ", 9).should == 6
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/, 9).should == 6
end
end
diff --git a/spec/ruby/core/string/byteslice_spec.rb b/spec/ruby/core/string/byteslice_spec.rb
index 9fe504aeb1..4ad9e8d8f1 100644
--- a/spec/ruby/core/string/byteslice_spec.rb
+++ b/spec/ruby/core/string/byteslice_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
require_relative 'shared/slice'
diff --git a/spec/ruby/core/string/bytesplice_spec.rb b/spec/ruby/core/string/bytesplice_spec.rb
index 5cb3b2c158..2c770e340a 100644
--- a/spec/ruby/core/string/bytesplice_spec.rb
+++ b/spec/ruby/core/string/bytesplice_spec.rb
@@ -3,60 +3,58 @@
require_relative '../../spec_helper'
describe "String#bytesplice" do
- ruby_version_is "3.2" do
- it "raises IndexError when index is less than -bytesize" do
- -> { "hello".bytesplice(-6, 0, "xxx") }.should raise_error(IndexError, "index -6 out of string")
- end
+ it "raises IndexError when index is less than -bytesize" do
+ -> { "hello".bytesplice(-6, 0, "xxx") }.should raise_error(IndexError, "index -6 out of string")
+ end
- it "raises IndexError when index is greater than bytesize" do
- -> { "hello".bytesplice(6, 0, "xxx") }.should raise_error(IndexError, "index 6 out of string")
- end
+ it "raises IndexError when index is greater than bytesize" do
+ -> { "hello".bytesplice(6, 0, "xxx") }.should raise_error(IndexError, "index 6 out of string")
+ end
- it "raises IndexError for negative length" do
- -> { "abc".bytesplice(0, -2, "") }.should raise_error(IndexError, "negative length -2")
- end
+ it "raises IndexError for negative length" do
+ -> { "abc".bytesplice(0, -2, "") }.should raise_error(IndexError, "negative length -2")
+ end
- it "replaces with integer indices" do
- "hello".bytesplice(-5, 0, "xxx").should == "xxxhello"
- "hello".bytesplice(0, 0, "xxx").should == "xxxhello"
- "hello".bytesplice(0, 1, "xxx").should == "xxxello"
- "hello".bytesplice(0, 5, "xxx").should == "xxx"
- "hello".bytesplice(0, 6, "xxx").should == "xxx"
- end
+ it "replaces with integer indices" do
+ "hello".bytesplice(-5, 0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0, 0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0, 1, "xxx").should == "xxxello"
+ "hello".bytesplice(0, 5, "xxx").should == "xxx"
+ "hello".bytesplice(0, 6, "xxx").should == "xxx"
+ end
- it "raises RangeError when range left boundary is less than -bytesize" do
- -> { "hello".bytesplice(-6...-6, "xxx") }.should raise_error(RangeError, "-6...-6 out of range")
- end
+ it "raises RangeError when range left boundary is less than -bytesize" do
+ -> { "hello".bytesplice(-6...-6, "xxx") }.should raise_error(RangeError, "-6...-6 out of range")
+ end
- it "replaces with ranges" do
- "hello".bytesplice(-5...-5, "xxx").should == "xxxhello"
- "hello".bytesplice(0...0, "xxx").should == "xxxhello"
- "hello".bytesplice(0..0, "xxx").should == "xxxello"
- "hello".bytesplice(0...1, "xxx").should == "xxxello"
- "hello".bytesplice(0..1, "xxx").should == "xxxllo"
- "hello".bytesplice(0..-1, "xxx").should == "xxx"
- "hello".bytesplice(0...5, "xxx").should == "xxx"
- "hello".bytesplice(0...6, "xxx").should == "xxx"
- end
+ it "replaces with ranges" do
+ "hello".bytesplice(-5...-5, "xxx").should == "xxxhello"
+ "hello".bytesplice(0...0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0..0, "xxx").should == "xxxello"
+ "hello".bytesplice(0...1, "xxx").should == "xxxello"
+ "hello".bytesplice(0..1, "xxx").should == "xxxllo"
+ "hello".bytesplice(0..-1, "xxx").should == "xxx"
+ "hello".bytesplice(0...5, "xxx").should == "xxx"
+ "hello".bytesplice(0...6, "xxx").should == "xxx"
+ end
- it "raises TypeError when integer index is provided without length argument" do
- -> { "hello".bytesplice(0, "xxx") }.should raise_error(TypeError, "wrong argument type Integer (expected Range)")
- end
+ it "raises TypeError when integer index is provided without length argument" do
+ -> { "hello".bytesplice(0, "xxx") }.should raise_error(TypeError, "wrong argument type Integer (expected Range)")
+ end
- it "replaces on an empty string" do
- "".bytesplice(0, 0, "").should == ""
- "".bytesplice(0, 0, "xxx").should == "xxx"
- end
+ it "replaces on an empty string" do
+ "".bytesplice(0, 0, "").should == ""
+ "".bytesplice(0, 0, "xxx").should == "xxx"
+ end
- it "mutates self" do
- s = "hello"
- s.bytesplice(2, 1, "xxx").should.equal?(s)
- end
+ it "mutates self" do
+ s = "hello"
+ s.bytesplice(2, 1, "xxx").should.equal?(s)
+ end
- it "raises when string is frozen" do
- s = "hello".freeze
- -> { s.bytesplice(2, 1, "xxx") }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"")
- end
+ it "raises when string is frozen" do
+ s = "hello".freeze
+ -> { s.bytesplice(2, 1, "xxx") }.should raise_error(FrozenError, "can't modify frozen String: \"hello\"")
end
ruby_version_is "3.3" do
@@ -134,75 +132,73 @@ describe "String#bytesplice" do
end
describe "String#bytesplice with multibyte characters" do
- ruby_version_is "3.2" do
- it "raises IndexError when index is out of byte size boundary" do
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-16, 0, "xxx") }.should raise_error(IndexError, "index -16 out of string")
- end
+ it "raises IndexError when index is out of byte size boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-16, 0, "xxx") }.should raise_error(IndexError, "index -16 out of string")
+ end
- it "raises IndexError when index is not on a codepoint boundary" do
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(1, 0, "xxx") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
- end
+ it "raises IndexError when index is not on a codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(1, 0, "xxx") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
+ end
- it "raises IndexError when length is not matching the codepoint boundary" do
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 1, "xxx") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 2, "xxx") }.should raise_error(IndexError, "offset 2 does not land on character boundary")
- end
+ it "raises IndexError when length is not matching the codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 1, "xxx") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 2, "xxx") }.should raise_error(IndexError, "offset 2 does not land on character boundary")
+ end
- it "replaces with integer indices" do
- "ã“ã‚“ã«ã¡ã¯".bytesplice(-15, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã¯ã¯").should == "ã“ã¯ã¯ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(15, 0, "xxx").should == "ã“ã‚“ã«ã¡ã¯xxx"
- end
+ it "replaces with integer indices" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã¯ã¯").should == "ã“ã¯ã¯ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(15, 0, "xxx").should == "ã“ã‚“ã«ã¡ã¯xxx"
+ end
- it "replaces with range" do
- "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-16, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0...0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "xxx").should == "xxxã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0...3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0..5, "xxx").should == "xxxã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0..-1, "xxx").should == "xxx"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0...15, "xxx").should == "xxx"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0...18, "xxx").should == "xxx"
- end
+ it "replaces with range" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-16, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..5, "xxx").should == "xxxã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..-1, "xxx").should == "xxx"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...15, "xxx").should == "xxx"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...18, "xxx").should == "xxx"
+ end
- it "treats negative length for range as 0" do
- "ã“ã‚“ã«ã¡ã¯".bytesplice(0...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(3...-100, "xxx").should == "ã“xxxã‚“ã«ã¡ã¯"
- "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
- end
+ it "treats negative length for range as 0" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3...-100, "xxx").should == "ã“xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ end
- it "raises when ranges not match codepoint boundaries" do
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..0, "x") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..1, "x") }.should raise_error(IndexError, "offset 2 does not land on character boundary")
- # Begin is incorrect
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-4..-1, "x") }.should raise_error(IndexError, "offset 11 does not land on character boundary")
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-5..-1, "x") }.should raise_error(IndexError, "offset 10 does not land on character boundary")
- # End is incorrect
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-2, "x") }.should raise_error(IndexError, "offset 14 does not land on character boundary")
- -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-3, "x") }.should raise_error(IndexError, "offset 13 does not land on character boundary")
- end
+ it "raises when ranges not match codepoint boundaries" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..0, "x") }.should raise_error(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..1, "x") }.should raise_error(IndexError, "offset 2 does not land on character boundary")
+ # Begin is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-4..-1, "x") }.should raise_error(IndexError, "offset 11 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-5..-1, "x") }.should raise_error(IndexError, "offset 10 does not land on character boundary")
+ # End is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-2, "x") }.should raise_error(IndexError, "offset 14 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-3, "x") }.should raise_error(IndexError, "offset 13 does not land on character boundary")
+ end
- it "deals with a different encoded argument" do
- s = "ã“ã‚“ã«ã¡ã¯"
- s.encoding.should == Encoding::UTF_8
- sub = "xxxxxx"
- sub.force_encoding(Encoding::US_ASCII)
+ it "deals with a different encoded argument" do
+ s = "ã“ã‚“ã«ã¡ã¯"
+ s.encoding.should == Encoding::UTF_8
+ sub = "xxxxxx"
+ sub.force_encoding(Encoding::US_ASCII)
- result = s.bytesplice(0, 3, sub)
- result.should == "xxxxxxã‚“ã«ã¡ã¯"
- result.encoding.should == Encoding::UTF_8
+ result = s.bytesplice(0, 3, sub)
+ result.should == "xxxxxxã‚“ã«ã¡ã¯"
+ result.encoding.should == Encoding::UTF_8
- s = "xxxxxx"
- s.force_encoding(Encoding::US_ASCII)
- sub = "ã“ã‚“ã«ã¡ã¯"
- sub.encoding.should == Encoding::UTF_8
+ s = "xxxxxx"
+ s.force_encoding(Encoding::US_ASCII)
+ sub = "ã“ã‚“ã«ã¡ã¯"
+ sub.encoding.should == Encoding::UTF_8
- result = s.bytesplice(0, 3, sub)
- result.should == "ã“ã‚“ã«ã¡ã¯xxx"
- result.encoding.should == Encoding::UTF_8
- end
+ result = s.bytesplice(0, 3, sub)
+ result.should == "ã“ã‚“ã«ã¡ã¯xxx"
+ result.encoding.should == Encoding::UTF_8
end
ruby_version_is "3.3" do
diff --git a/spec/ruby/core/string/chilled_string_spec.rb b/spec/ruby/core/string/chilled_string_spec.rb
index 968e4ec1f0..73d055cbdf 100644
--- a/spec/ruby/core/string/chilled_string_spec.rb
+++ b/spec/ruby/core/string/chilled_string_spec.rb
@@ -47,6 +47,14 @@ describe "chilled String" do
input.should == "chilled-mutated"
end
+ it "emits a warning for concatenated strings" do
+ input = "still" "+chilled"
+ -> {
+ input << "-mutated"
+ }.should complain(/literal string will be frozen in the future/)
+ input.should == "still+chilled-mutated"
+ end
+
it "emits a warning on singleton_class creation" do
-> {
"chilled".singleton_class
diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb
index b276d0baa8..12a5bf5892 100644
--- a/spec/ruby/core/string/codepoints_spec.rb
+++ b/spec/ruby/core/string/codepoints_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/codepoints'
require_relative 'shared/each_codepoint_without_block'
diff --git a/spec/ruby/core/string/count_spec.rb b/spec/ruby/core/string/count_spec.rb
index 06ba5a4f0e..e614e901dd 100644
--- a/spec/ruby/core/string/count_spec.rb
+++ b/spec/ruby/core/string/count_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
diff --git a/spec/ruby/core/string/dedup_spec.rb b/spec/ruby/core/string/dedup_spec.rb
index 57d2be2cfd..2b31d80708 100644
--- a/spec/ruby/core/string/dedup_spec.rb
+++ b/spec/ruby/core/string/dedup_spec.rb
@@ -2,7 +2,5 @@ require_relative '../../spec_helper'
require_relative 'shared/dedup'
describe 'String#dedup' do
- ruby_version_is '3.2' do
- it_behaves_like :string_dedup, :dedup
- end
+ it_behaves_like :string_dedup, :dedup
end
diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb
index 33c2141812..46e0aa0f36 100644
--- a/spec/ruby/core/string/modulo_spec.rb
+++ b/spec/ruby/core/string/modulo_spec.rb
@@ -391,16 +391,8 @@ describe "String#%" do
("%c" % 'A').should == "A"
end
- ruby_version_is ""..."3.2" do
- it "raises an exception for multiple character strings as argument for %c" do
- -> { "%c" % 'AA' }.should raise_error(ArgumentError)
- end
- end
-
- ruby_version_is "3.2" do
- it "supports only the first character as argument for %c" do
- ("%c" % 'AA').should == "A"
- end
+ it "supports only the first character as argument for %c" do
+ ("%c" % 'AA').should == "A"
end
it "calls to_str on argument for %c formats" do
diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb
index 6d46eb590e..55773f5238 100644
--- a/spec/ruby/core/string/rstrip_spec.rb
+++ b/spec/ruby/core/string/rstrip_spec.rb
@@ -68,27 +68,13 @@ describe "String#rstrip!" do
-> { "".freeze.rstrip! }.should raise_error(FrozenError)
end
- ruby_version_is "3.2" do
- it "raises an Encoding::CompatibilityError if the last non-space codepoint is invalid" do
- s = "abc\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- -> { s.rstrip! }.should raise_error(Encoding::CompatibilityError)
+ it "raises an Encoding::CompatibilityError if the last non-space codepoint is invalid" do
+ s = "abc\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ -> { s.rstrip! }.should raise_error(Encoding::CompatibilityError)
- s = "abc\xDF ".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- -> { s.rstrip! }.should raise_error(Encoding::CompatibilityError)
- end
- end
-
- ruby_version_is ""..."3.2" do
- it "raises an ArgumentError if the last non-space codepoint is invalid" do
- s = "abc\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- -> { s.rstrip! }.should raise_error(ArgumentError)
-
- s = "abc\xDF ".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- -> { s.rstrip! }.should raise_error(ArgumentError)
- end
+ s = "abc\xDF ".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should be_false
+ -> { s.rstrip! }.should raise_error(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/shared/codepoints.rb b/spec/ruby/core/string/shared/codepoints.rb
index f71263054a..1c28ba3d5e 100644
--- a/spec/ruby/core/string/shared/codepoints.rb
+++ b/spec/ruby/core/string/shared/codepoints.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_codepoints, shared: true do
it "returns self" do
s = "foo"
diff --git a/spec/ruby/core/string/shared/each_codepoint_without_block.rb b/spec/ruby/core/string/shared/each_codepoint_without_block.rb
index 31b4c02c9c..c88e5c54c7 100644
--- a/spec/ruby/core/string/shared/each_codepoint_without_block.rb
+++ b/spec/ruby/core/string/shared/each_codepoint_without_block.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_each_codepoint_without_block, shared: true do
describe "when no block is given" do
it "returns an Enumerator" do
diff --git a/spec/ruby/core/string/shared/eql.rb b/spec/ruby/core/string/shared/eql.rb
index 845b0a3e15..d5af337d53 100644
--- a/spec/ruby/core/string/shared/eql.rb
+++ b/spec/ruby/core/string/shared/eql.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb
index b69a394875..7c68345f10 100644
--- a/spec/ruby/core/string/shared/succ.rb
+++ b/spec/ruby/core/string/shared/succ.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_succ, shared: true do
it "returns an empty string for empty strings" do
"".send(@method).should == ""
diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb
index 4ea238e6b5..981d480684 100644
--- a/spec/ruby/core/string/squeeze_spec.rb
+++ b/spec/ruby/core/string/squeeze_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
# frozen_string_literal: false
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
diff --git a/spec/ruby/core/string/to_c_spec.rb b/spec/ruby/core/string/to_c_spec.rb
index 4864a98e39..1813890e72 100644
--- a/spec/ruby/core/string/to_c_spec.rb
+++ b/spec/ruby/core/string/to_c_spec.rb
@@ -13,9 +13,7 @@ describe "String#to_c" do
it "ignores trailing garbage" do
'79+4iruby'.to_c.should == Complex(79, 4)
- ruby_bug "[Bug #19087]", ""..."3.2" do
- '7__9+4__0i'.to_c.should == Complex(7, 0)
- end
+ '7__9+4__0i'.to_c.should == Complex(7, 0)
end
context "it treats special float value strings as characters" do
@@ -43,15 +41,13 @@ describe "String#to_c" do
}.should raise_error(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
end
- ruby_version_is "3.2" do
- it "treats a sequence of underscores as an end of Complex string" do
- "5+3_1i".to_c.should == Complex(5, 31)
- "5+3__1i".to_c.should == Complex(5)
- "5+3___1i".to_c.should == Complex(5)
+ it "treats a sequence of underscores as an end of Complex string" do
+ "5+3_1i".to_c.should == Complex(5, 31)
+ "5+3__1i".to_c.should == Complex(5)
+ "5+3___1i".to_c.should == Complex(5)
- "12_3".to_c.should == Complex(123)
- "12__3".to_c.should == Complex(12)
- "12___3".to_c.should == Complex(12)
- end
+ "12_3".to_c.should == Complex(123)
+ "12__3".to_c.should == Complex(12)
+ "12___3".to_c.should == Complex(12)
end
end
diff --git a/spec/ruby/core/string/to_f_spec.rb b/spec/ruby/core/string/to_f_spec.rb
index 72e2a90b13..abfd2517b6 100644
--- a/spec/ruby/core/string/to_f_spec.rb
+++ b/spec/ruby/core/string/to_f_spec.rb
@@ -120,11 +120,23 @@ describe "String#to_f" do
"\3771.2".b.to_f.should == 0
end
- ruby_version_is "3.2" do
+ ruby_version_is "3.2.3" do
it "raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding" do
-> {
'1.2'.encode("UTF-16").to_f
}.should raise_error(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
end
end
+
+ it "allows String representation without a fractional part" do
+ "1.".to_f.should == 1.0
+ "+1.".to_f.should == 1.0
+ "-1.".to_f.should == -1.0
+ "1.e+0".to_f.should == 1.0
+ "1.e+0".to_f.should == 1.0
+
+ ruby_bug "#20705", ""..."3.4" do
+ "1.e-2".to_f.should be_close(0.01, TOLERANCE)
+ end
+ end
end
diff --git a/spec/ruby/core/string/unpack/a_spec.rb b/spec/ruby/core/string/unpack/a_spec.rb
index 4002ece697..a68e842e15 100644
--- a/spec/ruby/core/string/unpack/a_spec.rb
+++ b/spec/ruby/core/string/unpack/a_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/at_spec.rb b/spec/ruby/core/string/unpack/at_spec.rb
index 70b2389d69..d4133c23ee 100644
--- a/spec/ruby/core/string/unpack/at_spec.rb
+++ b/spec/ruby/core/string/unpack/at_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/b_spec.rb b/spec/ruby/core/string/unpack/b_spec.rb
index 23d93a8aea..b088f901fc 100644
--- a/spec/ruby/core/string/unpack/b_spec.rb
+++ b/spec/ruby/core/string/unpack/b_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/c_spec.rb b/spec/ruby/core/string/unpack/c_spec.rb
index c2bf813954..1e9548fb82 100644
--- a/spec/ruby/core/string/unpack/c_spec.rb
+++ b/spec/ruby/core/string/unpack/c_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/comment_spec.rb b/spec/ruby/core/string/unpack/comment_spec.rb
index e18a53df3c..050d2b7fc0 100644
--- a/spec/ruby/core/string/unpack/comment_spec.rb
+++ b/spec/ruby/core/string/unpack/comment_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/core/string/unpack/h_spec.rb b/spec/ruby/core/string/unpack/h_spec.rb
index 19c4d63664..535836087d 100644
--- a/spec/ruby/core/string/unpack/h_spec.rb
+++ b/spec/ruby/core/string/unpack/h_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/m_spec.rb b/spec/ruby/core/string/unpack/m_spec.rb
index c551c755d1..357987a053 100644
--- a/spec/ruby/core/string/unpack/m_spec.rb
+++ b/spec/ruby/core/string/unpack/m_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/shared/basic.rb b/spec/ruby/core/string/unpack/shared/basic.rb
index b37a447683..734630bda0 100644
--- a/spec/ruby/core/string/unpack/shared/basic.rb
+++ b/spec/ruby/core/string/unpack/shared/basic.rb
@@ -9,12 +9,19 @@ describe :string_unpack_basic, shared: true do
"abc".unpack(d).should be_an_instance_of(Array)
end
+ ruby_version_is ""..."3.3" do
+ it "warns about using an unknown directive" do
+ -> { "abcdefgh".unpack("a R" + unpack_format) }.should complain(/unknown unpack directive 'R' in 'a R#{unpack_format}'/)
+ -> { "abcdefgh".unpack("a 0" + unpack_format) }.should complain(/unknown unpack directive '0' in 'a 0#{unpack_format}'/)
+ -> { "abcdefgh".unpack("a :" + unpack_format) }.should complain(/unknown unpack directive ':' in 'a :#{unpack_format}'/)
+ end
+ end
+
ruby_version_is "3.3" do
- # https://bugs.ruby-lang.org/issues/19150
- it 'raise ArgumentError when a directive is unknown' do
- -> { "abcdefgh".unpack("a R" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive 'R'/)
- -> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive '0'/)
- -> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, /unknown unpack directive ':'/)
+ it "raises ArgumentError when a directive is unknown" do
+ -> { "abcdefgh".unpack("a K" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'")
+ -> { "abcdefgh".unpack("a 0" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'")
+ -> { "abcdefgh".unpack("a :" + unpack_format) }.should raise_error(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'")
end
end
end
diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb
index 93282bf4c9..b31c2c8bdc 100644
--- a/spec/ruby/core/string/unpack/shared/float.rb
+++ b/spec/ruby/core/string/unpack/shared/float.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_unpack_float_le, shared: true do
it "decodes one float for a single format character" do
diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb
index d71a2cf00d..d3934753ba 100644
--- a/spec/ruby/core/string/unpack/shared/integer.rb
+++ b/spec/ruby/core/string/unpack/shared/integer.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_unpack_16bit_le, shared: true do
it "decodes one short for a single format character" do
diff --git a/spec/ruby/core/string/unpack/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb
index 456abee784..68c8f6f11c 100644
--- a/spec/ruby/core/string/unpack/u_spec.rb
+++ b/spec/ruby/core/string/unpack/u_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/w_spec.rb b/spec/ruby/core/string/unpack/w_spec.rb
index 6a1cff1965..7d3533ccae 100644
--- a/spec/ruby/core/string/unpack/w_spec.rb
+++ b/spec/ruby/core/string/unpack/w_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/x_spec.rb b/spec/ruby/core/string/unpack/x_spec.rb
index 5e248de77e..2926ebbe0f 100644
--- a/spec/ruby/core/string/unpack/x_spec.rb
+++ b/spec/ruby/core/string/unpack/x_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack/z_spec.rb b/spec/ruby/core/string/unpack/z_spec.rb
index ce8da4b29e..1030390550 100644
--- a/spec/ruby/core/string/unpack/z_spec.rb
+++ b/spec/ruby/core/string/unpack/z_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
diff --git a/spec/ruby/core/string/unpack1_spec.rb b/spec/ruby/core/string/unpack1_spec.rb
index 3b3b879f75..cfb47fe695 100644
--- a/spec/ruby/core/string/unpack1_spec.rb
+++ b/spec/ruby/core/string/unpack1_spec.rb
@@ -31,4 +31,17 @@ describe "String#unpack1" do
it "raises an ArgumentError when the offset is larger than the string bytesize" do
-> { "a".unpack1("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string")
end
+
+ context "with format 'm0'" do
+ # unpack1("m0") takes a special code path that calls Pack.unpackBase46Strict instead of Pack.unpack_m,
+ # which is why we repeat the tests for unpack("m0") here.
+
+ it "decodes base64" do
+ "dGVzdA==".unpack1("m0").should == "test"
+ end
+
+ it "raises an ArgumentError for an invalid base64 character" do
+ -> { "dGV%zdA==".unpack1("m0") }.should raise_error(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/string/unpack_spec.rb b/spec/ruby/core/string/unpack_spec.rb
index 083484ebe9..a0abf8fa99 100644
--- a/spec/ruby/core/string/unpack_spec.rb
+++ b/spec/ruby/core/string/unpack_spec.rb
@@ -26,7 +26,7 @@ describe "String#unpack" do
"a".unpack("C", offset: 1).should == [nil]
end
- it "raises an ArgumentError when the offset is larget than the string" do
+ it "raises an ArgumentError when the offset is larger than the string" do
-> { "a".unpack("C", offset: 2) }.should raise_error(ArgumentError, "offset outside of string")
end
end
diff --git a/spec/ruby/core/string/uplus_spec.rb b/spec/ruby/core/string/uplus_spec.rb
index c0b0c49ede..20767bcc01 100644
--- a/spec/ruby/core/string/uplus_spec.rb
+++ b/spec/ruby/core/string/uplus_spec.rb
@@ -13,14 +13,48 @@ describe 'String#+@' do
output.should == 'foobar'
end
- it 'returns self if the String is not frozen' do
- input = 'foo'
+ it 'returns a mutable String itself' do
+ input = String.new("foo")
output = +input
- output.equal?(input).should == true
+ output.should.equal?(input)
+
+ input << "bar"
+ output.should == "foobar"
+ end
+
+ context 'if file has "frozen_string_literal: true" magic comment' do
+ it 'returns mutable copy of a literal' do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
+ end
end
- it 'returns mutable copy despite freeze-magic-comment in file' do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
+ context 'if file has "frozen_string_literal: false" magic comment' do
+ it 'returns literal string itself' do
+ input = 'foo'
+ output = +input
+
+ output.equal?(input).should == true
+ end
+ end
+
+ context 'if file has no frozen_string_literal magic comment' do
+ ruby_version_is ''...'3.4' do
+ it 'returns literal string itself' do
+ eval(<<~RUBY).should == true
+ s = "foo"
+ s.equal?(+s)
+ RUBY
+ end
+ end
+
+ ruby_version_is '3.4' do
+ it 'returns mutable copy of a literal' do
+ eval(<<~RUBY).should == false
+ s = "foo"
+ s.equal?(+s)
+ RUBY
+ end
+ end
end
end
diff --git a/spec/ruby/core/struct/constants_spec.rb b/spec/ruby/core/struct/constants_spec.rb
index fa61a4b912..7e8af1a211 100644
--- a/spec/ruby/core/struct/constants_spec.rb
+++ b/spec/ruby/core/struct/constants_spec.rb
@@ -1,15 +1,13 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Struct::Group" do
- it "is no longer defined" do
- Struct.should_not.const_defined?(:Group)
- end
+describe "Struct::Group" do
+ it "is no longer defined" do
+ Struct.should_not.const_defined?(:Group)
end
+end
- describe "Struct::Passwd" do
- it "is no longer defined" do
- Struct.should_not.const_defined?(:Passwd)
- end
+describe "Struct::Passwd" do
+ it "is no longer defined" do
+ Struct.should_not.const_defined?(:Passwd)
end
end
diff --git a/spec/ruby/core/struct/deconstruct_keys_spec.rb b/spec/ruby/core/struct/deconstruct_keys_spec.rb
index cd05aee056..e16b50f930 100644
--- a/spec/ruby/core/struct/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/struct/deconstruct_keys_spec.rb
@@ -43,6 +43,13 @@ describe "Struct#deconstruct_keys" do
s.deconstruct_keys([-1] ).should == {-1 => 30}
end
+ it "ignores incorrect position numbers" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(10, 20, 30)
+
+ s.deconstruct_keys([0, 3]).should == {0 => 10}
+ end
+
it "support mixing attribute names and argument position numbers" do
struct = Struct.new(:x, :y)
s = struct.new(1, 2)
@@ -80,7 +87,29 @@ describe "Struct#deconstruct_keys" do
obj.deconstruct_keys(nil).should == {x: 1, y: 2}
end
- it "raises TypeError if index is not a String, a Symbol and not convertible to Integer " do
+ it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return(1)
+
+ s.deconstruct_keys([key]).should == { key => 2 }
+ end
+
+ it "raises a TypeError if the conversion with #to_int does not return an Integer" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return("not an Integer")
+
+ -> {
+ s.deconstruct_keys([key])
+ }.should raise_error(TypeError, /can't convert MockObject to Integer/)
+ end
+
+ it "raises TypeError if index is not a String, a Symbol and not convertible to Integer" do
struct = Struct.new(:x, :y)
s = struct.new(1, 2)
diff --git a/spec/ruby/core/struct/element_set_spec.rb b/spec/ruby/core/struct/element_set_spec.rb
index 6ba7b081a9..0a0e34a5ee 100644
--- a/spec/ruby/core/struct/element_set_spec.rb
+++ b/spec/ruby/core/struct/element_set_spec.rb
@@ -26,4 +26,11 @@ describe "Struct#[]=" do
-> { car[-4] = true }.should raise_error(IndexError)
-> { car[Object.new] = true }.should raise_error(TypeError)
end
+
+ it "raises a FrozenError on a frozen struct" do
+ car = StructClasses::Car.new('Ford', 'Ranger')
+ car.freeze
+
+ -> { car[:model] = 'Escape' }.should raise_error(FrozenError)
+ end
end
diff --git a/spec/ruby/core/struct/initialize_spec.rb b/spec/ruby/core/struct/initialize_spec.rb
index 1861bcafb0..06055594d5 100644
--- a/spec/ruby/core/struct/initialize_spec.rb
+++ b/spec/ruby/core/struct/initialize_spec.rb
@@ -41,21 +41,11 @@ describe "Struct#initialize" do
StructClasses::SubclassX.new(:y).new.key.should == :value
end
- ruby_version_is ""..."3.2" do
- it "warns about passing only keyword arguments" do
- -> {
- StructClasses::Ruby.new(version: "3.1", platform: "OS")
- }.should complain(/warning: Passing only keyword arguments/)
- end
- end
+ it "can be initialized with keyword arguments" do
+ positional_args = StructClasses::Ruby.new("3.2", "OS")
+ keyword_args = StructClasses::Ruby.new(version: "3.2", platform: "OS")
- ruby_version_is "3.2" do
- it "can be initialized with keyword arguments" do
- positional_args = StructClasses::Ruby.new("3.2", "OS")
- keyword_args = StructClasses::Ruby.new(version: "3.2", platform: "OS")
-
- positional_args.version.should == keyword_args.version
- positional_args.platform.should == keyword_args.platform
- end
+ positional_args.version.should == keyword_args.version
+ positional_args.platform.should == keyword_args.platform
end
end
diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb
index 73e88a81c1..1d35de7b87 100644
--- a/spec/ruby/core/struct/new_spec.rb
+++ b/spec/ruby/core/struct/new_spec.rb
@@ -73,20 +73,8 @@ describe "Struct.new" do
-> { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError)
end
- ruby_version_is ""..."3.2" do
- it "raises a TypeError or ArgumentError if passed a Hash with an unknown key" do
- # CRuby < 3.2 raises ArgumentError: unknown keyword: :name, but that seems a bug:
- # https://bugs.ruby-lang.org/issues/18632
- -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(StandardError) { |e|
- [ArgumentError, TypeError].should.include?(e.class)
- }
- end
- end
-
- ruby_version_is "3.2" do
- it "raises a TypeError if passed a Hash with an unknown key" do
- -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed a Hash with an unknown key" do
+ -> { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError)
end
ruby_version_is ""..."3.3" do
@@ -166,16 +154,43 @@ describe "Struct.new" do
-> { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
end
- ruby_version_is '3.2' do
- it "accepts keyword arguments to initialize" do
- type = Struct.new(:args)
+ it "accepts keyword arguments to initialize" do
+ type = Struct.new(:args)
+
+ obj = type.new(args: 42)
+ obj2 = type.new(42)
- obj = type.new(args: 42)
- obj2 = type.new(42)
+ obj.should == obj2
+ obj.args.should == 42
+ obj2.args.should == 42
+ end
+
+ context "given positional and keyword arguments" do
+ it "treats keyword arguments as a positional parameter" do
+ type = Struct.new(:a, :b)
+ s = type.new("a", b: "b")
+ s.a.should == "a"
+ s.b.should == {b: "b"}
+
+ type = Struct.new(:a, :b, :c)
+ s = type.new("a", b: "b", c: "c")
+ s.a.should == "a"
+ s.b.should == {b: "b", c: "c"}
+ s.c.should == nil
+ end
+
+ it "ignores empty keyword arguments" do
+ type = Struct.new(:a, :b)
+ h = {}
+ s = type.new("a", **h)
+
+ s.a.should == "a"
+ s.b.should == nil
+ end
- obj.should == obj2
- obj.args.should == 42
- obj2.args.should == 42
+ it "raises ArgumentError when all struct attribute values are specified" do
+ type = Struct.new(:a, :b)
+ -> { type.new("a", "b", c: "c") }.should raise_error(ArgumentError, "struct size differs")
end
end
end
diff --git a/spec/ruby/core/struct/struct_spec.rb b/spec/ruby/core/struct/struct_spec.rb
index 8817dc1a58..1b6a4488ce 100644
--- a/spec/ruby/core/struct/struct_spec.rb
+++ b/spec/ruby/core/struct/struct_spec.rb
@@ -33,6 +33,13 @@ describe "Struct anonymous class instance methods" do
car['model'].should == 'F150'
car[1].should == 'F150'
end
+
+ it "writer methods raise a FrozenError on a frozen struct" do
+ car = StructClasses::Car.new('Ford', 'Ranger')
+ car.freeze
+
+ -> { car.model = 'Escape' }.should raise_error(FrozenError)
+ end
end
describe "Struct subclasses" do
diff --git a/spec/ruby/core/symbol/inspect_spec.rb b/spec/ruby/core/symbol/inspect_spec.rb
index 6dbb36c2ad..df4566c48e 100644
--- a/spec/ruby/core/symbol/inspect_spec.rb
+++ b/spec/ruby/core/symbol/inspect_spec.rb
@@ -6,7 +6,7 @@ describe "Symbol#inspect" do
:fred? => ":fred?",
:fred! => ":fred!",
:BAD! => ":BAD!",
- :_BAD! => ":_BAD!",
+ :_BAD! => ":_BAD!",
:$ruby => ":$ruby",
:@ruby => ":@ruby",
:@@ruby => ":@@ruby",
@@ -66,9 +66,9 @@ describe "Symbol#inspect" do
:~ => ":~",
:| => ":|",
- :"!" => [":\"!\"", ":!" ],
- :"!=" => [":\"!=\"", ":!="],
- :"!~" => [":\"!~\"", ":!~"],
+ :"!" => ":!",
+ :"!=" => ":!=",
+ :"!~" => ":!~",
:"\$" => ":\"$\"", # for justice!
:"&&" => ":\"&&\"",
:"'" => ":\"\'\"",
@@ -96,10 +96,15 @@ describe "Symbol#inspect" do
:"foo " => ":\"foo \"",
:" foo" => ":\" foo\"",
:" " => ":\" \"",
+
+ :"ê" => [":ê", ":\"\\u00EA\""],
+ :"测" => [":测", ":\"\\u6D4B\""],
+ :"🦊" => [":🦊", ":\"\\u{1F98A}\""],
}
+ expected_by_encoding = Encoding::default_external == Encoding::UTF_8 ? 0 : 1
symbols.each do |input, expected|
- expected = expected[1] if expected.is_a?(Array)
+ expected = expected[expected_by_encoding] if expected.is_a?(Array)
it "returns self as a symbol literal for #{expected}" do
input.inspect.should == expected
end
diff --git a/spec/ruby/core/symbol/shared/id2name.rb b/spec/ruby/core/symbol/shared/id2name.rb
index d012b7634e..00a9c7d7dc 100644
--- a/spec/ruby/core/symbol/shared/id2name.rb
+++ b/spec/ruby/core/symbol/shared/id2name.rb
@@ -13,4 +13,18 @@ describe :symbol_id2name, shared: true do
symbol.send(@method).encoding.should == Encoding::US_ASCII
end
+
+ ruby_version_is "3.4" do
+ it "warns about mutating returned string" do
+ -> { :bad!.send(@method).upcase! }.should complain(/warning: string returned by :bad!.to_s will be frozen in the future/)
+ end
+
+ it "does not warn about mutation when Warning[:deprecated] is false" do
+ deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ -> { :bad!.send(@method).upcase! }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb
index 54eccdba11..def5d6d344 100644
--- a/spec/ruby/core/symbol/to_proc_spec.rb
+++ b/spec/ruby/core/symbol/to_proc_spec.rb
@@ -27,31 +27,29 @@ describe "Symbol#to_proc" do
pr.parameters.should == [[:req], [:rest]]
end
- ruby_version_is "3.2" do
- it "only calls public methods" do
- body = proc do
- public def pub; @a << :pub end
- protected def pro; @a << :pro end
- private def pri; @a << :pri end
- attr_reader :a
- end
+ it "only calls public methods" do
+ body = proc do
+ public def pub; @a << :pub end
+ protected def pro; @a << :pro end
+ private def pri; @a << :pri end
+ attr_reader :a
+ end
- @a = []
- singleton_class.class_eval(&body)
- tap(&:pub)
- proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/)
- proc{tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/)
- @a.should == [:pub]
+ @a = []
+ singleton_class.class_eval(&body)
+ tap(&:pub)
+ proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/)
+ proc{tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/)
+ @a.should == [:pub]
- @a = []
- c = Class.new(&body)
- o = c.new
- o.instance_variable_set(:@a, [])
- o.tap(&:pub)
- proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/)
- proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/)
- o.a.should == [:pub]
- end
+ @a = []
+ c = Class.new(&body)
+ o = c.new
+ o.instance_variable_set(:@a, [])
+ o.tap(&:pub)
+ proc{tap(&:pro)}.should raise_error(NoMethodError, /protected method [`']pro' called/)
+ proc{o.tap(&:pri)}.should raise_error(NoMethodError, /private method [`']pri' called/)
+ o.a.should == [:pub]
end
it "raises an ArgumentError when calling #call on the Proc without receiver" do
diff --git a/spec/ruby/core/thread/each_caller_location_spec.rb b/spec/ruby/core/thread/each_caller_location_spec.rb
index 29c271789b..aa7423675b 100644
--- a/spec/ruby/core/thread/each_caller_location_spec.rb
+++ b/spec/ruby/core/thread/each_caller_location_spec.rb
@@ -1,49 +1,47 @@
require_relative '../../spec_helper'
describe "Thread.each_caller_location" do
- ruby_version_is "3.2" do
- it "iterates through the current execution stack and matches caller_locations content and type" do
- ScratchPad.record []
- Thread.each_caller_location { |l| ScratchPad << l; }
+ it "iterates through the current execution stack and matches caller_locations content and type" do
+ ScratchPad.record []
+ Thread.each_caller_location { |l| ScratchPad << l; }
- ScratchPad.recorded.map(&:to_s).should == caller_locations.map(&:to_s)
- ScratchPad.recorded[0].should be_kind_of(Thread::Backtrace::Location)
- end
+ ScratchPad.recorded.map(&:to_s).should == caller_locations.map(&:to_s)
+ ScratchPad.recorded[0].should be_kind_of(Thread::Backtrace::Location)
+ end
- it "returns subset of 'Thread.to_enum(:each_caller_location)' locations" do
- ar = []
- ecl = Thread.each_caller_location { |x| ar << x }
+ it "returns subset of 'Thread.to_enum(:each_caller_location)' locations" do
+ ar = []
+ ecl = Thread.each_caller_location { |x| ar << x }
- (ar.map(&:to_s) - Thread.to_enum(:each_caller_location).to_a.map(&:to_s)).should.empty?
- end
+ (ar.map(&:to_s) - Thread.to_enum(:each_caller_location).to_a.map(&:to_s)).should.empty?
+ end
- it "stops the backtrace iteration if 'break' occurs" do
- i = 0
- ar = []
- ecl = Thread.each_caller_location do |x|
- ar << x
- i += 1
- break x if i == 2
- end
-
- ar.map(&:to_s).should == caller_locations(1, 2).map(&:to_s)
- ecl.should be_kind_of(Thread::Backtrace::Location)
+ it "stops the backtrace iteration if 'break' occurs" do
+ i = 0
+ ar = []
+ ecl = Thread.each_caller_location do |x|
+ ar << x
+ i += 1
+ break x if i == 2
end
- it "returns nil" do
- Thread.each_caller_location {}.should == nil
- end
+ ar.map(&:to_s).should == caller_locations(1, 2).map(&:to_s)
+ ecl.should be_kind_of(Thread::Backtrace::Location)
+ end
- it "raises LocalJumpError when called without a block" do
- -> {
- Thread.each_caller_location
- }.should raise_error(LocalJumpError, "no block given")
- end
+ it "returns nil" do
+ Thread.each_caller_location {}.should == nil
+ end
- it "doesn't accept keyword arguments" do
- -> {
- Thread.each_caller_location(12, foo: 10) {}
- }.should raise_error(ArgumentError);
- end
+ it "raises LocalJumpError when called without a block" do
+ -> {
+ Thread.each_caller_location
+ }.should raise_error(LocalJumpError, "no block given")
+ end
+
+ it "doesn't accept keyword arguments" do
+ -> {
+ Thread.each_caller_location(12, foo: 10) {}
+ }.should raise_error(ArgumentError);
end
end
diff --git a/spec/ruby/core/thread/fixtures/classes.rb b/spec/ruby/core/thread/fixtures/classes.rb
index 23a090feb0..7c485660a8 100644
--- a/spec/ruby/core/thread/fixtures/classes.rb
+++ b/spec/ruby/core/thread/fixtures/classes.rb
@@ -6,6 +6,31 @@ module ThreadSpecs
end
end
+ class NewThreadToRaise
+ def self.raise(*args, **kwargs, &block)
+ thread = Thread.new do
+ Thread.current.report_on_exception = false
+
+ if block_given?
+ block.call do
+ sleep
+ end
+ else
+ sleep
+ end
+ end
+
+ Thread.pass until thread.stop?
+
+ thread.raise(*args, **kwargs)
+
+ thread.join
+ ensure
+ thread.kill if thread.alive?
+ Thread.pass while thread.alive? # Thread#kill may not terminate a thread immediately so it may be detected as a leaked one
+ end
+ end
+
class Status
attr_reader :thread, :inspect, :status, :to_s
def initialize(thread)
diff --git a/spec/ruby/core/thread/raise_spec.rb b/spec/ruby/core/thread/raise_spec.rb
index 49323cf270..b473eabd42 100644
--- a/spec/ruby/core/thread/raise_spec.rb
+++ b/spec/ruby/core/thread/raise_spec.rb
@@ -3,6 +3,9 @@ require_relative 'fixtures/classes'
require_relative '../../shared/kernel/raise'
describe "Thread#raise" do
+ it_behaves_like :kernel_raise, :raise, ThreadSpecs::NewThreadToRaise
+ it_behaves_like :kernel_raise_across_contexts, :raise, ThreadSpecs::NewThreadToRaise
+
it "ignores dead threads and returns nil" do
t = Thread.new { :dead }
Thread.pass while t.alive?
diff --git a/spec/ruby/core/time/_dump_spec.rb b/spec/ruby/core/time/_dump_spec.rb
index 4dc1c43cd2..852f9a07ab 100644
--- a/spec/ruby/core/time/_dump_spec.rb
+++ b/spec/ruby/core/time/_dump_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
describe "Time#_dump" do
diff --git a/spec/ruby/core/time/_load_spec.rb b/spec/ruby/core/time/_load_spec.rb
index bb0d705bbc..30899de262 100644
--- a/spec/ruby/core/time/_load_spec.rb
+++ b/spec/ruby/core/time/_load_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
describe "Time._load" do
diff --git a/spec/ruby/core/time/deconstruct_keys_spec.rb b/spec/ruby/core/time/deconstruct_keys_spec.rb
index ee17e7dbd4..b5cfdaa93f 100644
--- a/spec/ruby/core/time/deconstruct_keys_spec.rb
+++ b/spec/ruby/core/time/deconstruct_keys_spec.rb
@@ -1,45 +1,43 @@
require_relative '../../spec_helper'
-ruby_version_is "3.2" do
- describe "Time#deconstruct_keys" do
- it "returns whole hash for nil as an argument" do
- d = Time.utc(2022, 10, 5, 13, 30)
- res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
- min: 30, sec: 0, subsec: 0, dst: false, zone: "UTC" }
- d.deconstruct_keys(nil).should == res
- end
-
- it "returns only specified keys" do
- d = Time.utc(2022, 10, 5, 13, 39)
- d.deconstruct_keys([:zone, :subsec]).should == { zone: "UTC", subsec: 0 }
- end
-
- it "requires one argument" do
- -> {
- Time.new(2022, 10, 5, 13, 30).deconstruct_keys
- }.should raise_error(ArgumentError)
- end
-
- it "it raises error when argument is neither nil nor array" do
- d = Time.new(2022, 10, 5, 13, 30)
-
- -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
- -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
- -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
- -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
- end
-
- it "returns {} when passed []" do
- Time.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
- end
-
- it "ignores non-Symbol keys" do
- Time.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
- end
-
- it "ignores not existing Symbol keys and processes keys after the first non-existing one" do
- d = Time.utc(2022, 10, 5, 13, 30)
- d.deconstruct_keys([:year, :a, :month, :b, :day]).should == { year: 2022, month: 10, day: 5 }
- end
+describe "Time#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = Time.utc(2022, 10, 5, 13, 30)
+ res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
+ min: 30, sec: 0, subsec: 0, dst: false, zone: "UTC" }
+ d.deconstruct_keys(nil).should == res
+ end
+
+ it "returns only specified keys" do
+ d = Time.utc(2022, 10, 5, 13, 39)
+ d.deconstruct_keys([:zone, :subsec]).should == { zone: "UTC", subsec: 0 }
+ end
+
+ it "requires one argument" do
+ -> {
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys
+ }.should raise_error(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = Time.new(2022, 10, 5, 13, 30)
+
+ -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys and processes keys after the first non-existing one" do
+ d = Time.utc(2022, 10, 5, 13, 30)
+ d.deconstruct_keys([:year, :a, :month, :b, :day]).should == { year: 2022, month: 10, day: 5 }
end
end
diff --git a/spec/ruby/core/time/minus_spec.rb b/spec/ruby/core/time/minus_spec.rb
index 8449778465..9182d99652 100644
--- a/spec/ruby/core/time/minus_spec.rb
+++ b/spec/ruby/core/time/minus_spec.rb
@@ -109,7 +109,7 @@ describe "Time#-" do
it "does not return a subclass instance" do
c = Class.new(Time)
- x = c.now + 1
+ x = c.now - 1
x.should be_an_instance_of(Time)
end
diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb
index 0fd48640d4..dc3ccbdc00 100644
--- a/spec/ruby/core/time/new_spec.rb
+++ b/spec/ruby/core/time/new_spec.rb
@@ -467,258 +467,286 @@ describe "Time.new with a timezone argument" do
end
end
- ruby_version_is "3.2" do
- describe "Time.new with a String argument" do
- it "parses an ISO-8601 like format" do
- t = Time.utc(2020, 12, 24, 15, 56, 17)
-
- Time.new("2020-12-24T15:56:17Z").should == t
- Time.new("2020-12-25 00:56:17 +09:00").should == t
- Time.new("2020-12-25 00:57:47 +09:01:30").should == t
- Time.new("2020-12-25 00:56:17 +0900").should == t
- Time.new("2020-12-25 00:57:47 +090130").should == t
- Time.new("2020-12-25T00:56:17+09:00").should == t
-
- Time.new("2020-12-25T00:56:17.123456+09:00").should == Time.utc(2020, 12, 24, 15, 56, 17, 123456)
- end
+ describe "Time.new with a String argument" do
+ it "parses an ISO-8601 like format" do
+ t = Time.utc(2020, 12, 24, 15, 56, 17)
- it "accepts precision keyword argument and truncates specified digits of sub-second part" do
- Time.new("2021-12-25 00:00:00.123456789876 +09:00").subsec.should == 0.123456789r
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: nil).subsec.should == 0.123456789876r
- Time.new("2021-12-25 00:00:00 +09:00", precision: 0).subsec.should == 0
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: -1).subsec.should == 0.123456789876r
- end
+ Time.new("2020-12-24T15:56:17Z").should == t
+ Time.new("2020-12-25 00:56:17 +09:00").should == t
+ Time.new("2020-12-25 00:57:47 +09:01:30").should == t
+ Time.new("2020-12-25 00:56:17 +0900").should == t
+ Time.new("2020-12-25 00:57:47 +090130").should == t
+ Time.new("2020-12-25T00:56:17+09:00").should == t
- it "returns Time in local timezone if not provided in the String argument" do
- Time.new("2021-12-25 00:00:00").zone.should == Time.new(2021, 12, 25).zone
- Time.new("2021-12-25 00:00:00").utc_offset.should == Time.new(2021, 12, 25).utc_offset
- end
+ Time.new("2020-12-25T00:56:17.123456+09:00").should == Time.utc(2020, 12, 24, 15, 56, 17, 123456)
+ end
- it "returns Time in timezone specified in the String argument" do
- Time.new("2021-12-25 00:00:00 +05:00").to_s.should == "2021-12-25 00:00:00 +0500"
- end
+ it "accepts precision keyword argument and truncates specified digits of sub-second part" do
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00").subsec.should == 0.123456789r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: nil).subsec.should == 0.123456789876r
+ Time.new("2021-12-25 00:00:00 +09:00", precision: 0).subsec.should == 0
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: -1).subsec.should == 0.123456789876r
+ end
- it "returns Time in timezone specified in the String argument even if the in keyword argument provided" do
- Time.new("2021-12-25 00:00:00 +09:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 +0900"
- end
+ it "returns Time in local timezone if not provided in the String argument" do
+ Time.new("2021-12-25 00:00:00").zone.should == Time.new(2021, 12, 25).zone
+ Time.new("2021-12-25 00:00:00").utc_offset.should == Time.new(2021, 12, 25).utc_offset
+ end
- it "returns Time in timezone specified with in keyword argument if timezone isn't provided in the String argument" do
- Time.new("2021-12-25 00:00:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 -0100"
- end
+ it "returns Time in timezone specified in the String argument" do
+ Time.new("2021-12-25 00:00:00 +05:00").to_s.should == "2021-12-25 00:00:00 +0500"
+ end
- it "returns Time of Jan 1 for string with just year" do
- Time.new("2021").should == Time.new(2021, 1, 1)
- Time.new("2021").zone.should == Time.new(2021, 1, 1).zone
- Time.new("2021").utc_offset.should == Time.new(2021, 1, 1).utc_offset
- end
+ it "returns Time in timezone specified in the String argument even if the in keyword argument provided" do
+ Time.new("2021-12-25 00:00:00 +09:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 +0900"
+ end
- it "returns Time of Jan 1 for string with just year in timezone specified with in keyword argument" do
- Time.new("2021", in: "+17:00").to_s.should == "2021-01-01 00:00:00 +1700"
- end
+ it "returns Time in timezone specified with in keyword argument if timezone isn't provided in the String argument" do
+ Time.new("2021-12-25 00:00:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 -0100"
+ end
- it "converts precision keyword argument into Integer if is not nil" do
- obj = Object.new
- def obj.to_int; 3; end
+ it "returns Time of Jan 1 for string with just year" do
+ Time.new("2021").should == Time.new(2021, 1, 1)
+ Time.new("2021").zone.should == Time.new(2021, 1, 1).zone
+ Time.new("2021").utc_offset.should == Time.new(2021, 1, 1).utc_offset
+ end
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 1.2).subsec.should == 0.1r
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: obj).subsec.should == 0.123r
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 3r).subsec.should == 0.123r
- end
+ it "returns Time of Jan 1 for string with just year in timezone specified with in keyword argument" do
+ Time.new("2021", in: "+17:00").to_s.should == "2021-01-01 00:00:00 +1700"
+ end
- ruby_version_is ""..."3.3" do
- it "raise TypeError is can't convert precision keyword argument into Integer" do
- -> {
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "")
- }.should raise_error(TypeError, "no implicit conversion from string")
- end
- end
+ it "converts precision keyword argument into Integer if is not nil" do
+ obj = Object.new
+ def obj.to_int; 3; end
- ruby_version_is "3.3" do
- it "raise TypeError is can't convert precision keyword argument into Integer" do
- -> {
- Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "")
- }.should raise_error(TypeError, "no implicit conversion of String into Integer")
- end
- end
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 1.2).subsec.should == 0.1r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: obj).subsec.should == 0.123r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 3r).subsec.should == 0.123r
+ end
- it "raises ArgumentError if part of time string is missing" do
- -> {
- Time.new("2020-12-25 00:56 +09:00")
- }.should raise_error(ArgumentError, /missing sec part: 00:56 |can't parse:/)
+ it "returns Time with correct subseconds when given seconds fraction is shorted than 6 digits" do
+ Time.new("2020-12-25T00:56:17.123 +09:00").nsec.should == 123000000
+ Time.new("2020-12-25T00:56:17.123 +09:00").usec.should == 123000
+ Time.new("2020-12-25T00:56:17.123 +09:00").subsec.should == 0.123
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is milliseconds" do
+ Time.new("2020-12-25T00:56:17.123456 +09:00").nsec.should == 123456000
+ Time.new("2020-12-25T00:56:17.123456 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456 +09:00").subsec.should == 0.123456
+ end
+ it "returns Time with correct subseconds when given seconds fraction is longer that 6 digits but shorted than 9 digits" do
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").nsec.should == 123456780
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").subsec.should == 0.12345678
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is nanoseconds" do
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").nsec.should == 123456789
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").subsec.should == 0.123456789
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is longer than 9 digits" do
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").nsec.should == 123456789
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").subsec.should == 0.123456789
+ end
+
+ ruby_version_is ""..."3.3" do
+ it "raise TypeError is can't convert precision keyword argument into Integer" do
-> {
- Time.new("2020-12-25 00 +09:00")
- }.should raise_error(ArgumentError, /missing min part: 00 |can't parse:/)
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "")
+ }.should raise_error(TypeError, "no implicit conversion from string")
end
+ end
- ruby_version_is "3.2.3" do
- it "raises ArgumentError if the time part is missing" do
- -> {
- Time.new("2020-12-25")
- }.should raise_error(ArgumentError, /no time information|can't parse:/)
- end
-
- it "raises ArgumentError if day is missing" do
- -> {
- Time.new("2020-12")
- }.should raise_error(ArgumentError, /no time information|can't parse:/)
- end
+ ruby_version_is "3.3" do
+ it "raise TypeError is can't convert precision keyword argument into Integer" do
+ -> {
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "")
+ }.should raise_error(TypeError, "no implicit conversion of String into Integer")
end
+ end
+
+ it "raises ArgumentError if part of time string is missing" do
+ -> {
+ Time.new("2020-12-25 00:56 +09:00")
+ }.should raise_error(ArgumentError, /missing sec part: 00:56 |can't parse:/)
- it "raises ArgumentError if subsecond is missing after dot" do
+ -> {
+ Time.new("2020-12-25 00 +09:00")
+ }.should raise_error(ArgumentError, /missing min part: 00 |can't parse:/)
+ end
+
+ ruby_version_is "3.2.3" do
+ it "raises ArgumentError if the time part is missing" do
-> {
- Time.new("2020-12-25 00:56:17. +0900")
- }.should raise_error(ArgumentError, /subsecond expected after dot: 00:56:17. |can't parse:/)
+ Time.new("2020-12-25")
+ }.should raise_error(ArgumentError, /no time information|can't parse:/)
end
- it "raises ArgumentError if String argument is not in the supported format" do
+ it "raises ArgumentError if day is missing" do
-> {
- Time.new("021-12-25 00:00:00.123456 +09:00")
- }.should raise_error(ArgumentError, /year must be 4 or more digits: 021|can't parse:/)
+ Time.new("2020-12")
+ }.should raise_error(ArgumentError, /no time information|can't parse:/)
+ end
+ end
- -> {
- Time.new("2020-012-25 00:56:17 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z|can't parse:/)
+ it "raises ArgumentError if subsecond is missing after dot" do
+ -> {
+ Time.new("2020-12-25 00:56:17. +0900")
+ }.should raise_error(ArgumentError, /subsecond expected after dot: 00:56:17. |can't parse:/)
+ end
- -> {
- Time.new("2020-2-25 00:56:17 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z|can't parse:/)
+ it "raises ArgumentError if String argument is not in the supported format" do
+ -> {
+ Time.new("021-12-25 00:00:00.123456 +09:00")
+ }.should raise_error(ArgumentError, /year must be 4 or more digits: 021|can't parse:/)
- -> {
- Time.new("2020-12-215 00:56:17 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z|can't parse:/)
+ -> {
+ Time.new("2020-012-25 00:56:17 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z|can't parse:/)
- -> {
- Time.new("2020-12-25 000:56:17 +0900")
- }.should raise_error(ArgumentError, /two digits hour is expected: 000:56:17 |can't parse:/)
+ -> {
+ Time.new("2020-2-25 00:56:17 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z|can't parse:/)
- -> {
- Time.new("2020-12-25 0:56:17 +0900")
- }.should raise_error(ArgumentError, /two digits hour is expected: 0:56:17 \+0|can't parse:/)
+ -> {
+ Time.new("2020-12-215 00:56:17 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z|can't parse:/)
- -> {
- Time.new("2020-12-25 00:516:17 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z|can't parse:/)
+ -> {
+ Time.new("2020-12-25 000:56:17 +0900")
+ }.should raise_error(ArgumentError, /two digits hour is expected: 000:56:17 |can't parse:/)
- -> {
- Time.new("2020-12-25 00:6:17 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z|can't parse:/)
+ -> {
+ Time.new("2020-12-25 0:56:17 +0900")
+ }.should raise_error(ArgumentError, /two digits hour is expected: 0:56:17 \+0|can't parse:/)
- -> {
- Time.new("2020-12-25 00:56:137 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z|can't parse:/)
+ -> {
+ Time.new("2020-12-25 00:516:17 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z|can't parse:/)
- -> {
- Time.new("2020-12-25 00:56:7 +0900")
- }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z|can't parse:/)
+ -> {
+ Time.new("2020-12-25 00:6:17 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z|can't parse:/)
- -> {
- Time.new("2020-12-25 00:56. +0900")
- }.should raise_error(ArgumentError, /fraction min is not supported: 00:56\.|can't parse:/)
+ -> {
+ Time.new("2020-12-25 00:56:137 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z|can't parse:/)
- -> {
- Time.new("2020-12-25 00. +0900")
- }.should raise_error(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/)
- end
+ -> {
+ Time.new("2020-12-25 00:56:7 +0900")
+ }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z|can't parse:/)
- it "raises ArgumentError if date/time parts values are not valid" do
- -> {
- Time.new("2020-13-25 00:56:17 +09:00")
- }.should raise_error(ArgumentError, /(mon|argument) out of range/)
+ -> {
+ Time.new("2020-12-25 00:56. +0900")
+ }.should raise_error(ArgumentError, /fraction min is not supported: 00:56\.|can't parse:/)
- -> {
- Time.new("2020-12-32 00:56:17 +09:00")
- }.should raise_error(ArgumentError, /(mday|argument) out of range/)
+ -> {
+ Time.new("2020-12-25 00. +0900")
+ }.should raise_error(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/)
+ end
- -> {
- Time.new("2020-12-25 25:56:17 +09:00")
- }.should raise_error(ArgumentError, /(hour|argument) out of range/)
+ it "raises ArgumentError if date/time parts values are not valid" do
+ -> {
+ Time.new("2020-13-25 00:56:17 +09:00")
+ }.should raise_error(ArgumentError, /(mon|argument) out of range/)
- -> {
- Time.new("2020-12-25 00:61:17 +09:00")
- }.should raise_error(ArgumentError, /(min|argument) out of range/)
+ -> {
+ Time.new("2020-12-32 00:56:17 +09:00")
+ }.should raise_error(ArgumentError, /(mday|argument) out of range/)
- -> {
- Time.new("2020-12-25 00:56:61 +09:00")
- }.should raise_error(ArgumentError, /(sec|argument) out of range/)
+ -> {
+ Time.new("2020-12-25 25:56:17 +09:00")
+ }.should raise_error(ArgumentError, /(hour|argument) out of range/)
- -> {
- Time.new("2020-12-25 00:56:17 +23:59:60")
- }.should raise_error(ArgumentError, /utc_offset|argument out of range/)
+ -> {
+ Time.new("2020-12-25 00:61:17 +09:00")
+ }.should raise_error(ArgumentError, /(min|argument) out of range/)
- -> {
- Time.new("2020-12-25 00:56:17 +24:00")
- }.should raise_error(ArgumentError, /(utc_offset|argument) out of range/)
+ -> {
+ Time.new("2020-12-25 00:56:61 +09:00")
+ }.should raise_error(ArgumentError, /(sec|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:17 +23:59:60")
+ }.should raise_error(ArgumentError, /utc_offset|argument out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:17 +24:00")
+ }.should raise_error(ArgumentError, /(utc_offset|argument) out of range/)
+ -> {
+ Time.new("2020-12-25 00:56:17 +23:61")
+ }.should raise_error(ArgumentError, /utc_offset/)
+
+ ruby_bug '#20797', ''...'3.4' do
-> {
- Time.new("2020-12-25 00:56:17 +23:61")
+ Time.new("2020-12-25 00:56:17 +00:23:61")
}.should raise_error(ArgumentError, /utc_offset/)
-
- ruby_bug '#20797', ''...'3.4' do
- -> {
- Time.new("2020-12-25 00:56:17 +00:23:61")
- }.should raise_error(ArgumentError, /utc_offset/)
- end
end
+ end
- it "raises ArgumentError if utc offset parts are not valid" do
- -> { Time.new("2020-12-25 00:56:17 +24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.new("2020-12-25 00:56:17 +2400") }.should raise_error(ArgumentError, "utc_offset out of range")
+ it "raises ArgumentError if utc offset parts are not valid" do
+ -> { Time.new("2020-12-25 00:56:17 +24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
+ -> { Time.new("2020-12-25 00:56:17 +2400") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.new("2020-12-25 00:56:17 +99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.new("2020-12-25 00:56:17 +9900") }.should raise_error(ArgumentError, "utc_offset out of range")
+ -> { Time.new("2020-12-25 00:56:17 +99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
+ -> { Time.new("2020-12-25 00:56:17 +9900") }.should raise_error(ArgumentError, "utc_offset out of range")
- -> { Time.new("2020-12-25 00:56:17 +00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
- -> { Time.new("2020-12-25 00:56:17 +0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+ -> { Time.new("2020-12-25 00:56:17 +00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.new("2020-12-25 00:56:17 +0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
- -> { Time.new("2020-12-25 00:56:17 +00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
- -> { Time.new("2020-12-25 00:56:17 +0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+ -> { Time.new("2020-12-25 00:56:17 +00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.new("2020-12-25 00:56:17 +0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
- ruby_bug '#20797', ''...'3.4' do
- -> { Time.new("2020-12-25 00:56:17 +00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
- -> { Time.new("2020-12-25 00:56:17 +000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+ ruby_bug '#20797', ''...'3.4' do
+ -> { Time.new("2020-12-25 00:56:17 +00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.new("2020-12-25 00:56:17 +000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
- -> { Time.new("2020-12-25 00:56:17 +00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
- -> { Time.new("2020-12-25 00:56:17 +000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
- end
+ -> { Time.new("2020-12-25 00:56:17 +00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.new("2020-12-25 00:56:17 +000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
+ end
- it "raises ArgumentError if string has not ascii-compatible encoding" do
- -> {
- Time.new("2021-11-31 00:00:60 +09:00".encode("utf-32le"))
- }.should raise_error(ArgumentError, "time string should have ASCII compatible encoding")
- end
+ it "raises ArgumentError if string has not ascii-compatible encoding" do
+ -> {
+ Time.new("2021-11-31 00:00:60 +09:00".encode("utf-32le"))
+ }.should raise_error(ArgumentError, "time string should have ASCII compatible encoding")
+ end
- it "raises ArgumentError if string doesn't start with year" do
- -> {
- Time.new("a\nb")
- }.should raise_error(ArgumentError, "can't parse: \"a\\nb\"")
- end
+ it "raises ArgumentError if string doesn't start with year" do
+ -> {
+ Time.new("a\nb")
+ }.should raise_error(ArgumentError, "can't parse: \"a\\nb\"")
+ end
- it "raises ArgumentError if string has extra characters after offset" do
- -> {
- Time.new("2021-11-31 00:00:59 +09:00 abc")
- }.should raise_error(ArgumentError, /can't parse.+ abc/)
+ it "raises ArgumentError if string has extra characters after offset" do
+ -> {
+ Time.new("2021-11-31 00:00:59 +09:00 abc")
+ }.should raise_error(ArgumentError, /can't parse.+ abc/)
+ end
+
+ ruby_version_is "3.2.3" do
+ it "raises ArgumentError when there are leading space characters" do
+ -> { Time.new(" 2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("\t2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("\n2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("\v2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("\f2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("\r2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
end
- ruby_version_is "3.2.3" do
- it "raises ArgumentError when there are leading space characters" do
- -> { Time.new(" 2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("\t2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("\n2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("\v2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("\f2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("\r2020-12-02 00:00:00") }.should raise_error(ArgumentError, /can't parse/)
- end
-
- it "raises ArgumentError when there are trailing whitespaces" do
- -> { Time.new("2020-12-02 00:00:00 ") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("2020-12-02 00:00:00\t") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("2020-12-02 00:00:00\n") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("2020-12-02 00:00:00\v") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("2020-12-02 00:00:00\f") }.should raise_error(ArgumentError, /can't parse/)
- -> { Time.new("2020-12-02 00:00:00\r") }.should raise_error(ArgumentError, /can't parse/)
- end
+ it "raises ArgumentError when there are trailing whitespaces" do
+ -> { Time.new("2020-12-02 00:00:00 ") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\t") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\n") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\v") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\f") }.should raise_error(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\r") }.should raise_error(ArgumentError, /can't parse/)
end
end
end
diff --git a/spec/ruby/core/time/now_spec.rb b/spec/ruby/core/time/now_spec.rb
index f19e015461..e3fe6edad6 100644
--- a/spec/ruby/core/time/now_spec.rb
+++ b/spec/ruby/core/time/now_spec.rb
@@ -84,99 +84,97 @@ describe "Time.now" do
end
end
- ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/17485
- describe "Timezone object" do
- it "raises TypeError if timezone does not implement #utc_to_local method" do
+ describe "Timezone object" do # https://bugs.ruby-lang.org/issues/17485
+ it "raises TypeError if timezone does not implement #utc_to_local method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ time
+ end
+
+ -> {
+ Time.now(in: zone)
+ }.should raise_error(TypeError, /can't convert Object into an exact number/)
+ end
+
+ it "does not raise exception if timezone does not implement #local_to_utc method" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+
+ Time.now(in: zone).should be_kind_of(Time)
+ end
+
+ # The result also should be a Time or Time-like object (not necessary to be the same class)
+ # or Integer. The zone of the result is just ignored.
+ describe "returned value by #utc_to_local and #local_to_utc methods" do
+ it "could be Time instance" do
zone = Object.new
- def zone.local_to_utc(time)
- time
+ def zone.utc_to_local(t)
+ time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time + 60 * 60 # + 1 hour
end
- -> {
- Time.now(in: zone)
- }.should raise_error(TypeError, /can't convert Object into an exact number/)
+ Time.now(in: zone).should be_kind_of(Time)
+ Time.now(in: zone).utc_offset.should == 3600
end
- it "does not raise exception if timezone does not implement #local_to_utc method" do
+ it "could be Time subclass instance" do
zone = Object.new
- def zone.utc_to_local(time)
- time
+ def zone.utc_to_local(t)
+ time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time += 60 * 60 # + 1 hour
+
+ Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
end
Time.now(in: zone).should be_kind_of(Time)
+ Time.now(in: zone).utc_offset.should == 3600
end
- # The result also should be a Time or Time-like object (not necessary to be the same class)
- # or Integer. The zone of the result is just ignored.
- describe "returned value by #utc_to_local and #local_to_utc methods" do
- it "could be Time instance" do
- zone = Object.new
- def zone.utc_to_local(t)
- time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
- time + 60 * 60 # + 1 hour
- end
-
- Time.now(in: zone).should be_kind_of(Time)
- Time.now(in: zone).utc_offset.should == 3600
+ it "could be Integer" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time.to_i + 60*60
end
- it "could be Time subclass instance" do
- zone = Object.new
- def zone.utc_to_local(t)
- time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
- time += 60 * 60 # + 1 hour
-
- Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
- end
+ Time.now(in: zone).should be_kind_of(Time)
+ Time.now(in: zone).utc_offset.should == 60*60
+ end
- Time.now(in: zone).should be_kind_of(Time)
- Time.now(in: zone).utc_offset.should == 3600
+ it "could have any #zone and #utc_offset because they are ignored" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
+ .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'America/New_York', -5*60*60)
end
+ Time.now(in: zone).utc_offset.should == 0
- it "could be Integer" do
- zone = Object.new
- def zone.utc_to_local(time)
- time.to_i + 60*60
- end
-
- Time.now(in: zone).should be_kind_of(Time)
- Time.now(in: zone).utc_offset.should == 60*60
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
+ .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'Asia/Tokyo', 9*60*60)
end
+ Time.now(in: zone).utc_offset.should == 0
- it "could have any #zone and #utc_offset because they are ignored" do
- zone = Object.new
- def zone.utc_to_local(t)
- Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
- .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'America/New_York', -5*60*60)
- end
- Time.now(in: zone).utc_offset.should == 0
-
- zone = Object.new
- def zone.utc_to_local(t)
- Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
- .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'Asia/Tokyo', 9*60*60)
- end
- Time.now(in: zone).utc_offset.should == 0
-
- zone = Object.new
- def zone.utc_to_local(t)
- Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
- end
- Time.now(in: zone).utc_offset.should == 0
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
end
+ Time.now(in: zone).utc_offset.should == 0
+ end
- it "raises ArgumentError if difference between argument and result is too large" do
- zone = Object.new
- def zone.utc_to_local(t)
- time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
- time -= 24 * 60 * 60 # - 1 day
- Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
- end
-
- -> {
- Time.now(in: zone)
- }.should raise_error(ArgumentError, "utc_offset out of range")
+ it "raises ArgumentError if difference between argument and result is too large" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time -= 24 * 60 * 60 # - 1 day
+ Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
end
+
+ -> {
+ Time.now(in: zone)
+ }.should raise_error(ArgumentError, "utc_offset out of range")
end
end
end
diff --git a/spec/ruby/core/time/shared/time_params.rb b/spec/ruby/core/time/shared/time_params.rb
index b6a6c88c8e..9832fd17fe 100644
--- a/spec/ruby/core/time/shared/time_params.rb
+++ b/spec/ruby/core/time/shared/time_params.rb
@@ -179,6 +179,10 @@ describe :time_params, shared: true do
}.should raise_error(ArgumentError, "argument out of range")
end
+ it "raises ArgumentError when given 8 arguments" do
+ -> { Time.send(@method, *[0]*8) }.should raise_error(ArgumentError)
+ end
+
it "raises ArgumentError when given 9 arguments" do
-> { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError)
end
diff --git a/spec/ruby/core/time/utc_spec.rb b/spec/ruby/core/time/utc_spec.rb
index 3d36e13ccf..ab3c0df657 100644
--- a/spec/ruby/core/time/utc_spec.rb
+++ b/spec/ruby/core/time/utc_spec.rb
@@ -43,10 +43,14 @@ describe "Time#utc?" do
it "does not treat time with +00:00 offset as UTC" do
Time.new(2022, 1, 1, 0, 0, 0, "+00:00").utc?.should == false
+ Time.now.localtime("+00:00").utc?.should == false
+ Time.at(Time.now, in: "+00:00").utc?.should == false
end
it "does not treat time with 0 offset as UTC" do
Time.new(2022, 1, 1, 0, 0, 0, 0).utc?.should == false
+ Time.now.localtime(0).utc?.should == false
+ Time.at(Time.now, in: 0).utc?.should == false
end
end
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
index 6cc8bb3897..93a6b281e3 100644
--- a/spec/ruby/core/tracepoint/enable_spec.rb
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -57,50 +57,25 @@ describe 'TracePoint#enable' do
end.enable { event_name.should equal(:line) }
end
- ruby_version_is '3.2' do
- it 'enables the trace object only for the current thread' do
- threads = []
- trace = TracePoint.new(:line) do |tp|
- # Runs on purpose on any Thread
- threads << Thread.current
- end
-
- thread = nil
- trace.enable do
- line_event = true
- thread = Thread.new do
- event_in_other_thread = true
- end
- thread.join
- end
-
- threads = threads.uniq
- threads.should.include?(Thread.current)
- threads.should_not.include?(thread)
+ it 'enables the trace object only for the current thread' do
+ threads = []
+ trace = TracePoint.new(:line) do |tp|
+ # Runs on purpose on any Thread
+ threads << Thread.current
end
- end
- ruby_version_is ''...'3.2' do
- it 'enables the trace object for any thread' do
- threads = []
- trace = TracePoint.new(:line) do |tp|
- # Runs on purpose on any Thread
- threads << Thread.current
- end
-
- thread = nil
- trace.enable do
- line_event = true
- thread = Thread.new do
- event_in_other_thread = true
- end
- thread.join
+ thread = nil
+ trace.enable do
+ line_event = true
+ thread = Thread.new do
+ event_in_other_thread = true
end
-
- threads = threads.uniq
- threads.should.include?(Thread.current)
- threads.should.include?(thread)
+ thread.join
end
+
+ threads = threads.uniq
+ threads.should.include?(Thread.current)
+ threads.should_not.include?(thread)
end
it 'can accept arguments within a block but it should not yield arguments' do
diff --git a/spec/ruby/core/unboundmethod/equal_value_spec.rb b/spec/ruby/core/unboundmethod/equal_value_spec.rb
index 036c6b7f8c..b2d78c50af 100644
--- a/spec/ruby/core/unboundmethod/equal_value_spec.rb
+++ b/spec/ruby/core/unboundmethod/equal_value_spec.rb
@@ -76,38 +76,19 @@ describe "UnboundMethod#==" do
(@identical_body == @original_body).should == false
end
- ruby_version_is ""..."3.2" do
- it "returns false if same method but one extracted from a subclass" do
- (@parent == @child1).should == false
- (@child1 == @parent).should == false
- end
-
- it "returns false if same method but extracted from two different subclasses" do
- (@child2 == @child1).should == false
- (@child1 == @child2).should == false
- end
-
- it "returns false if methods are the same but added from an included Module" do
- (@includee == @includer).should == false
- (@includer == @includee).should == false
- end
+ it "returns true if same method but one extracted from a subclass" do
+ (@parent == @child1).should == true
+ (@child1 == @parent).should == true
end
- ruby_version_is "3.2" do
- it "returns true if same method but one extracted from a subclass" do
- (@parent == @child1).should == true
- (@child1 == @parent).should == true
- end
-
- it "returns false if same method but extracted from two different subclasses" do
- (@child2 == @child1).should == true
- (@child1 == @child2).should == true
- end
+ it "returns true if same method but extracted from two different subclasses" do
+ (@child2 == @child1).should == true
+ (@child1 == @child2).should == true
+ end
- it "returns true if methods are the same but added from an included Module" do
- (@includee == @includer).should == true
- (@includer == @includee).should == true
- end
+ it "returns true if methods are the same but added from an included Module" do
+ (@includee == @includer).should == true
+ (@includer == @includee).should == true
end
it "returns false if both have same Module, same name, identical body but not the same" do
diff --git a/spec/ruby/core/unboundmethod/owner_spec.rb b/spec/ruby/core/unboundmethod/owner_spec.rb
index e8a734dac4..b099c56de1 100644
--- a/spec/ruby/core/unboundmethod/owner_spec.rb
+++ b/spec/ruby/core/unboundmethod/owner_spec.rb
@@ -25,9 +25,7 @@ describe "UnboundMethod#owner" do
child_singleton_class.instance_method(:another_class_method).owner.should == child_singleton_class
end
- ruby_version_is "3.2" do
- it "returns the class on which public was called for a private method in ancestor" do
- MethodSpecs::InheritedMethods::C.instance_method(:derp).owner.should == MethodSpecs::InheritedMethods::C
- end
+ it "returns the class on which public was called for a private method in ancestor" do
+ MethodSpecs::InheritedMethods::C.instance_method(:derp).owner.should == MethodSpecs::InheritedMethods::C
end
end
diff --git a/spec/ruby/core/unboundmethod/private_spec.rb b/spec/ruby/core/unboundmethod/private_spec.rb
index 9a890db6fd..5a563939d1 100644
--- a/spec/ruby/core/unboundmethod/private_spec.rb
+++ b/spec/ruby/core/unboundmethod/private_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "UnboundMethod#private?" do
- ruby_version_is ""..."3.2" do
- it "returns false when the method is public" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_public_method).unbind.private?.should == false
- end
-
- it "returns false when the method is protected" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_protected_method).unbind.private?.should == false
- end
-
- it "returns true when the method is private" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_private_method).unbind.private?.should == true
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_private_method).unbind.should_not.respond_to?(:private?)
- end
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_private_method).unbind.should_not.respond_to?(:private?)
end
end
diff --git a/spec/ruby/core/unboundmethod/protected_spec.rb b/spec/ruby/core/unboundmethod/protected_spec.rb
index b79e2da63b..70622d658d 100644
--- a/spec/ruby/core/unboundmethod/protected_spec.rb
+++ b/spec/ruby/core/unboundmethod/protected_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "UnboundMethod#protected?" do
- ruby_version_is ""..."3.2" do
- it "returns false when the method is public" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_public_method).unbind.protected?.should == false
- end
-
- it "returns true when the method is protected" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_protected_method).unbind.protected?.should == true
- end
-
- it "returns false when the method is private" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_private_method).unbind.protected?.should == false
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_protected_method).unbind.should_not.respond_to?(:protected?)
- end
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_protected_method).unbind.should_not.respond_to?(:protected?)
end
end
diff --git a/spec/ruby/core/unboundmethod/public_spec.rb b/spec/ruby/core/unboundmethod/public_spec.rb
index c2a2795a84..ae75e2601c 100644
--- a/spec/ruby/core/unboundmethod/public_spec.rb
+++ b/spec/ruby/core/unboundmethod/public_spec.rb
@@ -2,27 +2,8 @@ require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe "UnboundMethod#public?" do
- ruby_version_is ""..."3.2" do
- it "returns true when the method is public" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_public_method).unbind.public?.should == true
- end
-
- it "returns false when the method is protected" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_protected_method).unbind.public?.should == false
- end
-
- it "returns false when the method is private" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_private_method).unbind.public?.should == false
- end
- end
-
- ruby_version_is "3.2" do
- it "has been removed" do
- obj = UnboundMethodSpecs::Methods.new
- obj.method(:my_public_method).unbind.should_not.respond_to?(:public?)
- end
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_public_method).unbind.should_not.respond_to?(:public?)
end
end
diff --git a/spec/ruby/core/unboundmethod/shared/to_s.rb b/spec/ruby/core/unboundmethod/shared/to_s.rb
index b92bb0b207..6b2c9c3e79 100644
--- a/spec/ruby/core/unboundmethod/shared/to_s.rb
+++ b/spec/ruby/core/unboundmethod/shared/to_s.rb
@@ -20,22 +20,11 @@ describe :unboundmethod_to_s, shared: true do
it "the String shows the method name, Module defined in and Module extracted from" do
@from_module.send(@method).should =~ /\bfrom_mod\b/
@from_module.send(@method).should =~ /\bUnboundMethodSpecs::Mod\b/
-
- ruby_version_is ""..."3.2" do
- @from_method.send(@method).should =~ /\bUnboundMethodSpecs::Methods\b/
- end
end
it "returns a String including all details" do
- ruby_version_is ""..."3.2" do
- @from_module.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
- @from_method.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Methods(UnboundMethodSpecs::Mod)#from_mod"
- end
-
- ruby_version_is "3.2" do
- @from_module.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
- @from_method.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
- end
+ @from_module.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
+ @from_method.send(@method).should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
end
it "does not show the defining module if it is the same as the origin" do
diff --git a/spec/ruby/core/unboundmethod/source_location_spec.rb b/spec/ruby/core/unboundmethod/source_location_spec.rb
index 2391d07d99..9cc2198017 100644
--- a/spec/ruby/core/unboundmethod/source_location_spec.rb
+++ b/spec/ruby/core/unboundmethod/source_location_spec.rb
@@ -55,10 +55,10 @@ describe "UnboundMethod#source_location" do
eval('def m; end', nil, "foo", 100)
end
location = c.instance_method(:m).source_location
- ruby_version_is(""..."3.5") do
+ ruby_version_is(""..."4.1") do
location.should == ["foo", 100]
end
- ruby_version_is("3.5") do
+ ruby_version_is("4.1") do
location.should == ["foo", 100, 0, 100, 10]
end
end
diff --git a/spec/ruby/core/warning/categories_spec.rb b/spec/ruby/core/warning/categories_spec.rb
new file mode 100644
index 0000000000..1e310ef38b
--- /dev/null
+++ b/spec/ruby/core/warning/categories_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "Warning.categories" do
+ # There might be more, but these are standard across Ruby implementations
+ it "returns the list of possible warning categories" do
+ Warning.categories.should.include? :deprecated
+ Warning.categories.should.include? :experimental
+ Warning.categories.should.include? :performance
+ end
+ end
+end
diff --git a/spec/ruby/core/warning/warn_spec.rb b/spec/ruby/core/warning/warn_spec.rb
index 572885c2b4..2e4a822e02 100644
--- a/spec/ruby/core/warning/warn_spec.rb
+++ b/spec/ruby/core/warning/warn_spec.rb
@@ -97,6 +97,20 @@ describe "Warning.warn" do
end
end
+ ruby_version_is "3.4" do
+ it "warns when category is :strict_unused_block but Warning[:strict_unused_block] is false" do
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = true
+ begin
+ -> {
+ Warning.warn("foo", category: :strict_unused_block)
+ }.should complain("foo")
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+ end
+
it "doesn't print message when category is :deprecated but Warning[:deprecated] is false" do
warn_deprecated = Warning[:deprecated]
Warning[:deprecated] = false
@@ -121,6 +135,20 @@ describe "Warning.warn" do
end
end
+ ruby_version_is "3.4" do
+ it "doesn't print message when category is :strict_unused_block but Warning[:strict_unused_block] is false" do
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = false
+ begin
+ -> {
+ Warning.warn("foo", category: :strict_unused_block)
+ }.should_not complain
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+ end
+
ruby_bug '#20573', ''...'3.4' do
it "isn't called by Kernel.warn when category is :deprecated but Warning[:deprecated] is false" do
warn_deprecated = Warning[:deprecated]
diff --git a/spec/ruby/default.mspec b/spec/ruby/default.mspec
index 1e8f8893aa..c8b1215f56 100644
--- a/spec/ruby/default.mspec
+++ b/spec/ruby/default.mspec
@@ -20,8 +20,11 @@ class MSpecScript
# C extension API specs
set :capi, [ 'optional/capi' ]
+ # Thread safety specs
+ set :thread_safety, [ 'optional/thread_safety' ]
+
# A list of _all_ optional specs
- set :optional, get(:capi)
+ set :optional, get(:capi) + get(:thread_safety)
# An ordered list of the directories containing specs to run
set :files, get(:command_line) + get(:language) + get(:core) + get(:library) + get(:security) + get(:optional)
diff --git a/spec/ruby/language/assignments_spec.rb b/spec/ruby/language/assignments_spec.rb
index 222d8699c5..c4adf73c1c 100644
--- a/spec/ruby/language/assignments_spec.rb
+++ b/spec/ruby/language/assignments_spec.rb
@@ -23,25 +23,12 @@ describe 'Assignments' do
ScratchPad.recorded.should == [:receiver, :argument, :rhs]
end
- # similar tests for evaluation order are located in language/constants_spec.rb
- ruby_version_is ''...'3.2' do
- it 'evaluates expressions right to left when assignment with compounded constant' do
- m = Module.new
- ScratchPad.record []
-
- (ScratchPad << :module; m)::A = (ScratchPad << :rhs; :value)
- ScratchPad.recorded.should == [:rhs, :module]
- end
- end
-
- ruby_version_is '3.2' do
- it 'evaluates expressions left to right when assignment with compounded constant' do
- m = Module.new
- ScratchPad.record []
+ it 'evaluates expressions left to right when assignment with compounded constant' do
+ m = Module.new
+ ScratchPad.record []
- (ScratchPad << :module; m)::A = (ScratchPad << :rhs; :value)
- ScratchPad.recorded.should == [:module, :rhs]
- end
+ (ScratchPad << :module; m)::A = (ScratchPad << :rhs; :value)
+ ScratchPad.recorded.should == [:module, :rhs]
end
it 'raises TypeError after evaluation of right-hand-side when compounded constant module is not a module' do
@@ -54,6 +41,65 @@ describe 'Assignments' do
ScratchPad.recorded.should == [:rhs]
end
end
+
+ context "given block argument" do
+ before do
+ @klass = Class.new do
+ def initialize(h) @h = h end
+ def [](k, &block) @h[k]; end
+ def []=(k, v, &block) @h[k] = v; end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "accepts block argument" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ eval "obj[:a, &block] = 2"
+ eval("obj[:a, &block]").should == 2
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ -> {
+ eval "obj[:a, &block] = 2"
+ }.should raise_error(SyntaxError, /unexpected block arg given in index assignment|block arg given in index assignment/)
+ end
+ end
+ end
+
+ context "given keyword arguments" do
+ before do
+ @klass = Class.new do
+ attr_reader :x
+
+ def []=(*args, **kw)
+ @x = [args, kw]
+ end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "supports keyword arguments in index assignments" do
+ a = @klass.new
+ eval "a[1, 2, 3, b: 4] = 5"
+ a.x.should == [[1, 2, 3, {b: 4}, 5], {}]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError when given keyword arguments in index assignments" do
+ a = @klass.new
+ -> { eval "a[1, 2, 3, b: 4] = 5" }.should raise_error(SyntaxError,
+ /keywords are not allowed in index assignment expressions|keyword arg given in index assignment/) # prism|parse.y
+ end
+ end
+ end
end
describe 'using +=' do
@@ -127,6 +173,77 @@ describe 'Assignments' do
a.public_method(:k, 2).should == 2
end
+ context "given block argument" do
+ before do
+ @klass = Class.new do
+ def initialize(h) @h = h end
+ def [](k, &block) @h[k]; end
+ def []=(k, v, &block) @h[k] = v; end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "accepts block argument" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ eval "obj[:a, &block] += 2"
+ eval("obj[:a, &block]").should == 3
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ -> {
+ eval "obj[:a, &block] += 2"
+ }.should raise_error(SyntaxError, /unexpected block arg given in index assignment|block arg given in index assignment/)
+ end
+ end
+ end
+
+ context "given keyword arguments" do
+ before do
+ @klass = Class.new do
+ attr_reader :x
+
+ def [](*args)
+ 100
+ end
+
+ def []=(*args, **kw)
+ @x = [args, kw]
+ end
+ end
+ end
+
+ ruby_version_is ""..."3.3" do
+ it "supports keyword arguments in index assignments" do
+ a = @klass.new
+ eval "a[1, 2, 3, b: 4] += 5"
+ a.x.should == [[1, 2, 3, {b: 4}, 105], {}]
+ end
+ end
+
+ ruby_version_is "3.3"..."3.4" do
+ it "supports keyword arguments in index assignments" do
+ a = @klass.new
+ eval "a[1, 2, 3, b: 4] += 5"
+ a.x.should == [[1, 2, 3, 105], {b: 4}]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError when given keyword arguments in index assignments" do
+ a = @klass.new
+ -> { eval "a[1, 2, 3, b: 4] += 5" }.should raise_error(SyntaxError,
+ /keywords are not allowed in index assignment expressions|keyword arg given in index assignment/) # prism|parse.y
+ end
+ end
+ end
+
context 'splatted argument' do
it 'correctly handles it' do
@b[:m] = 10
@@ -345,45 +462,33 @@ describe 'Multiple assignments' do
ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value]
end
- ruby_version_is ''...'3.2' do
- it 'evaluates expressions right to left when assignment with compounded constant' do
- m = Module.new
- ScratchPad.record []
+ it 'evaluates expressions left to right when assignment with compounded constant' do
+ m = Module.new
+ ScratchPad.record []
- (ScratchPad << :a; m)::A, (ScratchPad << :b; m)::B = (ScratchPad << :c; :c), (ScratchPad << :d; :d)
- ScratchPad.recorded.should == [:c, :d, :a, :b]
- end
+ (ScratchPad << :a; m)::A, (ScratchPad << :b; m)::B = (ScratchPad << :c; :c), (ScratchPad << :d; :d)
+ ScratchPad.recorded.should == [:a, :b, :c, :d]
end
- ruby_version_is '3.2' do
- it 'evaluates expressions left to right when assignment with compounded constant' do
- m = Module.new
- ScratchPad.record []
-
- (ScratchPad << :a; m)::A, (ScratchPad << :b; m)::B = (ScratchPad << :c; :c), (ScratchPad << :d; :d)
- ScratchPad.recorded.should == [:a, :b, :c, :d]
- end
-
- it 'evaluates expressions left to right when assignment with a nested compounded constant' do
- m = Module.new
- ScratchPad.record []
+ it 'evaluates expressions left to right when assignment with a nested compounded constant' do
+ m = Module.new
+ ScratchPad.record []
- ((ScratchPad << :a; m)::A, foo), bar = [(ScratchPad << :b; :b)]
- ScratchPad.recorded.should == [:a, :b]
- end
+ ((ScratchPad << :a; m)::A, foo), bar = [(ScratchPad << :b; :b)]
+ ScratchPad.recorded.should == [:a, :b]
+ end
- it 'evaluates expressions left to right when assignment with deeply nested compounded constants' do
- m = Module.new
- ScratchPad.record []
+ it 'evaluates expressions left to right when assignment with deeply nested compounded constants' do
+ m = Module.new
+ ScratchPad.record []
- (ScratchPad << :a; m)::A,
- ((ScratchPad << :b; m)::B,
- ((ScratchPad << :c; m)::C, (ScratchPad << :d; m)::D),
- (ScratchPad << :e; m)::E),
- (ScratchPad << :f; m)::F = (ScratchPad << :value; :value)
+ (ScratchPad << :a; m)::A,
+ ((ScratchPad << :b; m)::B,
+ ((ScratchPad << :c; m)::C, (ScratchPad << :d; m)::D),
+ (ScratchPad << :e; m)::E),
+ (ScratchPad << :f; m)::F = (ScratchPad << :value; :value)
- ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value]
- end
+ ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value]
end
end
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index 1a73b415f2..cc003b8946 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -62,37 +62,18 @@ describe "A block yielded a single" do
m([1, 2, 3, 4, 5, 6]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 2, 3, [4], 5, 6]
end
- ruby_version_is "3.2" do
- it "does not autosplat single argument to required arguments when a keyword rest argument is present" do
- m([1, 2]) { |a, **k| [a, k] }.should == [[1, 2], {}]
- end
-
- it "does not autosplat single argument to required arguments when keyword arguments are present" do
- m([1, 2]) { |a, b: :b, c: :c| [a, b, c] }.should == [[1, 2], :b, :c]
- end
-
- it "raises error when required keyword arguments are present" do
- -> {
- m([1, 2]) { |a, b:, c:| [a, b, c] }
- }.should raise_error(ArgumentError, "missing keywords: :b, :c")
- end
+ it "does not autosplat single argument to required arguments when a keyword rest argument is present" do
+ m([1, 2]) { |a, **k| [a, k] }.should == [[1, 2], {}]
end
- ruby_version_is ''..."3.2" do
- # https://bugs.ruby-lang.org/issues/18633
- it "autosplats single argument to required arguments when a keyword rest argument is present" do
- m([1, 2]) { |a, **k| [a, k] }.should == [1, {}]
- end
-
- it "autosplats single argument to required arguments when optional keyword arguments are present" do
- m([1, 2]) { |a, b: :b, c: :c| [a, b, c] }.should == [1, :b, :c]
- end
+ it "does not autosplat single argument to required arguments when keyword arguments are present" do
+ m([1, 2]) { |a, b: :b, c: :c| [a, b, c] }.should == [[1, 2], :b, :c]
+ end
- it "raises error when required keyword arguments are present" do
- -> {
- m([1, 2]) { |a, b:, c:| [a, b, c] }
- }.should raise_error(ArgumentError, "missing keywords: :b, :c")
- end
+ it "raises error when required keyword arguments are present" do
+ -> {
+ m([1, 2]) { |a, b:, c:| [a, b, c] }
+ }.should raise_error(ArgumentError, "missing keywords: :b, :c")
end
it "assigns elements to mixed argument types" do
@@ -1040,25 +1021,23 @@ describe "Anonymous block forwarding" do
no_kw(:a) { 1 }.should == 1
end
- ruby_version_is "3.2" do
- it "works alongside explicit keyword arguments" do
- eval <<-EOF
- def inner; yield end
- def rest_kw(*a, kwarg: 1, &); inner(&) end
- def kw(kwarg: 1, &); inner(&) end
- def pos_kw_kwrest(arg1, kwarg: 1, **kw, &); inner(&) end
- def pos_rkw(arg1, kwarg1:, &); inner(&) end
- def all(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, &); inner(&) end
- def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, **kw, &); inner(&) end
- EOF
-
- rest_kw { 1 }.should == 1
- kw { 1 }.should == 1
- pos_kw_kwrest(:a) { 1 }.should == 1
- pos_rkw(:a, kwarg1: 3) { 1 }.should == 1
- all(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
- all_kwrest(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
- end
+ it "works alongside explicit keyword arguments" do
+ eval <<-EOF
+ def inner; yield end
+ def rest_kw(*a, kwarg: 1, &); inner(&) end
+ def kw(kwarg: 1, &); inner(&) end
+ def pos_kw_kwrest(arg1, kwarg: 1, **kw, &); inner(&) end
+ def pos_rkw(arg1, kwarg1:, &); inner(&) end
+ def all(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, &); inner(&) end
+ def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, **kw, &); inner(&) end
+ EOF
+
+ rest_kw { 1 }.should == 1
+ kw { 1 }.should == 1
+ pos_kw_kwrest(:a) { 1 }.should == 1
+ pos_rkw(:a, kwarg1: 3) { 1 }.should == 1
+ all(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
+ all_kwrest(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
end
end
@@ -1070,6 +1049,12 @@ describe "`it` calls without arguments in a block with no ordinary parameters" d
}.should complain(/warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; use it\(\) or self.it/)
end
+ it "emits a deprecation warning if numbered parameters are used" do
+ -> {
+ eval "proc { it; _1 }"
+ }.should complain(/warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; use it\(\) or self.it/)
+ end
+
it "does not emit a deprecation warning when a block has parameters" do
-> { eval "proc { |a, b| it }" }.should_not complain
-> { eval "proc { |*rest| it }" }.should_not complain
@@ -1079,14 +1064,75 @@ describe "`it` calls without arguments in a block with no ordinary parameters" d
-> { eval "proc { |**| it }" }.should_not complain
-> { eval "proc { |&block| it }" }.should_not complain
-> { eval "proc { |&| it }" }.should_not complain
+ -> { eval "proc { || it }" }.should_not complain
end
it "does not emit a deprecation warning when `it` calls with arguments" do
-> { eval "proc { it(42) }" }.should_not complain
+ -> { eval "proc { it 42 }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when `it` calls with a block" do
+ -> { eval "proc { it {} }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when a local variable inside the block named `it` exists" do
+ -> { eval "proc { it = 42; it }" }.should_not complain
end
it "does not emit a deprecation warning when `it` calls with explicit empty arguments list" do
-> { eval "proc { it() }" }.should_not complain
end
+
+ it "calls the method `it` if defined" do
+ o = Object.new
+ def o.it
+ 21
+ end
+ suppress_warning do
+ o.instance_eval("proc { it * 2 }").call(1).should == 42
+ end
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "does not emit a deprecation warning" do
+ -> {
+ eval "proc { it }"
+ }.should_not complain
+ end
+
+ it "acts as the first argument if no local variables exist" do
+ eval("proc { it * 2 }").call(5).should == 10
+ end
+
+ it "can be reassigned to act as a local variable" do
+ eval("proc { tmp = it; it = tmp * 2; it }").call(21).should == 42
+ end
+
+ it "can be used in nested calls" do
+ eval("proc { it.map { it * 2 } }").call([1, 2, 3]).should == [2, 4, 6]
+ end
+
+ it "cannot be mixed with numbered parameters" do
+ -> {
+ eval "proc { it + _1 }"
+ }.should raise_error(SyntaxError, /numbered parameters are not allowed when 'it' is already used|'it' is already used in/)
+
+ -> {
+ eval "proc { _1 + it }"
+ }.should raise_error(SyntaxError, /numbered parameter is already used in|'it' is not allowed when a numbered parameter is already used/)
+ end
+ end
+end
+
+describe "if `it` is defined as a variable" do
+ it "treats `it` as a captured variable if defined outside of a block" do
+ it = 5
+ proc { it }.call(0).should == 5
+ end
+
+ it "treats `it` as a local variable if defined inside of a block" do
+ proc { it = 5; it }.call(0).should == 5
end
end
diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb
index 0b770d69b5..6fb785fd56 100644
--- a/spec/ruby/language/class_spec.rb
+++ b/spec/ruby/language/class_spec.rb
@@ -46,7 +46,14 @@ describe "A class definition" do
-> {
class ClassSpecsNumber
end
- }.should raise_error(TypeError)
+ }.should raise_error(TypeError, /\AClassSpecsNumber is not a class/)
+ end
+
+ it "raises TypeError if constant given as class name exists and is a Module but not a Class" do
+ -> {
+ class ClassSpecs
+ end
+ }.should raise_error(TypeError, /\AClassSpecs is not a class/)
end
# test case known to be detecting bugs (JRuby, MRI)
@@ -346,6 +353,39 @@ describe "Reopening a class" do
ClassSpecs::M.m.should == 1
ClassSpecs::L.singleton_class.send(:remove_method, :m)
end
+
+ it "does not reopen a class included in Object" do
+ ruby_exe(<<~RUBY).should == "false"
+ module IncludedInObject
+ class IncludedClass
+ end
+ end
+ class Object
+ include IncludedInObject
+ end
+ class IncludedClass
+ end
+ print IncludedInObject::IncludedClass == Object::IncludedClass
+ RUBY
+ end
+
+ it "does not reopen a class included in non-Object modules" do
+ ruby_exe(<<~RUBY).should == "false/false"
+ module Included
+ module IncludedClass; end
+ end
+ module M
+ include Included
+ module IncludedClass; end
+ end
+ class C
+ include Included
+ module IncludedClass; end
+ end
+ print Included::IncludedClass == M::IncludedClass, "/",
+ Included::IncludedClass == C::IncludedClass
+ RUBY
+ end
end
describe "class provides hooks" do
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index 35913b9e30..063c52c422 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -161,34 +161,16 @@ describe "Literal (A::X) constant resolution" do
ConstantSpecs::ClassB.send(:remove_const, :CS_CONST109)
end
- ruby_version_is "3.2" do
- it "evaluates left-to-right" do
- mod = Module.new
+ it "evaluates left-to-right" do
+ mod = Module.new
- mod.module_eval <<-EOC
- order = []
- ConstantSpecsRHS = Module.new
- (order << :lhs; ConstantSpecsRHS)::B = (order << :rhs)
- EOC
+ mod.module_eval <<-EOC
+ order = []
+ ConstantSpecsRHS = Module.new
+ (order << :lhs; ConstantSpecsRHS)::B = (order << :rhs)
+ EOC
- mod::ConstantSpecsRHS::B.should == [:lhs, :rhs]
- end
- end
-
- ruby_version_is ""..."3.2" do
- it "evaluates the right hand side before evaluating a constant path" do
- mod = Module.new
-
- mod.module_eval <<-EOC
- ConstantSpecsRHS::B = begin
- module ConstantSpecsRHS; end
-
- "hello"
- end
- EOC
-
- mod::ConstantSpecsRHS::B.should == 'hello'
- end
+ mod::ConstantSpecsRHS::B.should == [:lhs, :rhs]
end
end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index eb44331bb5..0cf1790791 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -97,7 +97,8 @@ describe "An instance method" do
def foo; end
end
}.should raise_error(FrozenError) { |e|
- e.message.should.start_with? "can't modify frozen module"
+ msg_class = ruby_version_is("4.0") ? "Module" : "module"
+ e.message.should == "can't modify frozen #{msg_class}: #{e.receiver}"
}
-> {
@@ -106,7 +107,8 @@ describe "An instance method" do
def foo; end
end
}.should raise_error(FrozenError){ |e|
- e.message.should.start_with? "can't modify frozen class"
+ msg_class = ruby_version_is("4.0") ? "Class" : "class"
+ e.message.should == "can't modify frozen #{msg_class}: #{e.receiver}"
}
end
end
@@ -283,20 +285,21 @@ describe "A singleton method definition" do
it "raises FrozenError with the correct class name" do
obj = Object.new
obj.freeze
- -> { def obj.foo; end }.should raise_error(FrozenError){ |e|
- e.message.should.start_with? "can't modify frozen object"
- }
+ msg_class = ruby_version_is("4.0") ? "Object" : "object"
+ -> { def obj.foo; end }.should raise_error(FrozenError, "can't modify frozen #{msg_class}: #{obj}")
+ obj = Object.new
c = obj.singleton_class
- -> { def c.foo; end }.should raise_error(FrozenError){ |e|
- e.message.should.start_with? "can't modify frozen Class"
- }
+ c.singleton_class.freeze
+ -> { def c.foo; end }.should raise_error(FrozenError, "can't modify frozen Class: #{c}")
+
+ c = Class.new
+ c.freeze
+ -> { def c.foo; end }.should raise_error(FrozenError, "can't modify frozen Class: #{c}")
m = Module.new
m.freeze
- -> { def m.foo; end }.should raise_error(FrozenError){ |e|
- e.message.should.start_with? "can't modify frozen Module"
- }
+ -> { def m.foo; end }.should raise_error(FrozenError, "can't modify frozen Module: #{m}")
end
end
diff --git a/spec/ruby/language/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb
index 0fcd3e57bf..c711a536c2 100644
--- a/spec/ruby/language/delegation_spec.rb
+++ b/spec/ruby/language/delegation_spec.rb
@@ -87,51 +87,47 @@ describe "delegation with def(x, ...)" do
end
end
-ruby_version_is "3.2" do
- describe "delegation with def(*)" do
- it "delegates rest" do
- a = Class.new(DelegationSpecs::Target)
- a.class_eval(<<-RUBY)
- def delegate(*)
- target(*)
- end
- RUBY
-
- a.new.delegate(0, 1).should == [[0, 1], {}, nil]
+describe "delegation with def(*)" do
+ it "delegates rest" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(*)
+ target(*)
end
+ RUBY
- ruby_version_is "3.3" do
- context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
- it "does not allow delegating rest" do
- -> {
- eval "def m(*); proc { |*| n(*) } end"
- }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/)
- end
+ a.new.delegate(0, 1).should == [[0, 1], {}, nil]
+ end
+
+ ruby_version_is "3.3" do
+ context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
+ it "does not allow delegating rest" do
+ -> {
+ eval "def m(*); proc { |*| n(*) } end"
+ }.should raise_error(SyntaxError, /anonymous rest parameter is also used within block/)
end
end
end
end
-ruby_version_is "3.2" do
- describe "delegation with def(**)" do
- it "delegates kwargs" do
- a = Class.new(DelegationSpecs::Target)
- a.class_eval(<<-RUBY)
- def delegate(**)
- target(**)
- end
- RUBY
-
- a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil]
+describe "delegation with def(**)" do
+ it "delegates kwargs" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(**)
+ target(**)
end
+ RUBY
- ruby_version_is "3.3" do
- context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
- it "does not allow delegating kwargs" do
- -> {
- eval "def m(**); proc { |**| n(**) } end"
- }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/)
- end
+ a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil]
+ end
+
+ ruby_version_is "3.3" do
+ context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
+ it "does not allow delegating kwargs" do
+ -> {
+ eval "def m(**); proc { |**| n(**) } end"
+ }.should raise_error(SyntaxError, /anonymous keyword rest parameter is also used within block/)
end
end
end
diff --git a/spec/ruby/language/fixtures/class_with_class_variable.rb b/spec/ruby/language/fixtures/class_with_class_variable.rb
new file mode 100644
index 0000000000..0b07f16d30
--- /dev/null
+++ b/spec/ruby/language/fixtures/class_with_class_variable.rb
@@ -0,0 +1,9 @@
+module StringSpecs
+ class ClassWithClassVariable
+ @@a = "xxx"
+
+ def foo
+ "#@@a"
+ end
+ end
+end
diff --git a/spec/ruby/language/fixtures/module.rb b/spec/ruby/language/fixtures/module.rb
index 33d323846e..75eee77791 100644
--- a/spec/ruby/language/fixtures/module.rb
+++ b/spec/ruby/language/fixtures/module.rb
@@ -12,13 +12,4 @@ module ModuleSpecs
module Anonymous
end
-
- module IncludedInObject
- module IncludedModuleSpecs
- end
- end
-end
-
-class Object
- include ModuleSpecs::IncludedInObject
end
diff --git a/spec/ruby/language/fixtures/send.rb b/spec/ruby/language/fixtures/send.rb
index 5d1d9da214..4787abee5c 100644
--- a/spec/ruby/language/fixtures/send.rb
+++ b/spec/ruby/language/fixtures/send.rb
@@ -81,6 +81,16 @@ module LangSendSpecs
end
end
+ class RawToProc
+ def initialize(to_proc)
+ @to_proc = to_proc
+ end
+
+ def to_proc
+ @to_proc
+ end
+ end
+
class ToAry
def initialize(obj)
@obj = obj
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index b119b6ca73..668716e2e3 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -149,6 +149,26 @@ describe "Hash literal" do
{a: 1, **h, c: 4}.should == {a: 1, b: 2, c: 4}
end
+ ruby_version_is ""..."3.4" do
+ it "does not expand nil using ** into {} and raises TypeError" do
+ h = nil
+ -> { {a: 1, **h} }.should raise_error(TypeError, "no implicit conversion of nil into Hash")
+
+ -> { {a: 1, **nil} }.should raise_error(TypeError, "no implicit conversion of nil into Hash")
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "expands nil using ** into {}" do
+ h = nil
+ {**h}.should == {}
+ {a: 1, **h}.should == {a: 1}
+
+ {**nil}.should == {}
+ {a: 1, **nil}.should == {a: 1}
+ end
+ end
+
it "expands an '**{}' or '**obj' element with the last key/value pair taking precedence" do
-> {
@h = eval "{a: 1, **{a: 2, b: 3, c: 1}, c: 3}"
diff --git a/spec/ruby/language/it_parameter_spec.rb b/spec/ruby/language/it_parameter_spec.rb
new file mode 100644
index 0000000000..72023180d9
--- /dev/null
+++ b/spec/ruby/language/it_parameter_spec.rb
@@ -0,0 +1,66 @@
+require_relative '../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "The `it` parameter" do
+ it "provides it in a block" do
+ -> { it }.call("a").should == "a"
+ proc { it }.call("a").should == "a"
+ lambda { it }.call("a").should == "a"
+ ["a"].map { it }.should == ["a"]
+ end
+
+ it "assigns nil to not passed parameters" do
+ proc { it }.call().should == nil
+ end
+
+ it "can be used in both outer and nested blocks at the same time" do
+ -> { it + -> { it * it }.call(2) }.call(3).should == 7
+ end
+
+ it "is a regular local variable if there is already a 'it' local variable" do
+ it = 0
+ proc { it }.call("a").should == 0
+ end
+
+ it "raises SyntaxError when block parameters are specified explicitly" do
+ -> { eval("-> () { it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("-> (x) { it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("proc { || it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("proc { |x| it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("lambda { || it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("lambda { |x| it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("['a'].map { || it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("['a'].map { |x| it }") }.should raise_error(SyntaxError, /ordinary parameter is defined/)
+ end
+
+ it "affects block arity" do
+ -> {}.arity.should == 0
+ -> { it }.arity.should == 1
+ end
+
+ it "affects block parameters" do
+ -> { it }.parameters.should == [[:req]]
+
+ ruby_version_is ""..."4.0" do
+ proc { it }.parameters.should == [[:opt, nil]]
+ end
+ ruby_version_is "4.0" do
+ proc { it }.parameters.should == [[:opt]]
+ end
+ end
+
+ it "does not affect binding local variables" do
+ -> { it; binding.local_variables }.call("a").should == []
+ end
+
+ it "does not work in methods" do
+ obj = Object.new
+ def obj.foo; it; end
+
+ -> { obj.foo("a") }.should raise_error(ArgumentError, /wrong number of arguments/)
+ end
+ end
+end
diff --git a/spec/ruby/language/keyword_arguments_spec.rb b/spec/ruby/language/keyword_arguments_spec.rb
index 3f8ddfa40d..4f6370d419 100644
--- a/spec/ruby/language/keyword_arguments_spec.rb
+++ b/spec/ruby/language/keyword_arguments_spec.rb
@@ -336,61 +336,23 @@ describe "Keyword arguments" do
end
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
+ 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
- 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
+ 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
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
- m(kw).should == [[{a: 1}], {}]
- m(kw)[0][0].should.equal?(kw)
- Hash.ruby2_keywords_hash?(kw).should == false
- end
+ m(a: 1).should == [[{a: 1}], {}]
+ m({a: 1}).should == [[{a: 1}], {}]
end
end
diff --git a/spec/ruby/language/magic_comment_spec.rb b/spec/ruby/language/magic_comment_spec.rb
index f2bf3a08e5..af9c9dbfd0 100644
--- a/spec/ruby/language/magic_comment_spec.rb
+++ b/spec/ruby/language/magic_comment_spec.rb
@@ -45,7 +45,8 @@ end
describe "Magic comments" do
describe "in stdin" do
- it_behaves_like :magic_comments, :locale, -> file {
+ default = (platform_is :windows and ruby_version_is "4.0") ? :UTF8 : :locale
+ it_behaves_like :magic_comments, default, -> file {
print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
ruby_exe(nil, args: "< #{fixture(__FILE__, file)}", options: "-r#{print_at_exit}")
}
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index b0d7058dbe..8f72bd45ed 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -1175,6 +1175,31 @@ describe "A method" do
end
end
+context "when passing **nil into a method that accepts keyword arguments" do
+ ruby_version_is ""..."3.4" do
+ it "raises TypeError" do
+ def m(**kw) kw; end
+
+ h = nil
+ -> { m(a: 1, **h) }.should raise_error(TypeError, "no implicit conversion of nil into Hash")
+ -> { m(a: 1, **nil) }.should raise_error(TypeError, "no implicit conversion of nil into Hash")
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "expands nil using ** into {}" do
+ def m(**kw) kw; end
+
+ h = nil
+ m(**h).should == {}
+ m(a: 1, **h).should == {a: 1}
+
+ m(**nil).should == {}
+ m(a: 1, **nil).should == {a: 1}
+ end
+ end
+end
+
describe "A method call with a space between method name and parentheses" do
before(:each) do
def m(*args)
@@ -1462,3 +1487,163 @@ describe "Inside 'endless' method definitions" do
greet("Homer").should == "Hi, Homer"
end
end
+
+describe "warning about not used block argument" do
+ ruby_version_is "3.4" do
+ it "warns when passing a block argument to a method that never uses it" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(
+ /#{__FILE__}:#{__LINE__ - 2}: warning: the block passed to 'm_that_does_not_use_block' defined at #{__FILE__}:#{__LINE__ - 7} may be ignored/,
+ verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that declares a block parameter" do
+ def m_with_block_parameter(&block)
+ 42
+ end
+
+ -> { m_with_block_parameter { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that declares an anonymous block parameter" do
+ def m_with_anonymous_block_parameter(&)
+ 42
+ end
+
+ -> { m_with_anonymous_block_parameter { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that yields an implicit block parameter" do
+ def m_with_yield
+ yield 42
+ end
+
+ -> { m_with_yield { } }.should_not complain(verbose: true)
+ end
+
+ it "warns when passing a block argument to a method that calls #block_given?" do
+ def m_with_block_given
+ block_given?
+ end
+
+ -> {
+ m_with_block_given { }
+ }.should complain(
+ /#{__FILE__}:#{__LINE__ - 2}: warning: the block passed to 'm_with_block_given' defined at #{__FILE__}:#{__LINE__ - 7} may be ignored/,
+ verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super" do
+ parent = Class.new do
+ def m
+ end
+ end
+
+ child = Class.new(parent) do
+ def m
+ super
+ end
+ end
+
+ obj = child.new
+ -> { obj.m { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super(...)" do
+ parent = Class.new do
+ def m(a)
+ end
+ end
+
+ child = Class.new(parent) do
+ def m(...)
+ super(...)
+ end
+ end
+
+ obj = child.new
+ -> { obj.m(42) { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when called #initialize()" do
+ klass = Class.new do
+ def initialize
+ end
+ end
+
+ -> { klass.new {} }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super()" do
+ parent = Class.new do
+ def m
+ end
+ end
+
+ child = Class.new(parent) do
+ def m
+ super()
+ end
+ end
+
+ obj = child.new
+ -> { obj.m { } }.should_not complain(verbose: true)
+ end
+
+ it "warns only once per call site" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ def call_m_that_does_not_use_block
+ m_that_does_not_use_block {}
+ end
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(/the block passed to 'm_that_does_not_use_block' defined at .+ may be ignored/, verbose: true)
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should_not complain(verbose: true)
+ end
+
+ it "can be disabled with :strict_unused_block warning category" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ # ensure that warning is emitted
+ -> { m_that_does_not_use_block { } }.should complain(verbose: true)
+
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = false
+ begin
+ -> { m_that_does_not_use_block { } }.should_not complain(verbose: true)
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+
+ it "can be enabled with :strict_unused_block = true warning category in not verbose mode" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = true
+ begin
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(/the block passed to 'm_that_does_not_use_block' defined at .+ may be ignored/)
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+ end
+end
diff --git a/spec/ruby/language/module_spec.rb b/spec/ruby/language/module_spec.rb
index 0bfd148868..fba4aa8c6e 100644
--- a/spec/ruby/language/module_spec.rb
+++ b/spec/ruby/language/module_spec.rb
@@ -30,20 +30,35 @@ describe "The module keyword" do
ModuleSpecs.send(:remove_const, :Reopened)
end
- ruby_version_is '3.2' do
- it "does not reopen a module included in Object" do
- module IncludedModuleSpecs; Reopened = true; end
- ModuleSpecs::IncludedInObject::IncludedModuleSpecs.should_not == Object::IncludedModuleSpecs
- ensure
- IncludedModuleSpecs.send(:remove_const, :Reopened)
- end
- end
-
- ruby_version_is ''...'3.2' do
- it "reopens a module included in Object" do
- module IncludedModuleSpecs; Reopened = true; end
- ModuleSpecs::IncludedInObject::IncludedModuleSpecs::Reopened.should be_true
- end
+ it "does not reopen a module included in Object" do
+ ruby_exe(<<~RUBY).should == "false"
+ module IncludedInObject
+ module IncludedModule; end
+ end
+ class Object
+ include IncludedInObject
+ end
+ module IncludedModule; end
+ print IncludedInObject::IncludedModule == Object::IncludedModule
+ RUBY
+ end
+
+ it "does not reopen a module included in non-Object modules" do
+ ruby_exe(<<~RUBY).should == "false/false"
+ module Included
+ module IncludedModule; end
+ end
+ module M
+ include Included
+ module IncludedModule; end
+ end
+ class C
+ include Included
+ module IncludedModule; end
+ end
+ print Included::IncludedModule == M::IncludedModule, "/",
+ Included::IncludedModule == C::IncludedModule
+ RUBY
end
it "raises a TypeError if the constant is a Class" do
diff --git a/spec/ruby/language/numbered_parameters_spec.rb b/spec/ruby/language/numbered_parameters_spec.rb
index 39ddd6fee8..de532c326d 100644
--- a/spec/ruby/language/numbered_parameters_spec.rb
+++ b/spec/ruby/language/numbered_parameters_spec.rb
@@ -90,14 +90,14 @@ describe "Numbered parameters" do
proc { _2 }.parameters.should == [[:opt, :_1], [:opt, :_2]]
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "affects binding local variables" do
-> { _1; binding.local_variables }.call("a").should == [:_1]
-> { _2; binding.local_variables }.call("a", "b").should == [:_1, :_2]
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "does not affect binding local variables" do
-> { _1; binding.local_variables }.call("a").should == []
-> { _2; binding.local_variables }.call("a", "b").should == []
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb
index cb4f5864d7..c1a6f0e4d6 100644
--- a/spec/ruby/language/pattern_matching_spec.rb
+++ b/spec/ruby/language/pattern_matching_spec.rb
@@ -493,7 +493,7 @@ describe "Pattern matching" do
in [0, 0] | [0, a]
end
RUBY
- }.should raise_error(SyntaxError, /illegal variable in alternative pattern/)
+ }.should raise_error(SyntaxError)
end
it "support underscore prefixed variables in alternation" do
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index f8645493b8..fc1667a38f 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -1,4 +1,5 @@
require_relative '../spec_helper'
+require_relative '../core/exception/shared/set_backtrace'
require 'stringio'
# The following tables are excerpted from Programming Ruby: The Pragmatic Programmer's Guide'
@@ -88,8 +89,8 @@ describe "Predefined global $~" do
$~ = /foo/.match("foo")
$~.should be_an_instance_of(MatchData)
- -> { $~ = Object.new }.should raise_error(TypeError)
- -> { $~ = 1 }.should raise_error(TypeError)
+ -> { $~ = Object.new }.should raise_error(TypeError, 'wrong argument type Object (expected MatchData)')
+ -> { $~ = 1 }.should raise_error(TypeError, 'wrong argument type Integer (expected MatchData)')
end
it "changes the value of derived capture globals when assigned" do
@@ -136,6 +137,19 @@ describe "Predefined global $&" do
"abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/
$&.encoding.should equal(Encoding::EUC_JP)
end
+
+ it "is read-only" do
+ -> {
+ eval %q{$& = ""}
+ }.should raise_error(SyntaxError, /Can't set variable \$&/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_ampersand $&
+ -> {
+ $predefined_spec_ampersand = ""
+ }.should raise_error(NameError, '$predefined_spec_ampersand is a read-only variable')
+ end
end
describe "Predefined global $`" do
@@ -154,6 +168,19 @@ describe "Predefined global $`" do
"abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /a/
$`.encoding.should equal(Encoding::ISO_8859_1)
end
+
+ it "is read-only" do
+ -> {
+ eval %q{$` = ""}
+ }.should raise_error(SyntaxError, /Can't set variable \$`/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_backquote $`
+ -> {
+ $predefined_spec_backquote = ""
+ }.should raise_error(NameError, '$predefined_spec_backquote is a read-only variable')
+ end
end
describe "Predefined global $'" do
@@ -172,6 +199,19 @@ describe "Predefined global $'" do
"abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /c/
$'.encoding.should equal(Encoding::ISO_8859_1)
end
+
+ it "is read-only" do
+ -> {
+ eval %q{$' = ""}
+ }.should raise_error(SyntaxError, /Can't set variable \$'/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_single_quote $'
+ -> {
+ $predefined_spec_single_quote = ""
+ }.should raise_error(NameError, '$predefined_spec_single_quote is a read-only variable')
+ end
end
describe "Predefined global $+" do
@@ -190,6 +230,19 @@ describe "Predefined global $+" do
"abc".dup.force_encoding(Encoding::EUC_JP) =~ /(b)/
$+.encoding.should equal(Encoding::EUC_JP)
end
+
+ it "is read-only" do
+ -> {
+ eval %q{$+ = ""}
+ }.should raise_error(SyntaxError, /Can't set variable \$\+/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_plus $+
+ -> {
+ $predefined_spec_plus = ""
+ }.should raise_error(NameError, '$predefined_spec_plus is a read-only variable')
+ end
end
describe "Predefined globals $1..N" do
@@ -229,7 +282,7 @@ describe "Predefined global $stdout" do
end
it "raises TypeError error if assigned to nil" do
- -> { $stdout = nil }.should raise_error(TypeError)
+ -> { $stdout = nil }.should raise_error(TypeError, '$stdout must have write method, NilClass given')
end
it "raises TypeError error if assigned to object that doesn't respond to #write" do
@@ -253,6 +306,12 @@ describe "Predefined global $!" do
$!.should == nil
end
+ it "is read-only" do
+ -> {
+ $! = []
+ }.should raise_error(NameError, '$! is a read-only variable')
+ end
+
# See http://jira.codehaus.org/browse/JRUBY-5550
it "remains nil after a failed core class \"checked\" coercion against a class that defines method_missing" do
$!.should == nil
@@ -512,6 +571,75 @@ describe "Predefined global $!" do
end
end
+describe "Predefined global $@" do
+ it "is Fiber-local" do
+ Fiber.new do
+ raise "hi"
+ rescue
+ Fiber.yield
+ end.resume
+
+ $@.should == nil
+ end
+
+ it "is set to a backtrace of a rescued exception" do
+ begin
+ raise
+ rescue
+ $@.should be_an_instance_of(Array)
+ $@.should == $!.backtrace
+ end
+ end
+
+ it "is cleared when an exception is rescued" do
+ begin
+ raise
+ rescue
+ end
+
+ $@.should == nil
+ end
+
+ it "is not set when there is no current exception" do
+ $@.should == nil
+ end
+
+ it "is set to a backtrace of a rescued exception" do
+ begin
+ raise
+ rescue
+ $@.should be_an_instance_of(Array)
+ $@.should == $!.backtrace
+ end
+ end
+
+ it "is not read-only" do
+ begin
+ raise
+ rescue
+ $@ = []
+ $@.should == []
+ end
+ end
+
+ it_behaves_like :exception_set_backtrace, -> backtrace {
+ exception = nil
+ begin
+ raise
+ rescue
+ $@ = backtrace
+ exception = $!
+ end
+ exception
+ }
+
+ it "cannot be assigned when there is no a rescued exception" do
+ -> {
+ $@ = []
+ }.should raise_error(ArgumentError, '$! not set')
+ end
+end
+
# Input/Output Variables
# ---------------------------------------------------------------------------------------------------
#
@@ -559,7 +687,7 @@ describe "Predefined global $/" do
$VERBOSE = @verbose
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "can be assigned a String" do
str = +"abc"
$/ = str
@@ -567,7 +695,7 @@ describe "Predefined global $/" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "makes a new frozen String from the assigned String" do
string_subclass = Class.new(String)
str = string_subclass.new("abc")
@@ -610,15 +738,19 @@ describe "Predefined global $/" do
obj = mock("$/ value")
obj.should_not_receive(:to_str)
- -> { $/ = obj }.should raise_error(TypeError)
+ -> { $/ = obj }.should raise_error(TypeError, 'value of $/ must be String')
end
it "raises a TypeError if assigned an Integer" do
- -> { $/ = 1 }.should raise_error(TypeError)
+ -> { $/ = 1 }.should raise_error(TypeError, 'value of $/ must be String')
end
it "raises a TypeError if assigned a boolean" do
- -> { $/ = true }.should raise_error(TypeError)
+ -> { $/ = true }.should raise_error(TypeError, 'value of $/ must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $/ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\/' is deprecated/)
end
end
@@ -635,7 +767,7 @@ describe "Predefined global $-0" do
$VERBOSE = @verbose
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "can be assigned a String" do
str = +"abc"
$-0 = str
@@ -643,7 +775,7 @@ describe "Predefined global $-0" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "makes a new frozen String from the assigned String" do
string_subclass = Class.new(String)
str = string_subclass.new("abc")
@@ -687,15 +819,19 @@ describe "Predefined global $-0" do
obj = mock("$-0 value")
obj.should_not_receive(:to_str)
- -> { $-0 = obj }.should raise_error(TypeError)
+ -> { $-0 = obj }.should raise_error(TypeError, 'value of $-0 must be String')
end
it "raises a TypeError if assigned an Integer" do
- -> { $-0 = 1 }.should raise_error(TypeError)
+ -> { $-0 = 1 }.should raise_error(TypeError, 'value of $-0 must be String')
end
it "raises a TypeError if assigned a boolean" do
- -> { $-0 = true }.should raise_error(TypeError)
+ -> { $-0 = true }.should raise_error(TypeError, 'value of $-0 must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $-0 = "_" }.should complain(/warning: (?:non-nil )?[`']\$-0' is deprecated/)
end
end
@@ -729,12 +865,16 @@ describe "Predefined global $\\" do
obj = mock("$\\ value")
obj.should_not_receive(:to_str)
- -> { $\ = obj }.should raise_error(TypeError)
+ -> { $\ = obj }.should raise_error(TypeError, 'value of $\ must be String')
end
it "raises a TypeError if assigned not String" do
- -> { $\ = 1 }.should raise_error(TypeError)
- -> { $\ = true }.should raise_error(TypeError)
+ -> { $\ = 1 }.should raise_error(TypeError, 'value of $\ must be String')
+ -> { $\ = true }.should raise_error(TypeError, 'value of $\ must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $\ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\\' is deprecated/)
end
end
@@ -748,11 +888,11 @@ describe "Predefined global $," do
end
it "raises TypeError if assigned a non-String" do
- -> { $, = Object.new }.should raise_error(TypeError)
+ -> { $, = Object.new }.should raise_error(TypeError, 'value of $, must be String')
end
it "warns if assigned non-nil" do
- -> { $, = "_" }.should complain(/warning: [`']\$,' is deprecated/)
+ -> { $, = "_" }.should complain(/warning: (?:non-nil )?[`']\$,' is deprecated/)
end
end
@@ -789,7 +929,7 @@ describe "Predefined global $;" do
end
it "warns if assigned non-nil" do
- -> { $; = "_" }.should complain(/warning: [`']\$;' is deprecated/)
+ -> { $; = "_" }.should complain(/warning: (?:non-nil )?[`']\$;' is deprecated/)
end
end
@@ -933,22 +1073,28 @@ describe "Execution variable $:" do
it "is read-only" do
-> {
$: = []
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$: is a read-only variable')
-> {
$LOAD_PATH = []
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$LOAD_PATH is a read-only variable')
-> {
$-I = []
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$-I is a read-only variable')
end
it "default $LOAD_PATH entries until sitelibdir included have @gem_prelude_index set" do
skip "no sense in ruby itself" if MSpecScript.instance_variable_defined?(:@testing_ruby)
- $:.should.include?(RbConfig::CONFIG['sitelibdir'])
- idx = $:.index(RbConfig::CONFIG['sitelibdir'])
+ if platform_is :windows
+ # See https://github.com/ruby/setup-ruby/pull/762#issuecomment-2917460440
+ $:.should.find { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ idx = $:.index { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ else
+ $:.should.include?(RbConfig::CONFIG['sitelibdir'])
+ idx = $:.index(RbConfig::CONFIG['sitelibdir'])
+ end
$:[idx..-1].all? { |p| p.instance_variable_defined?(:@gem_prelude_index) }.should be_true
$:[0...idx].all? { |p| !p.instance_variable_defined?(:@gem_prelude_index) }.should be_true
@@ -963,11 +1109,11 @@ describe "Global variable $\"" do
it "is read-only" do
-> {
$" = []
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$" is a read-only variable')
-> {
$LOADED_FEATURES = []
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$LOADED_FEATURES is a read-only variable')
end
end
@@ -975,7 +1121,7 @@ describe "Global variable $<" do
it "is read-only" do
-> {
$< = nil
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$< is a read-only variable')
end
end
@@ -983,7 +1129,7 @@ describe "Global variable $FILENAME" do
it "is read-only" do
-> {
$FILENAME = "-"
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$FILENAME is a read-only variable')
end
end
@@ -991,7 +1137,7 @@ describe "Global variable $?" do
it "is read-only" do
-> {
$? = nil
- }.should raise_error(NameError)
+ }.should raise_error(NameError, '$? is a read-only variable')
end
it "is thread-local" do
@@ -1002,19 +1148,19 @@ end
describe "Global variable $-a" do
it "is read-only" do
- -> { $-a = true }.should raise_error(NameError)
+ -> { $-a = true }.should raise_error(NameError, '$-a is a read-only variable')
end
end
describe "Global variable $-l" do
it "is read-only" do
- -> { $-l = true }.should raise_error(NameError)
+ -> { $-l = true }.should raise_error(NameError, '$-l is a read-only variable')
end
end
describe "Global variable $-p" do
it "is read-only" do
- -> { $-p = true }.should raise_error(NameError)
+ -> { $-p = true }.should raise_error(NameError, '$-p is a read-only variable')
end
end
@@ -1165,7 +1311,7 @@ describe "The predefined standard object nil" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("nil = true") }.should raise_error(SyntaxError)
+ -> { eval("nil = true") }.should raise_error(SyntaxError, /Can't assign to nil/)
end
end
@@ -1175,7 +1321,7 @@ describe "The predefined standard object true" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("true = false") }.should raise_error(SyntaxError)
+ -> { eval("true = false") }.should raise_error(SyntaxError, /Can't assign to true/)
end
end
@@ -1185,13 +1331,13 @@ describe "The predefined standard object false" do
end
it "raises a SyntaxError if assigned to" do
- -> { eval("false = nil") }.should raise_error(SyntaxError)
+ -> { eval("false = nil") }.should raise_error(SyntaxError, /Can't assign to false/)
end
end
describe "The self pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- -> { eval("self = 1") }.should raise_error(SyntaxError)
+ -> { eval("self = 1") }.should raise_error(SyntaxError, /Can't change the value of self/)
end
end
@@ -1382,9 +1528,9 @@ 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, path = $LOAD_PATH.resolve_feature_path('pp')
extension.should == :rb
- path.should.end_with?('/set.rb')
+ path.should.end_with?('/pp.rb')
end
it "returns what will be loaded without actual loading, .so file" do
diff --git a/spec/ruby/language/regexp/character_classes_spec.rb b/spec/ruby/language/regexp/character_classes_spec.rb
index d27a54a028..018757db41 100644
--- a/spec/ruby/language/regexp/character_classes_spec.rb
+++ b/spec/ruby/language/regexp/character_classes_spec.rb
@@ -562,6 +562,13 @@ describe "Regexp with character classes" do
"\u{16EE}".match(/[[:word:]]/).to_a.should == ["\u{16EE}"]
end
+ ruby_bug "#19417", ""..."3.4.6" do
+ it "matches Unicode join control characters with [[:word:]]" do
+ "\u{200C}".match(/[[:word:]]/).to_a.should == ["\u{200C}"]
+ "\u{200D}".match(/[[:word:]]/).to_a.should == ["\u{200D}"]
+ end
+ end
+
it "doesn't match Unicode No characters with [[:word:]]" do
"\u{17F0}".match(/[[:word:]]/).should be_nil
end
diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb
index 0571b2d3cf..ceb9cf823a 100644
--- a/spec/ruby/language/regexp/encoding_spec.rb
+++ b/spec/ruby/language/regexp/encoding_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative '../fixtures/classes'
@@ -39,7 +39,11 @@ describe "Regexps with encoding modifiers" do
end
it "warns when using /n with a match string with non-ASCII characters and an encoding other than ASCII-8BIT" do
- -> { /./n.match("\303\251".dup.force_encoding('utf-8')) }.should complain(%r{historical binary regexp match /.../n against UTF-8 string})
+ -> {
+ eval <<~RUBY
+ /./n.match("\303\251".dup.force_encoding('utf-8'))
+ RUBY
+ }.should complain(%r{historical binary regexp match /.../n against UTF-8 string})
end
it 'uses US-ASCII as /n encoding if all chars are 7-bit' do
diff --git a/spec/ruby/language/regexp/escapes_spec.rb b/spec/ruby/language/regexp/escapes_spec.rb
index 16a4d8c23b..541998b937 100644
--- a/spec/ruby/language/regexp/escapes_spec.rb
+++ b/spec/ruby/language/regexp/escapes_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index 0cd9584549..ce344b5b05 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -112,7 +112,7 @@ describe "Literal Regexps" do
/foo.(?<=\d)/.match("fooA foo1").to_a.should == ["foo1"]
end
- ruby_bug "#13671", ""..."3.6" do # https://bugs.ruby-lang.org/issues/13671
+ ruby_bug "#13671", ""..."4.0" do # https://bugs.ruby-lang.org/issues/13671
it "handles a lookbehind with ss characters" do
r = Regexp.new("(?<!dss)", Regexp::IGNORECASE)
r.should =~ "✨"
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index 79571d689f..6be3bfd023 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -136,10 +136,14 @@ describe "The rescue keyword" do
it 'captures successfully at the top-level' do
ScratchPad.record []
+ loaded_features = $".dup
+ begin
+ require_relative 'fixtures/rescue/top_level'
- require_relative 'fixtures/rescue/top_level'
-
- ScratchPad.recorded.should == ["message"]
+ ScratchPad.recorded.should == ["message"]
+ ensure
+ $".replace loaded_features
+ end
end
end
diff --git a/spec/ruby/language/reserved_keywords.rb b/spec/ruby/language/reserved_keywords.rb
new file mode 100644
index 0000000000..6c40e34ccc
--- /dev/null
+++ b/spec/ruby/language/reserved_keywords.rb
@@ -0,0 +1,149 @@
+require_relative '../spec_helper'
+
+describe "Ruby's reserved keywords" do
+ # Copied from https://github.com/ruby/ruby/blob/master/defs/keywords
+ keywords = %w[
+ alias
+ and
+ begin
+ BEGIN
+ break
+ case
+ class
+ def
+ defined?
+ do
+ else
+ elsif
+ end
+ END
+ ensure
+ false
+ for
+ if
+ in
+ module
+ next
+ nil
+ not
+ or
+ redo
+ rescue
+ retry
+ return
+ self
+ super
+ then
+ true
+ undef
+ unless
+ until
+ when
+ while
+ yield
+ __ENCODING__
+ __FILE__
+ __LINE__
+ ]
+
+ keywords.each do |name|
+ describe "keyword '#{name}'" do
+ it "can't be used as local variable name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ #{name} = :local_variable
+ RUBY
+ end
+
+ if name == "defined?"
+ it "can't be used as an instance variable name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ @#{name} = :instance_variable
+ RUBY
+ end
+
+ it "can't be used as a class variable name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ class C
+ @@#{name} = :class_variable
+ end
+ RUBY
+ end
+
+ it "can't be used as a global variable name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ $#{name} = :global_variable
+ RUBY
+ end
+ else
+ it "can be used as an instance variable name" do
+ result = eval <<~RUBY
+ @#{name} = :instance_variable
+ @#{name}
+ RUBY
+
+ result.should == :instance_variable
+ end
+
+ it "can be used as a class variable name" do
+ result = eval <<~RUBY
+ class C
+ @@#{name} = :class_variable
+ @@#{name}
+ end
+ RUBY
+
+ result.should == :class_variable
+ end
+
+ it "can be used as a global variable name" do
+ result = eval <<~RUBY
+ $#{name} = :global_variable
+ $#{name}
+ RUBY
+
+ result.should == :global_variable
+ end
+ end
+
+ it "can't be used as a positional parameter name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ def x(#{name}); end
+ RUBY
+ end
+
+ invalid_kw_param_names = ["BEGIN","END","defined?"]
+
+ if invalid_kw_param_names.include?(name)
+ it "can't be used a keyword parameter name" do
+ -> { eval(<<~RUBY) }.should raise_error(SyntaxError)
+ def m(#{name}:); end
+ RUBY
+ end
+ else
+ it "can be used a keyword parameter name" do
+ result = instance_eval <<~RUBY
+ def m(#{name}:)
+ binding.local_variable_get(:#{name})
+ end
+
+ m(#{name}: :argument)
+ RUBY
+
+ result.should == :argument
+ end
+ end
+
+ it "can be used as a method name" do
+ result = instance_eval <<~RUBY
+ def #{name}
+ :method_return_value
+ end
+
+ send(:#{name})
+ RUBY
+
+ result.should == :method_return_value
+ end
+ end
+ end
+end
diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb
index aaccdf0998..5d6340ffc5 100644
--- a/spec/ruby/language/send_spec.rb
+++ b/spec/ruby/language/send_spec.rb
@@ -106,6 +106,24 @@ describe "Invoking a method" do
specs.yield_now(&o).should == :from_to_proc
end
+ ruby_version_is "4.0" do
+ it "raises TypeError if 'to_proc' doesn't return a Proc" do
+ o = LangSendSpecs::RawToProc.new(42)
+
+ -> {
+ specs.makeproc(&o)
+ }.should raise_error(TypeError, "can't convert LangSendSpecs::RawToProc to Proc (LangSendSpecs::RawToProc#to_proc gives Integer)")
+ end
+
+ it "raises TypeError if block object isn't a Proc and doesn't respond to `to_proc`" do
+ o = Object.new
+
+ -> {
+ specs.makeproc(&o)
+ }.should raise_error(TypeError, "no implicit conversion of Object into Proc")
+ end
+ end
+
it "raises a SyntaxError with both a literal block and an object as block" do
-> {
eval "specs.oneb(10, &l){ 42 }"
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index 083a7f5db5..f287731bed 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -1,6 +1,7 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../spec_helper'
+require_relative 'fixtures/class_with_class_variable'
# TODO: rewrite these horrid specs. it "are..." seriously?!
@@ -27,6 +28,11 @@ describe "Ruby character strings" do
"#$ip".should == 'xxx'
end
+ it "interpolate class variables just with the # character" do
+ object = StringSpecs::ClassWithClassVariable.new
+ object.foo.should == 'xxx'
+ end
+
it "allows underscore as part of a variable name in a simple interpolation" do
@my_ip = 'xxx'
"#@my_ip".should == 'xxx'
@@ -280,15 +286,15 @@ describe "Ruby String interpolation" do
it "creates a non-frozen String" do
code = <<~'RUBY'
- "a#{6*7}c"
+ "a#{6*7}c"
RUBY
eval(code).should_not.frozen?
end
it "creates a non-frozen String when # frozen-string-literal: true is used" do
code = <<~'RUBY'
- # frozen-string-literal: true
- "a#{6*7}c"
+ # frozen-string-literal: true
+ "a#{6*7}c"
RUBY
eval(code).should_not.frozen?
end
diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb
index eb080eea55..e134271939 100644
--- a/spec/ruby/language/variables_spec.rb
+++ b/spec/ruby/language/variables_spec.rb
@@ -363,7 +363,7 @@ describe "Multiple assignment" do
a.should == []
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
it "converts nil to empty array without calling a method" do
nil.should_not_receive(:to_a)
@@ -372,7 +372,7 @@ describe "Multiple assignment" do
end
end
- ruby_version_is ""..."3.5" do
+ ruby_version_is ""..."4.0" do
it "calls #to_a to convert nil to an empty Array" do
nil.should_receive(:to_a).and_return([])
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
index 45f5ebffc7..8596356abd 100644
--- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -31,16 +31,12 @@ describe "Kernel#BigDecimal" do
end
it "accepts significant digits >= given precision" do
- suppress_warning do
- BigDecimal("3.1415923", 10).precs[1].should >= 10
- end
+ BigDecimal("3.1415923", 10).should == BigDecimal("3.1415923")
end
it "determines precision from initial value" do
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
- suppress_warning {
- BigDecimal(pi_string).precs[1]
- }.should >= pi_string.size-1
+ BigDecimal(pi_string).precision.should == pi_string.size-1
end
it "ignores leading and trailing whitespace" do
@@ -156,8 +152,10 @@ describe "Kernel#BigDecimal" do
BigDecimal("-12345.6E-1").should == -reference
end
- it "raises ArgumentError when Float is used without precision" do
- -> { BigDecimal(1.0) }.should raise_error(ArgumentError)
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "allows Float without precision" do
+ BigDecimal(1.2).should == BigDecimal("1.2")
+ end
end
it "returns appropriate BigDecimal zero for signed zero" do
@@ -206,14 +204,6 @@ describe "Kernel#BigDecimal" do
Float(@b).to_s.should == "166.66666666666666"
end
- it "has the expected precision on the LHS" do
- suppress_warning { @a.precs[0] }.should == 18
- end
-
- it "has the expected maximum precision on the LHS" do
- suppress_warning { @a.precs[1] }.should == 27
- end
-
it "produces the expected result when done via Float" do
(Float(@a) - Float(@b)).to_s.should == "-6.666596163995564e-10"
end
@@ -224,34 +214,10 @@ describe "Kernel#BigDecimal" do
# Check underlying methods work as we understand
- it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
- 1.upto(100) do |n|
- b = BigDecimal('4' * n)
- precs, _ = suppress_warning { b.precs }
- (precs >= 9).should be_true
- (precs >= n).should be_true
- (precs % 9).should == 0
- end
- suppress_warning { BigDecimal('NaN').precs[0] }.should == 9
- end
-
- it "BigDecimal maximum precision is nine more than precision except for abnormals" do
- 1.upto(100) do |n|
- b = BigDecimal('4' * n)
- precs, max = suppress_warning { b.precs }
- max.should == precs + 9
- end
- suppress_warning { BigDecimal('NaN').precs[1] }.should == 9
- end
-
it "BigDecimal(Rational, 18) produces the result we expect" do
BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3"
end
- it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
- BigDecimal(@b, suppress_warning { @a.precs[0] }).to_s.should == "0.166666666666666667e3"
- end
-
# Check the top-level expression works as we expect
it "produces a BigDecimal" do
@@ -259,8 +225,8 @@ describe "Kernel#BigDecimal" do
end
it "produces the expected result" do
- @c.should == BigDecimal("-0.666667e-9")
- @c.to_s.should == "-0.666667e-9"
+ @c.round(15).should == BigDecimal("-0.666667e-9")
+ @c.round(15).to_s.should == "-0.666667e-9"
end
it "produces the correct class for other arithmetic operators" do
diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb
index 542713011d..9cdab7d910 100644
--- a/spec/ruby/library/bigdecimal/add_spec.rb
+++ b/spec/ruby/library/bigdecimal/add_spec.rb
@@ -73,14 +73,6 @@ describe "BigDecimal#add" do
# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
# end
- describe "with Object" do
- it "tries to coerce the other operand to self" do
- object = mock("Object")
- object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
- @frac_3.add(object, 1).should == BigDecimal("0.1E16")
- end
- end
-
describe "with Rational" do
it "produces a BigDecimal" do
(@three + Rational(500, 2)).should == BigDecimal("0.253e3")
diff --git a/spec/ruby/library/bigdecimal/core_spec.rb b/spec/ruby/library/bigdecimal/core_spec.rb
index acee4dcf56..5097d70865 100644
--- a/spec/ruby/library/bigdecimal/core_spec.rb
+++ b/spec/ruby/library/bigdecimal/core_spec.rb
@@ -20,9 +20,12 @@ describe "Core extension by bigdecimal" do
describe "BigDecimal#log" do
it "handles high-precision Rational arguments" do
- result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0')
+ # log(BigDecimal(r, 50), 50)
+ result1 = BigDecimal('0.22314354220170971436137296411949880462556361100856e0')
+ # log(BigDecimal(r, 1000), 50)
+ result2 = BigDecimal('0.22314354220170971436137296411949880462556361100853e0')
r = Rational(1_234_567_890, 987_654_321)
- BigMath.log(r, 50).should == result
+ [result1, result2].should include(BigMath.log(r, 50).mult(1, 50))
end
end
diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb
index 294f01cba0..85c014bb8c 100644
--- a/spec/ruby/library/bigdecimal/divmod_spec.rb
+++ b/spec/ruby/library/bigdecimal/divmod_spec.rb
@@ -33,14 +33,16 @@ describe "BigDecimal#mod_part_of_divmod" do
end
end
- it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod
+ end
it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal("5667.19")
-
+ zero = BigDecimal("0")
-> { bd5667.mod_part_of_divmod(0) }.should raise_error(ZeroDivisionError)
-> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should raise_error(ZeroDivisionError)
- -> { @zero.mod_part_of_divmod(@zero) }.should raise_error(ZeroDivisionError)
+ -> { zero.mod_part_of_divmod(zero) }.should raise_error(ZeroDivisionError)
end
end
@@ -73,14 +75,25 @@ describe "BigDecimal#divmod" do
@zeroes = [@zero, @zero_pos, @zero_neg]
end
- it "divides value, returns an array" do
- res = @a.divmod(5)
- res.kind_of?(Array).should == true
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "divides value, returns [BigDecimal, BigDecimal]" do
+ res = @a.divmod(5)
+ res.kind_of?(Array).should == true
+ DivmodSpecs.check_both_bigdecimal(res)
+ end
+ end
+
+ version_is BigDecimal::VERSION, "4.0.0" do
+ it "divides value, returns [Integer, BigDecimal]" do
+ res = @a.divmod(5)
+ res.kind_of?(Array).should == true
+ res[0].kind_of?(Integer).should == true
+ res[1].kind_of?(BigDecimal).should == true
+ end
end
it "array contains quotient and modulus as BigDecimal" do
res = @a.divmod(5)
- DivmodSpecs.check_both_bigdecimal(res)
res[0].should == BigDecimal('0.8E1')
res[1].should == BigDecimal('2.00000000000000000001')
@@ -123,17 +136,27 @@ describe "BigDecimal#divmod" do
values_and_zeroes.each do |val1|
values.each do |val2|
res = val1.divmod(val2)
- DivmodSpecs.check_both_bigdecimal(res)
res[0].should == ((val1/val2).floor)
res[1].should == (val1 - res[0] * val2)
end
end
end
- it "returns an array of two NaNs if NaN is involved" do
- (@special_vals + @regular_vals + @zeroes).each do |val|
- DivmodSpecs.check_both_nan(val.divmod(@nan))
- DivmodSpecs.check_both_nan(@nan.divmod(val))
+ version_is BigDecimal::VERSION, "4.0.0" do
+ it "raise FloatDomainError error if NaN is involved" do
+ (@special_vals + @regular_vals + @zeroes).each do |val|
+ -> { val.divmod(@nan) }.should raise_error(FloatDomainError)
+ -> { @nan.divmod(val) }.should raise_error(FloatDomainError)
+ end
+ end
+ end
+
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "returns an array of two NaNs if NaN is involved" do
+ (@special_vals + @regular_vals + @zeroes).each do |val|
+ DivmodSpecs.check_both_nan(val.divmod(@nan))
+ DivmodSpecs.check_both_nan(@nan.divmod(val))
+ end
end
end
@@ -145,21 +168,30 @@ describe "BigDecimal#divmod" do
end
end
- it "returns an array of Infinity and NaN if the dividend is Infinity" do
- @regular_vals.each do |val|
- array = @infinity.divmod(val)
- array.length.should == 2
- array[0].infinite?.should == (val > 0 ? 1 : -1)
- array[1].should.nan?
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "returns an array of Infinity and NaN if the dividend is Infinity" do
+ @regular_vals.each do |val|
+ array = @infinity.divmod(val)
+ array.length.should == 2
+ array[0].infinite?.should == (val > 0 ? 1 : -1)
+ array[1].should.nan?
+ end
end
end
- it "returns an array of zero and the dividend if the divisor is Infinity" do
- @regular_vals.each do |val|
- array = val.divmod(@infinity)
- array.length.should == 2
- array[0].should == @zero
- array[1].should == val
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "returns an array of zero and the dividend or minus one and Infinity if the divisor is Infinity" do
+ @regular_vals.each do |val|
+ array = val.divmod(@infinity)
+ array.length.should == 2
+ if val >= 0
+ array[0].should == @zero
+ array[1].should == val
+ else
+ array[0].should == @one_minus
+ array[1].should == @infinity
+ end
+ end
end
end
diff --git a/spec/ruby/library/bigdecimal/mult_spec.rb b/spec/ruby/library/bigdecimal/mult_spec.rb
index b7f8044b0b..2353df9cb8 100644
--- a/spec/ruby/library/bigdecimal/mult_spec.rb
+++ b/spec/ruby/library/bigdecimal/mult_spec.rb
@@ -21,12 +21,4 @@ describe "BigDecimal#mult" do
@e.mult(@one, 1).should be_close(@one, @tolerance)
@e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
end
-
- describe "with Object" do
- it "tries to coerce the other operand to self" do
- object = mock("Object")
- object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
- @e3_minus.mult(object, 1).should == BigDecimal("9")
- end
- end
end
diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb
deleted file mode 100644
index 5fda8d3087..0000000000
--- a/spec/ruby/library/bigdecimal/precs_spec.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require_relative '../../spec_helper'
-require 'bigdecimal'
-
-describe "BigDecimal#precs" do
- before :each do
- @infinity = BigDecimal("Infinity")
- @infinity_neg = BigDecimal("-Infinity")
- @nan = BigDecimal("NaN")
- @zero = BigDecimal("0")
- @zero_neg = BigDecimal("-0")
-
- @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
- @infinity, @infinity_neg, @nan, @zero, @zero_neg]
- @precision = BigDecimal::BASE.to_s.length - 1
- end
-
- it "returns array of two values" do
- suppress_warning do
- @arr.each do |x|
- x.precs.kind_of?(Array).should == true
- x.precs.size.should == 2
- end
- end
- end
-
- it "returns Integers as array values" do
- suppress_warning do
- @arr.each do |x|
- x.precs[0].kind_of?(Integer).should == true
- x.precs[1].kind_of?(Integer).should == true
- end
- end
- end
-
- it "returns the current value of significant digits as the first value" do
- suppress_warning do
- BigDecimal("3.14159").precs[0].should >= 6
- BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
- [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
- value.precs[0].should <= @precision
- end
- end
- end
-
- it "returns the maximum number of significant digits as the second value" do
- suppress_warning do
- BigDecimal("3.14159").precs[1].should >= 6
- BigDecimal('1').precs[1].should >= 1
- BigDecimal('1' + '0' * 100).precs[1].should >= 101
- [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
- value.precs[1].should >= 1
- end
- end
- end
-end
diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb
index bac5f37ba9..0eb06f7ef1 100644
--- a/spec/ruby/library/bigdecimal/remainder_spec.rb
+++ b/spec/ruby/library/bigdecimal/remainder_spec.rb
@@ -37,9 +37,11 @@ describe "BigDecimal#remainder" do
@neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate
end
- it "returns NaN used with zero" do
- @mixed.remainder(@zero).should.nan?
- @zero.remainder(@zero).should.nan?
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "raises ZeroDivisionError used with zero" do
+ -> { @mixed.remainder(@zero) }.should raise_error(ZeroDivisionError)
+ -> { @zero.remainder(@zero) }.should raise_error(ZeroDivisionError)
+ end
end
it "returns zero if used on zero" do
diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb
index fba52df65d..6a4d220417 100644
--- a/spec/ruby/library/bigdecimal/round_spec.rb
+++ b/spec/ruby/library/bigdecimal/round_spec.rb
@@ -228,15 +228,7 @@ describe "BigDecimal#round" do
-> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
end
- version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do
- it 'raise for a non-existent round mode' do
- -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode")
- end
- end
-
- version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do
- it 'raise for a non-existent round mode' do
- -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)")
- end
+ it 'raise for a non-existent round mode' do
+ -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)")
end
end
diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb
index aa5c5a640b..eeb030fd23 100644
--- a/spec/ruby/library/bigdecimal/shared/modulo.rb
+++ b/spec/ruby/library/bigdecimal/shared/modulo.rb
@@ -101,10 +101,16 @@ describe :bigdecimal_modulo, shared: true do
@infinity_minus.send(@method, @infinity).should.nan?
end
- it "returns the dividend if the divisor is Infinity" do
- @one.send(@method, @infinity).should == @one
- @one.send(@method, @infinity_minus).should == @one
- @frac_2.send(@method, @infinity_minus).should == @frac_2
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "returns the dividend if the divisor is Infinity and signs are same" do
+ @one.send(@method, @infinity).should == @one
+ (-@frac_2).send(@method, @infinity_minus).should == -@frac_2
+ end
+
+ it "returns the divisor if the divisor is Infinity and signs are different" do
+ (-@one).send(@method, @infinity).should == @infinity
+ @frac_2.send(@method, @infinity_minus).should == @infinity_minus
+ end
end
it "raises TypeError if the argument cannot be coerced to BigDecimal" do
diff --git a/spec/ruby/library/bigdecimal/shared/power.rb b/spec/ruby/library/bigdecimal/shared/power.rb
index 568a08589b..6dafb638e2 100644
--- a/spec/ruby/library/bigdecimal/shared/power.rb
+++ b/spec/ruby/library/bigdecimal/shared/power.rb
@@ -10,8 +10,8 @@ describe :bigdecimal_power, shared: true do
e = BigDecimal("1.00000000000000000000123456789")
one = BigDecimal("1")
ten = BigDecimal("10")
- # The tolerance is dependent upon the size of BASE_FIG
- tolerance = BigDecimal("1E-70")
+ # Accuracy is at least ndigits(== 30) + DOUBLE_FIG(== 16)
+ tolerance = BigDecimal("1E-46")
ten_powers = BigDecimal("1E10000")
pi = BigDecimal("3.14159265358979")
e3_minus.send(@method, 2).should == e3_minus_power_2
diff --git a/spec/ruby/library/bigdecimal/shared/quo.rb b/spec/ruby/library/bigdecimal/shared/quo.rb
index 46e6d62bf4..18ff2fe9a5 100644
--- a/spec/ruby/library/bigdecimal/shared/quo.rb
+++ b/spec/ruby/library/bigdecimal/shared/quo.rb
@@ -31,6 +31,7 @@ describe :bigdecimal_quo, shared: true do
describe "with Object" do
it "tries to coerce the other operand to self" do
+ skip if @method == :div
object = mock("Object")
object.should_receive(:coerce).with(@one).and_return([@one, @two])
@one.send(@method, object, *@object).should == BigDecimal("0.5")
diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb
index bddfec2186..3b62a0c794 100644
--- a/spec/ruby/library/bigdecimal/sub_spec.rb
+++ b/spec/ruby/library/bigdecimal/sub_spec.rb
@@ -35,14 +35,6 @@ describe "BigDecimal#sub" do
@frac_1.sub(@frac_1, 1000000).should == @zero
end
- describe "with Object" do
- it "tries to coerce the other operand to self" do
- object = mock("Object")
- object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4])
- @frac_3.sub(object, 1).should == BigDecimal("-0.9E15")
- end
- end
-
describe "with Rational" do
it "produces a BigDecimal" do
(@three - Rational(500, 2)).should == BigDecimal('-0.247e3')
diff --git a/spec/ruby/library/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb
index 962609ebaf..0ed56d6d61 100644
--- a/spec/ruby/library/cgi/cookie/domain_spec.rb
+++ b/spec/ruby/library/cgi/cookie/domain_spec.rb
@@ -1,23 +1,26 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#domain" do
- it "returns self's domain" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.domain.should be_nil
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com")
- cookie.domain.should == "example.com"
+ describe "CGI::Cookie#domain" do
+ it "returns self's domain" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.domain.should be_nil
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com")
+ cookie.domain.should == "example.com"
+ end
end
-end
-describe "CGI::Cookie#domain=" do
- it "sets self's domain" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.domain = "test.com"
- cookie.domain.should == "test.com"
+ describe "CGI::Cookie#domain=" do
+ it "sets self's domain" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.domain = "test.com"
+ cookie.domain.should == "test.com"
- cookie.domain = "example.com"
- cookie.domain.should == "example.com"
+ cookie.domain = "example.com"
+ cookie.domain.should == "example.com"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/expires_spec.rb b/spec/ruby/library/cgi/cookie/expires_spec.rb
index c8f26d01cd..c5b2c4faf9 100644
--- a/spec/ruby/library/cgi/cookie/expires_spec.rb
+++ b/spec/ruby/library/cgi/cookie/expires_spec.rb
@@ -1,23 +1,26 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#expires" do
- it "returns self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.expires.should be_nil
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602))
- cookie.expires.should == Time.at(1196524602)
+ describe "CGI::Cookie#expires" do
+ it "returns self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.expires.should be_nil
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602))
+ cookie.expires.should == Time.at(1196524602)
+ end
end
-end
-describe "CGI::Cookie#expires=" do
- it "sets self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.expires = Time.at(1196524602)
- cookie.expires.should == Time.at(1196524602)
+ describe "CGI::Cookie#expires=" do
+ it "sets self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.expires = Time.at(1196524602)
+ cookie.expires.should == Time.at(1196524602)
- cookie.expires = Time.at(1196525000)
- cookie.expires.should == Time.at(1196525000)
+ cookie.expires = Time.at(1196525000)
+ cookie.expires.should == Time.at(1196525000)
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/initialize_spec.rb b/spec/ruby/library/cgi/cookie/initialize_spec.rb
index 4b6e104b10..248f35e78b 100644
--- a/spec/ruby/library/cgi/cookie/initialize_spec.rb
+++ b/spec/ruby/library/cgi/cookie/initialize_spec.rb
@@ -1,147 +1,150 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#initialize when passed String" do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
-
- it "sets the self's name to the passed String" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.name.should == "test-cookie"
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "sets the self's value to an empty Array" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.value.should == []
- end
-
- it "sets self to a non-secure cookie" do
- @cookie.send(:initialize, "test")
- @cookie.secure.should be_false
- end
-
- it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.path.should == ""
- end
-
- it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do
- old_script_name = ENV["SCRIPT_NAME"]
+ describe "CGI::Cookie#initialize when passed String" do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- begin
- ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ it "sets the self's name to the passed String" do
@cookie.send(:initialize, "test-cookie")
- @cookie.path.should == "some/path/"
+ @cookie.name.should == "test-cookie"
+ end
- ENV["SCRIPT_NAME"] = "script.rb"
+ it "sets the self's value to an empty Array" do
@cookie.send(:initialize, "test-cookie")
- @cookie.path.should == ""
+ @cookie.value.should == []
+ end
- ENV["SCRIPT_NAME"] = nil
+ it "sets self to a non-secure cookie" do
+ @cookie.send(:initialize, "test")
+ @cookie.secure.should be_false
+ end
+
+ it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do
@cookie.send(:initialize, "test-cookie")
@cookie.path.should == ""
- ensure
- ENV["SCRIPT_NAME"] = old_script_name
end
- end
- it "does not set self's expiration date" do
- @cookie.expires.should be_nil
- end
+ it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do
+ old_script_name = ENV["SCRIPT_NAME"]
- it "does not set self's domain" do
- @cookie.domain.should be_nil
- end
-end
+ begin
+ ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == "some/path/"
-describe "CGI::Cookie#initialize when passed Hash" do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
+ ENV["SCRIPT_NAME"] = "script.rb"
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == ""
+
+ ENV["SCRIPT_NAME"] = nil
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == ""
+ ensure
+ ENV["SCRIPT_NAME"] = old_script_name
+ end
+ end
+
+ it "does not set self's expiration date" do
+ @cookie.expires.should be_nil
+ end
- it "sets self's contents based on the passed Hash" do
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => ["one", "two", "three"],
- 'path' => 'some/path/',
- 'domain' => 'example.com',
- 'expires' => Time.at(1196524602),
- 'secure' => true)
-
- @cookie.name.should == "test-cookie"
- @cookie.value.should == ["one", "two", "three"]
- @cookie.path.should == "some/path/"
- @cookie.domain.should == "example.com"
- @cookie.expires.should == Time.at(1196524602)
- @cookie.secure.should be_true
+ it "does not set self's domain" do
+ @cookie.domain.should be_nil
+ end
end
- it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do
- old_script_name = ENV["SCRIPT_NAME"]
+ describe "CGI::Cookie#initialize when passed Hash" do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- begin
- ENV["SCRIPT_NAME"] = "some/path/script.rb"
- @cookie.send(:initialize, 'name' => 'test-cookie')
+ it "sets self's contents based on the passed Hash" do
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => ["one", "two", "three"],
+ 'path' => 'some/path/',
+ 'domain' => 'example.com',
+ 'expires' => Time.at(1196524602),
+ 'secure' => true)
+
+ @cookie.name.should == "test-cookie"
+ @cookie.value.should == ["one", "two", "three"]
@cookie.path.should == "some/path/"
+ @cookie.domain.should == "example.com"
+ @cookie.expires.should == Time.at(1196524602)
+ @cookie.secure.should be_true
+ end
- ENV["SCRIPT_NAME"] = "script.rb"
- @cookie.send(:initialize, 'name' => 'test-cookie')
- @cookie.path.should == ""
+ it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do
+ old_script_name = ENV["SCRIPT_NAME"]
- ENV["SCRIPT_NAME"] = nil
- @cookie.send(:initialize, 'name' => 'test-cookie')
- @cookie.path.should == ""
- ensure
- ENV["SCRIPT_NAME"] = old_script_name
+ begin
+ ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == "some/path/"
+
+ ENV["SCRIPT_NAME"] = "script.rb"
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == ""
+
+ ENV["SCRIPT_NAME"] = nil
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == ""
+ ensure
+ ENV["SCRIPT_NAME"] = old_script_name
+ end
end
- end
- it "tries to convert the Hash's 'value' to an Array using #Array" do
- obj = mock("Converted To Array")
- obj.should_receive(:to_ary).and_return(["1", "2", "3"])
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ "1", "2", "3" ]
-
- obj = mock("Converted To Array")
- obj.should_receive(:to_a).and_return(["one", "two", "three"])
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ "one", "two", "three" ]
-
- obj = mock("Put into an Array")
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ obj ]
- end
+ it "tries to convert the Hash's 'value' to an Array using #Array" do
+ obj = mock("Converted To Array")
+ obj.should_receive(:to_ary).and_return(["1", "2", "3"])
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ "1", "2", "3" ]
+
+ obj = mock("Converted To Array")
+ obj.should_receive(:to_a).and_return(["one", "two", "three"])
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ "one", "two", "three" ]
+
+ obj = mock("Put into an Array")
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ obj ]
+ end
- it "raises a ArgumentError when the passed Hash has no 'name' entry" do
- -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError)
- -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError)
+ it "raises a ArgumentError when the passed Hash has no 'name' entry" do
+ -> { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError)
+ -> { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError)
+ end
end
-end
-describe "CGI::Cookie#initialize when passed String, values ..." do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
+ describe "CGI::Cookie#initialize when passed String, values ..." do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- it "sets the self's name to the passed String" do
- @cookie.send(:initialize, "test-cookie", "one", "two", "three")
- @cookie.name.should == "test-cookie"
- end
+ it "sets the self's name to the passed String" do
+ @cookie.send(:initialize, "test-cookie", "one", "two", "three")
+ @cookie.name.should == "test-cookie"
+ end
- it "sets the self's value to an Array containing all passed values" do
- @cookie.send(:initialize, "test-cookie", "one", "two", "three")
- @cookie.value.should == ["one", "two", "three"]
- end
+ it "sets the self's value to an Array containing all passed values" do
+ @cookie.send(:initialize, "test-cookie", "one", "two", "three")
+ @cookie.value.should == ["one", "two", "three"]
+ end
- it "sets self to a non-secure cookie" do
- @cookie.send(:initialize, "test", "one", "two", "three")
- @cookie.secure.should be_false
+ it "sets self to a non-secure cookie" do
+ @cookie.send(:initialize, "test", "one", "two", "three")
+ @cookie.secure.should be_false
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/name_spec.rb b/spec/ruby/library/cgi/cookie/name_spec.rb
index 326a43ade3..4908204e8a 100644
--- a/spec/ruby/library/cgi/cookie/name_spec.rb
+++ b/spec/ruby/library/cgi/cookie/name_spec.rb
@@ -1,23 +1,26 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#name" do
- it "returns self's name" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.name.should == "test-cookie"
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "another-cookie")
- cookie.name.should == "another-cookie"
+ describe "CGI::Cookie#name" do
+ it "returns self's name" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.name.should == "test-cookie"
+
+ cookie = CGI::Cookie.new("name" => "another-cookie")
+ cookie.name.should == "another-cookie"
+ end
end
-end
-describe "CGI::Cookie#name=" do
- it "sets self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.name = "another-name"
- cookie.name.should == "another-name"
+ describe "CGI::Cookie#name=" do
+ it "sets self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.name = "another-name"
+ cookie.name.should == "another-name"
- cookie.name = "and-one-more"
- cookie.name.should == "and-one-more"
+ cookie.name = "and-one-more"
+ cookie.name.should == "and-one-more"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb
index d484c7bad9..bc505c37ba 100644
--- a/spec/ruby/library/cgi/cookie/parse_spec.rb
+++ b/spec/ruby/library/cgi/cookie/parse_spec.rb
@@ -1,26 +1,29 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie.parse" do
- it "parses a raw cookie string into a hash of Cookies" do
- expected = { "test-cookie" => ["one", "two", "three"] }
- CGI::Cookie.parse("test-cookie=one&two&three").should == expected
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] }
- CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected
- end
+ describe "CGI::Cookie.parse" do
+ it "parses a raw cookie string into a hash of Cookies" do
+ expected = { "test-cookie" => ["one", "two", "three"] }
+ CGI::Cookie.parse("test-cookie=one&two&three").should == expected
- it "does not use , for cookie separators" do
- expected = {
- "first-cookie" => ["one", "two"],
- "second-cookie" => ["three", "four,third_cookie=five", "six"]
- }
- CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected
- end
+ expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] }
+ CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected
+ end
+
+ it "does not use , for cookie separators" do
+ expected = {
+ "first-cookie" => ["one", "two"],
+ "second-cookie" => ["three", "four,third_cookie=five", "six"]
+ }
+ CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected
+ end
- it "unescapes the Cookie values" do
- cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
- expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] }
- CGI::Cookie.parse(cookie).should == expected
+ it "unescapes the Cookie values" do
+ cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
+ expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] }
+ CGI::Cookie.parse(cookie).should == expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/path_spec.rb b/spec/ruby/library/cgi/cookie/path_spec.rb
index 8a2f05aa50..13ee5d726b 100644
--- a/spec/ruby/library/cgi/cookie/path_spec.rb
+++ b/spec/ruby/library/cgi/cookie/path_spec.rb
@@ -1,23 +1,26 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#path" do
- it "returns self's path" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.path.should == ""
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/")
- cookie.path.should == "/some/path/"
+ describe "CGI::Cookie#path" do
+ it "returns self's path" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.path.should == ""
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/")
+ cookie.path.should == "/some/path/"
+ end
end
-end
-describe "CGI::Cookie#path=" do
- it "sets self's path" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.path = "/some/path/"
- cookie.path.should == "/some/path/"
+ describe "CGI::Cookie#path=" do
+ it "sets self's path" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.path = "/some/path/"
+ cookie.path.should == "/some/path/"
- cookie.path = "/another/path/"
- cookie.path.should == "/another/path/"
+ cookie.path = "/another/path/"
+ cookie.path.should == "/another/path/"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/secure_spec.rb b/spec/ruby/library/cgi/cookie/secure_spec.rb
index 694bc2eeed..cb38c8c2e0 100644
--- a/spec/ruby/library/cgi/cookie/secure_spec.rb
+++ b/spec/ruby/library/cgi/cookie/secure_spec.rb
@@ -1,70 +1,73 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#secure" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "returns whether self is a secure cookie or not" do
- @cookie.secure = true
- @cookie.secure.should be_true
+ describe "CGI::Cookie#secure" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- @cookie.secure = false
- @cookie.secure.should be_false
- end
-end
+ it "returns whether self is a secure cookie or not" do
+ @cookie.secure = true
+ @cookie.secure.should be_true
-describe "CGI::Cookie#secure= when passed true" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ @cookie.secure = false
+ @cookie.secure.should be_false
+ end
end
- it "returns true" do
- (@cookie.secure = true).should be_true
- end
+ describe "CGI::Cookie#secure= when passed true" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- it "sets self to a secure cookie" do
- @cookie.secure = true
- @cookie.secure.should be_true
- end
-end
+ it "returns true" do
+ (@cookie.secure = true).should be_true
+ end
-describe "CGI::Cookie#secure= when passed false" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "sets self to a secure cookie" do
+ @cookie.secure = true
+ @cookie.secure.should be_true
+ end
end
- it "returns false" do
- (@cookie.secure = false).should be_false
- end
+ describe "CGI::Cookie#secure= when passed false" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- it "sets self to a non-secure cookie" do
- @cookie.secure = false
- @cookie.secure.should be_false
- end
-end
+ it "returns false" do
+ (@cookie.secure = false).should be_false
+ end
-describe "CGI::Cookie#secure= when passed Object" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "sets self to a non-secure cookie" do
+ @cookie.secure = false
+ @cookie.secure.should be_false
+ end
end
- it "does not change self's secure value" do
- @cookie.secure = false
+ describe "CGI::Cookie#secure= when passed Object" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
+
+ it "does not change self's secure value" do
+ @cookie.secure = false
- @cookie.secure = Object.new
- @cookie.secure.should be_false
+ @cookie.secure = Object.new
+ @cookie.secure.should be_false
- @cookie.secure = "Test"
- @cookie.secure.should be_false
+ @cookie.secure = "Test"
+ @cookie.secure.should be_false
- @cookie.secure = true
+ @cookie.secure = true
- @cookie.secure = Object.new
- @cookie.secure.should be_true
+ @cookie.secure = Object.new
+ @cookie.secure.should be_true
- @cookie.secure = "Test"
- @cookie.secure.should be_true
+ @cookie.secure = "Test"
+ @cookie.secure.should be_true
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/to_s_spec.rb b/spec/ruby/library/cgi/cookie/to_s_spec.rb
index da15e6ed2a..20d2579f8d 100644
--- a/spec/ruby/library/cgi/cookie/to_s_spec.rb
+++ b/spec/ruby/library/cgi/cookie/to_s_spec.rb
@@ -1,33 +1,36 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#to_s" do
- it "returns a String representation of self" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.to_s.should == "test-cookie=; path="
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("test-cookie", "value")
- cookie.to_s.should == "test-cookie=value; path="
+ describe "CGI::Cookie#to_s" do
+ it "returns a String representation of self" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.to_s.should == "test-cookie=; path="
- cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
- cookie.to_s.should == "test-cookie=one&two&three; path="
+ cookie = CGI::Cookie.new("test-cookie", "value")
+ cookie.to_s.should == "test-cookie=value; path="
- cookie = CGI::Cookie.new(
- 'name' => 'test-cookie',
- 'value' => ["one", "two", "three"],
- 'path' => 'some/path/',
- 'domain' => 'example.com',
- 'expires' => Time.at(1196524602),
- 'secure' => true)
- cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure"
- end
+ cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
+ cookie.to_s.should == "test-cookie=one&two&three; path="
- it "escapes the self's values" do
- cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}")
- cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path="
- end
+ cookie = CGI::Cookie.new(
+ 'name' => 'test-cookie',
+ 'value' => ["one", "two", "three"],
+ 'path' => 'some/path/',
+ 'domain' => 'example.com',
+ 'expires' => Time.at(1196524602),
+ 'secure' => true)
+ cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure"
+ end
+
+ it "escapes the self's values" do
+ cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}")
+ cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path="
+ end
- it "does not escape tilde" do
- cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path="
+ it "does not escape tilde" do
+ cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path="
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/value_spec.rb b/spec/ruby/library/cgi/cookie/value_spec.rb
index 1d5da3a3ac..672653d7f4 100644
--- a/spec/ruby/library/cgi/cookie/value_spec.rb
+++ b/spec/ruby/library/cgi/cookie/value_spec.rb
@@ -1,76 +1,79 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::Cookie#value" do
- it "returns self's value" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.value.should == []
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("test-cookie", "one")
- cookie.value.should == ["one"]
+ describe "CGI::Cookie#value" do
+ it "returns self's value" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.value.should == []
- cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
- cookie.value.should == ["one", "two", "three"]
+ cookie = CGI::Cookie.new("test-cookie", "one")
+ cookie.value.should == ["one"]
- cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"])
- cookie.value.should == ["one", "two", "three"]
- end
+ cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
+ cookie.value.should == ["one", "two", "three"]
- it "is in synch with self" do
- fail = []
- [
- :pop,
- :shift,
- [:<<, "Hello"],
- [:push, "Hello"],
- [:unshift, "World"],
- [:replace, ["A", "B"]],
- [:[]=, 1, "Set"],
- [:delete, "first"],
- [:delete_at, 0],
- ].each do |method, *args|
- cookie1 = CGI::Cookie.new("test-cookie", "first", "second")
- cookie2 = CGI::Cookie.new("test-cookie", "first", "second")
- cookie1.send(method, *args)
- cookie2.value.send(method, *args)
- fail << method unless cookie1.value == cookie2.value
+ cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"])
+ cookie.value.should == ["one", "two", "three"]
end
- fail.should be_empty
- end
-end
-describe "CGI::Cookie#value=" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "is in synch with self" do
+ fail = []
+ [
+ :pop,
+ :shift,
+ [:<<, "Hello"],
+ [:push, "Hello"],
+ [:unshift, "World"],
+ [:replace, ["A", "B"]],
+ [:[]=, 1, "Set"],
+ [:delete, "first"],
+ [:delete_at, 0],
+ ].each do |method, *args|
+ cookie1 = CGI::Cookie.new("test-cookie", "first", "second")
+ cookie2 = CGI::Cookie.new("test-cookie", "first", "second")
+ cookie1.send(method, *args)
+ cookie2.value.send(method, *args)
+ fail << method unless cookie1.value == cookie2.value
+ end
+ fail.should be_empty
+ end
end
- it "sets self's value" do
- @cookie.value = ["one"]
- @cookie.value.should == ["one"]
+ describe "CGI::Cookie#value=" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- @cookie.value = ["one", "two", "three"]
- @cookie.value.should == ["one", "two", "three"]
- end
+ it "sets self's value" do
+ @cookie.value = ["one"]
+ @cookie.value.should == ["one"]
- it "automatically converts the passed Object to an Array using #Array" do
- @cookie.value = "test"
- @cookie.value.should == ["test"]
+ @cookie.value = ["one", "two", "three"]
+ @cookie.value.should == ["one", "two", "three"]
+ end
- obj = mock("to_a")
- obj.should_receive(:to_a).and_return(["1", "2"])
- @cookie.value = obj
- @cookie.value.should == ["1", "2"]
+ it "automatically converts the passed Object to an Array using #Array" do
+ @cookie.value = "test"
+ @cookie.value.should == ["test"]
- obj = mock("to_ary")
- obj.should_receive(:to_ary).and_return(["1", "2"])
- @cookie.value = obj
- @cookie.value.should == ["1", "2"]
- end
+ obj = mock("to_a")
+ obj.should_receive(:to_a).and_return(["1", "2"])
+ @cookie.value = obj
+ @cookie.value.should == ["1", "2"]
- it "does keep self and the values in sync" do
- @cookie.value = ["one", "two", "three"]
- @cookie[0].should == "one"
- @cookie[1].should == "two"
- @cookie[2].should == "three"
+ obj = mock("to_ary")
+ obj.should_receive(:to_ary).and_return(["1", "2"])
+ @cookie.value = obj
+ @cookie.value.should == ["1", "2"]
+ end
+
+ it "does keep self and the values in sync" do
+ @cookie.value = ["one", "two", "three"]
+ @cookie[0].should == "one"
+ @cookie[1].should == "two"
+ @cookie[2].should == "three"
+ end
end
end
diff --git a/spec/ruby/library/cgi/escapeElement_spec.rb b/spec/ruby/library/cgi/escapeElement_spec.rb
index 148926c453..72c38d6028 100644
--- a/spec/ruby/library/cgi/escapeElement_spec.rb
+++ b/spec/ruby/library/cgi/escapeElement_spec.rb
@@ -1,5 +1,11 @@
require_relative '../../spec_helper'
-require 'cgi'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.escapeElement when passed String, elements, ..." do
it "escapes only the tags of the passed elements in the passed String" do
diff --git a/spec/ruby/library/cgi/escapeHTML_spec.rb b/spec/ruby/library/cgi/escapeHTML_spec.rb
index 421aac5d4a..6e70e87ed7 100644
--- a/spec/ruby/library/cgi/escapeHTML_spec.rb
+++ b/spec/ruby/library/cgi/escapeHTML_spec.rb
@@ -1,5 +1,9 @@
require_relative '../../spec_helper'
-require 'cgi'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.escapeHTML" do
it "escapes special HTML characters (&\"<>') in the passed argument" do
diff --git a/spec/ruby/library/cgi/escapeURIComponent_spec.rb b/spec/ruby/library/cgi/escapeURIComponent_spec.rb
index f05795a2f5..1cea2b786a 100644
--- a/spec/ruby/library/cgi/escapeURIComponent_spec.rb
+++ b/spec/ruby/library/cgi/escapeURIComponent_spec.rb
@@ -1,57 +1,78 @@
require_relative '../../spec_helper'
-require 'cgi'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
-ruby_version_is "3.2" do
- describe "CGI.escapeURIComponent" do
- it "escapes whitespace" do
- string = "&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
- CGI.escapeURIComponent(string).should == '%26%3C%3E%22%20%E3%82%86%E3%82%93%E3%82%86%E3%82%93'
- end
+describe "CGI.escapeURIComponent" do
+ it "percent-encodes characters reserved according to RFC 3986" do
+ # https://www.rfc-editor.org/rfc/rfc3986#section-2.2
+ string = ":/?#[]@!$&'()*+,;="
+ CGI.escapeURIComponent(string).should == "%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D"
+ end
- it "does not escape with unreserved characters" do
- string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
- CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
- end
+ it "does not percent-encode unreserved characters according to RFC 3986" do
+ string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ end
- it "supports String with invalid encoding" do
- string = "\xC0\<\<".dup.force_encoding("UTF-8")
- CGI.escapeURIComponent(string).should == "%C0%3C%3C"
- end
+ it "encodes % character as %25" do
+ CGI.escapeURIComponent("%").should == "%25"
+ end
- it "processes String bytes one by one, not characters" do
- CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2
- end
+ # Compare to .escape which uses "+".
+ it "percent-encodes single whitespace" do
+ CGI.escapeURIComponent(" ").should == "%20"
+ end
- it "raises a TypeError with nil" do
- -> {
- CGI.escapeURIComponent(nil)
- }.should raise_error(TypeError, 'no implicit conversion of nil into String')
- end
+ it "percent-encodes all non-reserved and non-unreserved ASCII characters" do
+ special_set = ":/?#[]@!$&'()*+,;=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ all_other = (0x00..0x7F).filter_map { |i| i.chr unless special_set.include?(i.chr) }.join
+ encoded = CGI.escapeURIComponent(all_other)
+ encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{all_other.length}}\z/)
+ end
- it "encodes empty string" do
- CGI.escapeURIComponent("").should == ""
- end
+ it "percent-encodes non-ASCII bytes" do
+ bytes = (0x80..0xFF).map(&:chr).join
+ encoded = CGI.escapeURIComponent(bytes)
+ encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{bytes.length}}\z/)
+ end
- it "encodes single whitespace" do
- CGI.escapeURIComponent(" ").should == "%20"
- end
+ it "processes multi-byte characters as separate bytes, percent-encoding each one" do
+ CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2
+ end
- it "encodes double whitespace" do
- CGI.escapeURIComponent(" ").should == "%20%20"
- end
+ it "produces a copy of an empty string" do
+ string = "".encode(Encoding::BINARY)
+ encoded = CGI.escapeURIComponent(string)
+ encoded.should == ""
+ encoded.encoding.should == Encoding::BINARY
+ string.should_not.equal?(encoded)
+ end
- it "preserves encoding" do
- string = "whatever".encode("ASCII-8BIT")
- CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT
- end
+ it "preserves string's encoding" do
+ string = "whatever".encode("ASCII-8BIT")
+ CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT
+ end
- it "uses implicit type conversion to String" do
- object = Object.new
- def object.to_str
- "a b"
- end
+ it "processes even strings with invalid encoding, percent-encoding octets as-is" do
+ string = "\xC0<<".dup.force_encoding("UTF-8")
+ CGI.escapeURIComponent(string).should == "%C0%3C%3C"
+ end
- CGI.escapeURIComponent(object).should == "a%20b"
+ it "raises a TypeError with nil" do
+ -> {
+ CGI.escapeURIComponent(nil)
+ }.should raise_error(TypeError, "no implicit conversion of nil into String")
+ end
+
+ it "uses implicit type conversion to String" do
+ object = Object.new
+ def object.to_str
+ "a b"
end
+
+ CGI.escapeURIComponent(object).should == "a%20b"
end
end
diff --git a/spec/ruby/library/cgi/escape_spec.rb b/spec/ruby/library/cgi/escape_spec.rb
index c599a73cf0..55eb0b66c2 100644
--- a/spec/ruby/library/cgi/escape_spec.rb
+++ b/spec/ruby/library/cgi/escape_spec.rb
@@ -1,5 +1,9 @@
require_relative '../../spec_helper'
-require 'cgi'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.escape" do
it "url-encodes the passed argument" do
diff --git a/spec/ruby/library/cgi/htmlextension/a_spec.rb b/spec/ruby/library/cgi/htmlextension/a_spec.rb
index 05b4c2d14c..78d3dec8fa 100644
--- a/spec/ruby/library/cgi/htmlextension/a_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/a_spec.rb
@@ -1,49 +1,52 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#a" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns an 'a'-element, using the passed String as the 'href'-attribute" do
- output = @html.a("http://www.example.com")
- output.should equal_element("A", "HREF" => "http://www.example.com")
+ describe "CGI::HtmlExtension#a" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.a("http://www.example.com") { "Example" }
- output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example")
- end
- end
+ describe "when passed a String" do
+ it "returns an 'a'-element, using the passed String as the 'href'-attribute" do
+ output = @html.a("http://www.example.com")
+ output.should equal_element("A", "HREF" => "http://www.example.com")
+ end
- describe "when passed a Hash" do
- it "returns an 'a'-element, using the passed Hash for attributes" do
- attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
- @html.a(attributes).should equal_element("A", attributes)
+ it "includes the passed block's return value when passed a block" do
+ output = @html.a("http://www.example.com") { "Example" }
+ output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example")
+ end
end
- it "includes the passed block's return value when passed a block" do
- attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
- @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example")
- end
- end
+ describe "when passed a Hash" do
+ it "returns an 'a'-element, using the passed Hash for attributes" do
+ attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
+ @html.a(attributes).should equal_element("A", attributes)
+ end
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>)
+ it "includes the passed block's return value when passed a block" do
+ attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
+ @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example")
+ end
end
- it "returns the doctype declaration for HTML4" do
- CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>)
- end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>)
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/base_spec.rb b/spec/ruby/library/cgi/htmlextension/base_spec.rb
index 877ac321cd..1eedfdea54 100644
--- a/spec/ruby/library/cgi/htmlextension/base_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/base_spec.rb
@@ -1,33 +1,36 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#base" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when bassed a String" do
- it "returns a 'base'-element, using the passed String as the 'href'-attribute" do
- output = @html.base("http://www.example.com")
- output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ describe "CGI::HtmlExtension#base" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.base("http://www.example.com") { "Example" }
- output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
- end
- end
+ describe "when bassed a String" do
+ it "returns a 'base'-element, using the passed String as the 'href'-attribute" do
+ output = @html.base("http://www.example.com")
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ end
- describe "when passed a Hash" do
- it "returns a 'base'-element, using the passed Hash for attributes" do
- output = @html.base("HREF" => "http://www.example.com", "ID" => "test")
- output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ it "ignores a passed block" do
+ output = @html.base("http://www.example.com") { "Example" }
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" }
- output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ describe "when passed a Hash" do
+ it "returns a 'base'-element, using the passed Hash for attributes" do
+ output = @html.base("HREF" => "http://www.example.com", "ID" => "test")
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" }
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
index a7b833b1c5..883e36f78b 100644
--- a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
@@ -1,33 +1,36 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#blockquote" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do
- output = @html.blockquote("http://www.example.com/quotes/foo.html")
- output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html")
+ describe "CGI::HtmlExtension#blockquote" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
- output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!")
- end
- end
+ describe "when passed a String" do
+ it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do
+ output = @html.blockquote("http://www.example.com/quotes/foo.html")
+ output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html")
+ end
- describe "when passed a Hash" do
- it "returns a 'blockquote'-element, using the passed Hash for attributes" do
- output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
- output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ it "includes the passed block's return value when passed a block" do
+ output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
+ output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!")
+ end
end
- it "includes the passed block's return value when passed a block" do
- output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" }
- output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!")
+ describe "when passed a Hash" do
+ it "returns a 'blockquote'-element, using the passed Hash for attributes" do
+ output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ end
+
+ it "includes the passed block's return value when passed a block" do
+ output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" }
+ output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/br_spec.rb b/spec/ruby/library/cgi/htmlextension/br_spec.rb
index dfca121884..23c2cb4a48 100644
--- a/spec/ruby/library/cgi/htmlextension/br_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/br_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#br" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- CGISpecs.cgi_new("html3").br.should == "<BR>"
+ describe "CGI::HtmlExtension#br" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "returns the doctype declaration for HTML4" do
- CGISpecs.cgi_new("html4").br.should == "<BR>"
- end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- CGISpecs.cgi_new("html4Tr").br.should == "<BR>"
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ CGISpecs.cgi_new("html3").br.should == "<BR>"
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ CGISpecs.cgi_new("html4").br.should == "<BR>"
+ end
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ CGISpecs.cgi_new("html4Tr").br.should == "<BR>"
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/caption_spec.rb b/spec/ruby/library/cgi/htmlextension/caption_spec.rb
index 16615028b8..3d3e21ecaa 100644
--- a/spec/ruby/library/cgi/htmlextension/caption_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/caption_spec.rb
@@ -1,33 +1,36 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#caption" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do
- output = @html.caption("left")
- output.should equal_element("CAPTION", "ALIGN" => "left")
+ describe "CGI::HtmlExtension#caption" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.caption("left") { "Capital Cities" }
- output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities")
- end
- end
+ describe "when passed a String" do
+ it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do
+ output = @html.caption("left")
+ output.should equal_element("CAPTION", "ALIGN" => "left")
+ end
- describe "when passed a Hash" do
- it "returns a 'caption'-element, using the passed Hash for attributes" do
- output = @html.caption("ALIGN" => "left", "ID" => "test")
- output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test")
+ it "includes the passed block's return value when passed a block" do
+ output = @html.caption("left") { "Capital Cities" }
+ output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities")
+ end
end
- it "includes the passed block's return value when passed a block" do
- output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" }
- output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities")
+ describe "when passed a Hash" do
+ it "returns a 'caption'-element, using the passed Hash for attributes" do
+ output = @html.caption("ALIGN" => "left", "ID" => "test")
+ output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test")
+ end
+
+ it "includes the passed block's return value when passed a block" do
+ output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" }
+ output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
index 64f852cc52..07163c010e 100644
--- a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
@@ -1,76 +1,79 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#checkbox_group" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed name, values ..." do
- it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do
- output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz"))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox_group" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "allows passing a value inside an Array" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- end
+ describe "when passed name, values ..." do
+ it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do
+ output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz"))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value and the checked state or a label" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value inside an Array" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value, a label and the checked state" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
- output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true)
- output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value as an Array containing the value and the checked state or a label" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
- it "returns an empty String when passed no values" do
- @html.checkbox_group("test").should == ""
- end
+ it "allows passing a value as an Array containing the value, a label and the checked state" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
+ output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
+
+ it "returns an empty String when passed no values" do
+ @html.checkbox_group("test").should == ""
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash to generate the checkbox sequence" do
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "when passed Hash" do
+ it "uses the passed Hash to generate the checkbox sequence" do
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true)
- end
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true)
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
index af76fa1da9..ad87b78061 100644
--- a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
@@ -1,77 +1,80 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#checkbox" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a checkbox-'input'-element without a name" do
- output = @html.checkbox
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.checkbox { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a checkbox-'input'-element without a name" do
+ output = @html.checkbox
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a checkbox-'input'-element with the passed name" do
- output = @html.checkbox("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.checkbox("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a checkbox-'input'-element with the passed name" do
+ output = @html.checkbox("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
- describe "CGI::HtmlExtension#checkbox when passed name, value" do
- it "returns a checkbox-'input'-element with the passed name and value" do
- output = @html.checkbox("test", "test-value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.checkbox("test", "test-value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox when passed name, value" do
+ it "returns a checkbox-'input'-element with the passed name and value" do
+ output = @html.checkbox("test", "test-value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.checkbox("test", "test-value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed name, value, checked" do
- it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do
- output = @html.checkbox("test", "test-value", true)
- output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed name, value, checked" do
+ it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do
+ output = @html.checkbox("test", "test-value", true)
+ output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.checkbox("test", "test-value", false)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ output = @html.checkbox("test", "test-value", false)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.checkbox("test", "test-value", nil)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- end
+ output = @html.checkbox("test", "test-value", nil)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.checkbox("test", "test-value", nil) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox("test", "test-value", nil) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.checkbox(attributes)
- output.should equal_element("INPUT", attributes, "", not_closed: true)
- end
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.checkbox(attributes)
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
- it "ignores a passed block" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.checkbox(attributes) { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.checkbox(attributes) { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
index 9a28a8883b..02af831855 100644
--- a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
@@ -1,27 +1,30 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#doctype" do
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
- CGISpecs.cgi_new("html3").doctype.should == expect
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- it "returns the doctype declaration for HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- CGISpecs.cgi_new("html4").doctype.should == expect
- end
+ describe "CGI::HtmlExtension#doctype" do
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
+ CGISpecs.cgi_new("html3").doctype.should == expect
+ end
- it "returns the doctype declaration for the Frameset version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
- CGISpecs.cgi_new("html4Fr").doctype.should == expect
- end
+ it "returns the doctype declaration for HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+ CGISpecs.cgi_new("html4").doctype.should == expect
+ end
+
+ it "returns the doctype declaration for the Frameset version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
+ CGISpecs.cgi_new("html4Fr").doctype.should == expect
+ end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- CGISpecs.cgi_new("html4Tr").doctype.should == expect
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
+ CGISpecs.cgi_new("html4Tr").doctype.should == expect
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
index 2a0632fd58..eff077b9a2 100644
--- a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
@@ -1,72 +1,75 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#file_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a file-'input'-element without a name and a size of 20" do
- output = @html.file_field
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#file_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.file_field { "test" }
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a file-'input'-element without a name and a size of 20" do
+ output = @html.file_field
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a checkbox-'input'-element with the passed name" do
- output = @html.file_field("Example")
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example") { "test" }
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a checkbox-'input'-element with the passed name" do
+ output = @html.file_field("Example")
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name, size" do
- it "returns a checkbox-'input'-element with the passed name and size" do
- output = @html.file_field("Example", 40)
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("Example") { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example", 40) { "test" }
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed name, size" do
+ it "returns a checkbox-'input'-element with the passed name and size" do
+ output = @html.file_field("Example", 40)
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name, size, maxlength" do
- it "returns a checkbox-'input'-element with the passed name, size and maxlength" do
- output = @html.file_field("Example", 40, 100)
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("Example", 40) { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example", 40, 100) { "test" }
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ describe "when passed name, size, maxlength" do
+ it "returns a checkbox-'input'-element with the passed name, size and maxlength" do
+ output = @html.file_field("Example", 40, 100)
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.file_field("Example", 40, 100) { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
end
- end
- describe "when passed a Hash" do
- it "returns a file-'input'-element using the passed Hash for attributes" do
- output = @html.file_field("NAME" => "test", "SIZE" => 40)
- output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ describe "when passed a Hash" do
+ it "returns a file-'input'-element using the passed Hash for attributes" do
+ output = @html.file_field("NAME" => "test", "SIZE" => 40)
+ output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
- output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100)
- output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true)
- end
+ output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100)
+ output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/form_spec.rb b/spec/ruby/library/cgi/htmlextension/form_spec.rb
index 8c0ac97735..55ac63152b 100644
--- a/spec/ruby/library/cgi/htmlextension/form_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/form_spec.rb
@@ -1,58 +1,61 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#form" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:script_name).and_return("/path/to/some/script")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a 'form'-element" do
- output = @html.form
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
+ describe "CGI::HtmlExtension#form" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:script_name).and_return("/path/to/some/script")
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
- end
- end
+ describe "when passed no arguments" do
+ it "returns a 'form'-element" do
+ output = @html.form
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
+ end
- describe "when passed method" do
- it "returns a 'form'-element with the passed method" do
- output = @html.form("get")
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
- end
- end
+ describe "when passed method" do
+ it "returns a 'form'-element with the passed method" do
+ output = @html.form("get")
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
+ end
- describe "when passed method, action" do
- it "returns a 'form'-element with the passed method and the passed action" do
- output = @html.form("get", "/some/other/script")
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get", "/some/other/script") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
- end
- end
+ describe "when passed method, action" do
+ it "returns a 'form'-element with the passed method and the passed action" do
+ output = @html.form("get", "/some/other/script")
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ end
- describe "when passed method, action, enctype" do
- it "returns a 'form'-element with the passed method, action and enctype" do
- output = @html.form("get", "/some/other/script", "multipart/form-data")
- output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get", "/some/other/script") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ describe "when passed method, action, enctype" do
+ it "returns a 'form'-element with the passed method, action and enctype" do
+ output = @html.form("get", "/some/other/script", "multipart/form-data")
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/frame_spec.rb b/spec/ruby/library/cgi/htmlextension/frame_spec.rb
index 2ddd4e1ef0..fef40849eb 100644
--- a/spec/ruby/library/cgi/htmlextension/frame_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/frame_spec.rb
@@ -1,14 +1,17 @@
require_relative '../../../spec_helper'
-require_relative 'fixtures/common'
-require 'cgi'
-describe "CGI::HtmlExtension#frame" do
- before :each do
- @html = CGISpecs.cgi_new("html4Fr")
- end
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+
+ describe "CGI::HtmlExtension#frame" do
+ before :each do
+ @html = CGISpecs.cgi_new("html4Fr")
+ end
- it "initializes the HTML Generation methods for the Frameset version of HTML4" do
- @html.frameset.should == "<FRAMESET></FRAMESET>"
- @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
index baeb446593..3ad0a9c4d2 100644
--- a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
@@ -1,14 +1,17 @@
require_relative '../../../spec_helper'
-require_relative 'fixtures/common'
-require 'cgi'
-describe "CGI::HtmlExtension#frameset" do
- before :each do
- @html = CGISpecs.cgi_new("html4Fr")
- end
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+
+ describe "CGI::HtmlExtension#frameset" do
+ before :each do
+ @html = CGISpecs.cgi_new("html4Fr")
+ end
- it "initializes the HTML Generation methods for the Frameset version of HTML4" do
- @html.frameset.should == "<FRAMESET></FRAMESET>"
- @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
index 52ebd8c261..b2323775f6 100644
--- a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
@@ -1,59 +1,62 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#hidden" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an hidden-'input'-element without a name" do
- output = @html.hidden
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#hidden" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.hidden { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an hidden-'input'-element without a name" do
+ output = @html.hidden
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an hidden-'input'-element with the passed name" do
- output = @html.hidden("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.hidden("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an hidden-'input'-element with the passed name" do
+ output = @html.hidden("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an hidden-'input'-element with the passed name and value" do
- output = @html.hidden("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.hidden("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an hidden-'input'-element with the passed name and value" do
+ output = @html.hidden("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- attributes = { "NAME" => "test", "VALUE" => "some value" }
- output = @html.hidden("test", "some value")
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- attributes = { "NAME" => "test", "VALUE" => "some value" }
- output = @html.hidden("test", "some value") { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
+ output = @html.hidden("test", "some value")
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
+ output = @html.hidden("test", "some value") { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/html_spec.rb b/spec/ruby/library/cgi/htmlextension/html_spec.rb
index 5d89c82086..60a10fb6b4 100644
--- a/spec/ruby/library/cgi/htmlextension/html_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/html_spec.rb
@@ -1,66 +1,69 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#html" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a self's doctype and an 'html'-element" do
- expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
- @html.html.should == expected
+ describe "CGI::HtmlExtension#html" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
end
- it "includes the passed block when passed a block" do
- expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
- @html.html { "test" }.should == expected
- end
- end
+ describe "when passed no arguments" do
+ it "returns a self's doctype and an 'html'-element" do
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
+ @html.html.should == expected
+ end
- describe "when passed 'PRETTY'" do
- it "returns pretty output when the passed String is 'PRETTY" do
- expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
- @html.html("PRETTY").should == expected
+ it "includes the passed block when passed a block" do
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
+ @html.html { "test" }.should == expected
+ end
end
- it "includes the passed block when passed a block" do
- expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n"
- @html.html("PRETTY") { "test" }.should == expected
- end
- end
+ describe "when passed 'PRETTY'" do
+ it "returns pretty output when the passed String is 'PRETTY" do
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
+ @html.html("PRETTY").should == expected
+ end
- describe "when passed a Hash" do
- it "returns an 'html'-element using the passed Hash for attributes" do
- expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
- @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
+ it "includes the passed block when passed a block" do
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n"
+ @html.html("PRETTY") { "test" }.should == expected
+ end
end
- it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
- @html.html("DOCTYPE" => false).should == "<HTML>"
- @html.html("DOCTYPE" => nil).should == "<HTML>"
- end
- end
+ describe "when passed a Hash" do
+ it "returns an 'html'-element using the passed Hash for attributes" do
+ expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
+ @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
+ end
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
- CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
+ @html.html("DOCTYPE" => false).should == "<HTML>"
+ @html.html("DOCTYPE" => nil).should == "<HTML>"
+ end
end
- it "returns the doctype declaration for HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
- end
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
+ CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+ CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
+ CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
index d14bec9ca3..f8770119d4 100644
--- a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
@@ -1,69 +1,72 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#image_button" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an image-'input'-element without a source image" do
- output = @html.image_button
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#image_button" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.image_button { "test" }
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an image-'input'-element without a source image" do
+ output = @html.image_button
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ end
- describe "when passed src" do
- it "returns an image-'input'-element with the passed src" do
- output = @html.image_button("/path/to/image.png")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button { "test" }
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
- end
- end
+ describe "when passed src" do
+ it "returns an image-'input'-element with the passed src" do
+ output = @html.image_button("/path/to/image.png")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ end
- describe "when passed src, name" do
- it "returns an image-'input'-element with the passed src and name" do
- output = @html.image_button("/path/to/image.png", "test")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png", "test") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
- end
- end
+ describe "when passed src, name" do
+ it "returns an image-'input'-element with the passed src and name" do
+ output = @html.image_button("/path/to/image.png", "test")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ end
- describe "when passed src, name, alt" do
- it "returns an image-'input'-element with the passed src, name and alt" do
- output = @html.image_button("/path/to/image.png", "test", "alternative")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png", "test") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
- end
- end
+ describe "when passed src, name, alt" do
+ it "returns an image-'input'-element with the passed src, name and alt" do
+ output = @html.image_button("/path/to/image.png", "test", "alternative")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a image-'input'-element using the passed Hash for attributes" do
- output = @html.image_button("NAME" => "test", "VALUE" => "test-value")
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" }
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a image-'input'-element using the passed Hash for attributes" do
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value")
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/img_spec.rb b/spec/ruby/library/cgi/htmlextension/img_spec.rb
index 994ae7fedf..a05cfdea48 100644
--- a/spec/ruby/library/cgi/htmlextension/img_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/img_spec.rb
@@ -1,83 +1,86 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#img" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an 'img'-element without an src-url or alt-text" do
- output = @html.img
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ describe "CGI::HtmlExtension#img" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.img { "test" }
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an 'img'-element without an src-url or alt-text" do
+ output = @html.img
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
- describe "when passed src" do
- it "returns an 'img'-element with the passed src-url" do
- output = @html.img("/path/to/some/image.png")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img { "test" }
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed src" do
+ it "returns an 'img'-element with the passed src-url" do
+ output = @html.img("/path/to/some/image.png")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ end
- describe "when passed src, alt" do
- it "returns an 'img'-element with the passed src-url and the passed alt-text" do
- output = @html.img("/path/to/some/image.png", "Alternative")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png", "Alternative") { "test" }
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt" do
+ it "returns an 'img'-element with the passed src-url and the passed alt-text" do
+ output = @html.img("/path/to/some/image.png", "Alternative")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ end
- describe "when passed src, alt, width" do
- it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40)
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png", "Alternative") { "test" }
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" }
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt, width" do
+ it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40)
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ end
- describe "when passed src, alt, width, height" do
- it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40, 60)
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" }
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img { "test" }
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt, width, height" do
+ it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40, 60)
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns an 'img'-element with the passed Hash as attributes" do
- attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
- output = @html.img(attributes)
- output.should equal_element("IMG", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img { "test" }
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
- output = @html.img(attributes) { "test" }
- output.should equal_element("IMG", attributes, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns an 'img'-element with the passed Hash as attributes" do
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
+ output = @html.img(attributes)
+ output.should equal_element("IMG", attributes, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
+ output = @html.img(attributes) { "test" }
+ output.should equal_element("IMG", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
index 0bf2042a33..ee1c45b84e 100644
--- a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
@@ -1,64 +1,67 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#multipart_form" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:script_name).and_return("/path/to/some/script.rb")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a 'form'-element with it's enctype set to multipart" do
- output = @html.multipart_form
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "")
+ describe "CGI::HtmlExtension#multipart_form" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:script_name).and_return("/path/to/some/script.rb")
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test")
- end
- end
+ describe "when passed no arguments" do
+ it "returns a 'form'-element with it's enctype set to multipart" do
+ output = @html.multipart_form
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "")
+ end
- describe "when passed action" do
- it "returns a 'form'-element with the passed action" do
- output = @html.multipart_form("/some/other/script.rb")
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("/some/other/script.rb") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
- end
- end
+ describe "when passed action" do
+ it "returns a 'form'-element with the passed action" do
+ output = @html.multipart_form("/some/other/script.rb")
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ end
- describe "when passed action, enctype" do
- it "returns a 'form'-element with the passed action and enctype" do
- output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded")
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("/some/other/script.rb") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ describe "when passed action, enctype" do
+ it "returns a 'form'-element with the passed action and enctype" do
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded")
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ end
end
- end
- describe "when passed Hash" do
- it "returns a 'form'-element with the passed Hash as attributes" do
- output = @html.multipart_form("ID" => "test")
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "")
+ describe "when passed Hash" do
+ it "returns a 'form'-element with the passed Hash as attributes" do
+ output = @html.multipart_form("ID" => "test")
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "")
- output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get")
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "")
- end
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get")
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("ID" => "test") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("ID" => "test") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test")
- output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test")
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
index 683bc428ba..0fefdd5c45 100644
--- a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
@@ -1,84 +1,87 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#password_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an password-'input'-element without a name" do
- output = @html.password_field
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#password_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.password_field { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an password-'input'-element without a name" do
+ output = @html.password_field
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an password-'input'-element with the passed name" do
- output = @html.password_field("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an password-'input'-element with the passed name" do
+ output = @html.password_field("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an password-'input'-element with the passed name and value" do
- output = @html.password_field("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an password-'input'-element with the passed name and value" do
+ output = @html.password_field("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value, size" do
- it "returns an password-'input'-element with the passed name, value and size" do
- output = @html.password_field("test", "some value", 60)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value", 60) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value, size" do
+ it "returns an password-'input'-element with the passed name, value and size" do
+ output = @html.password_field("test", "some value", 60)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
- describe "when passed name, value, size, maxlength" do
- it "returns an password-'input'-element with the passed name, value, size and maxlength" do
- output = @html.password_field("test", "some value", 60, 12)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value", 60) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value", 60, 12) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ describe "when passed name, value, size, maxlength" do
+ it "returns an password-'input'-element with the passed name, value, size and maxlength" do
+ output = @html.password_field("test", "some value", 60, 12)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value", 60, 12) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- output = @html.password_field("NAME" => "test", "VALUE" => "some value")
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value")
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
- output = @html.password_field("TYPE" => "hidden")
- output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true)
- end
+ output = @html.password_field("TYPE" => "hidden")
+ output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" }
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" }
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
index 3462be09b0..7452d15317 100644
--- a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
@@ -1,8 +1,11 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-require_relative 'shared/popup_menu'
-describe "CGI::HtmlExtension#popup_menu" do
- it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
+ require_relative 'shared/popup_menu'
+
+ describe "CGI::HtmlExtension#popup_menu" do
+ it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu
+ end
end
diff --git a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
index 3dc3c879b5..8458685cdc 100644
--- a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
@@ -1,77 +1,80 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#radio_button" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a radio-'input'-element without a name" do
- output = @html.radio_button
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#radio_button" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.radio_button { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a radio-'input'-element without a name" do
+ output = @html.radio_button
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a radio-'input'-element with the passed name" do
- output = @html.radio_button("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.radio_button("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a radio-'input'-element with the passed name" do
+ output = @html.radio_button("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ end
- describe "CGI::HtmlExtension#checkbox when passed name, value" do
- it "returns a radio-'input'-element with the passed name and value" do
- output = @html.radio_button("test", "test-value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.radio_button("test", "test-value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox when passed name, value" do
+ it "returns a radio-'input'-element with the passed name and value" do
+ output = @html.radio_button("test", "test-value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.radio_button("test", "test-value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed name, value, checked" do
- it "returns a checked radio-'input'-element with the passed name and value when checked is true" do
- output = @html.radio_button("test", "test-value", true)
- output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed name, value, checked" do
+ it "returns a checked radio-'input'-element with the passed name and value when checked is true" do
+ output = @html.radio_button("test", "test-value", true)
+ output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.radio_button("test", "test-value", false)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ output = @html.radio_button("test", "test-value", false)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.radio_button("test", "test-value", nil)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- end
+ output = @html.radio_button("test", "test-value", nil)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.radio_button("test", "test-value", nil) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button("test", "test-value", nil) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a radio-'input'-element using the passed Hash for attributes" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.radio_button(attributes)
- output.should equal_element("INPUT", attributes, "", not_closed: true)
- end
+ describe "when passed Hash" do
+ it "returns a radio-'input'-element using the passed Hash for attributes" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.radio_button(attributes)
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
- it "ignores a passed block" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.radio_button(attributes) { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.radio_button(attributes) { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
index 1bfd43449d..fd925a5165 100644
--- a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
@@ -1,77 +1,80 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#radio_group" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed name, values ..." do
- it "returns a sequence of 'radio'-elements with the passed name and the passed values" do
- output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz"))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "CGI::HtmlExtension#radio_group" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "allows passing a value inside an Array" do
- output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- end
+ describe "when passed name, values ..." do
+ it "returns a sequence of 'radio'-elements with the passed name and the passed values" do
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz"))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value and the checked state or a label" do
- output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value inside an Array" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- # TODO: CGI does not like passing false instead of true.
- it "allows passing a value as an Array containing the value, a label and the checked state" do
- output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
- output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true)
- output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value as an Array containing the value and the checked state or a label" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
- it "returns an empty String when passed no values" do
- @html.radio_group("test").should == ""
- end
+ # TODO: CGI does not like passing false instead of true.
+ it "allows passing a value as an Array containing the value, a label and the checked state" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
+ output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
+
+ it "returns an empty String when passed no values" do
+ @html.radio_group("test").should == ""
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash to generate the radio sequence" do
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "when passed Hash" do
+ it "uses the passed Hash to generate the radio sequence" do
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true)
- end
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true)
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/reset_spec.rb b/spec/ruby/library/cgi/htmlextension/reset_spec.rb
index 86fa25fc8a..80e4441b16 100644
--- a/spec/ruby/library/cgi/htmlextension/reset_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/reset_spec.rb
@@ -1,57 +1,60 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#reset" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a reset-'input'-element" do
- output = @html.reset
- output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#reset" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.reset { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a reset-'input'-element" do
+ output = @html.reset
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ end
- describe "when passed value" do
- it "returns a reset-'input'-element with the passed value" do
- output = @html.reset("Example")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
- end
- end
+ describe "when passed value" do
+ it "returns a reset-'input'-element with the passed value" do
+ output = @html.reset("Example")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
- describe "when passed value, name" do
- it "returns a reset-'input'-element with the passed value and the passed name" do
- output = @html.reset("Example", "test-name")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example", "test-name") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
- end
- end
+ describe "when passed value, name" do
+ it "returns a reset-'input'-element with the passed value and the passed name" do
+ output = @html.reset("Example", "test-name")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a reset-'input'-element with the passed value" do
- output = @html.reset("Example")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset("Example", "test-name") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a reset-'input'-element with the passed value" do
+ output = @html.reset("Example")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.reset("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
index 4eb0c86c1a..b565444679 100644
--- a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
@@ -1,8 +1,11 @@
require_relative '../../../spec_helper'
-require_relative 'fixtures/common'
-require 'cgi'
-require_relative 'shared/popup_menu'
-describe "CGI::HtmlExtension#scrolling_list" do
- it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+ require_relative 'shared/popup_menu'
+
+ describe "CGI::HtmlExtension#scrolling_list" do
+ it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list
+ end
end
diff --git a/spec/ruby/library/cgi/htmlextension/submit_spec.rb b/spec/ruby/library/cgi/htmlextension/submit_spec.rb
index 063891b959..bb6e079c4e 100644
--- a/spec/ruby/library/cgi/htmlextension/submit_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/submit_spec.rb
@@ -1,57 +1,60 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#submit" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a submit-'input'-element" do
- output = @html.submit
- output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#submit" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.submit { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a submit-'input'-element" do
+ output = @html.submit
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ end
- describe "when passed value" do
- it "returns a submit-'input'-element with the passed value" do
- output = @html.submit("Example")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
- end
- end
+ describe "when passed value" do
+ it "returns a submit-'input'-element with the passed value" do
+ output = @html.submit("Example")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
- describe "when passed value, name" do
- it "returns a submit-'input'-element with the passed value and the passed name" do
- output = @html.submit("Example", "test-name")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example", "test-name") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
- end
- end
+ describe "when passed value, name" do
+ it "returns a submit-'input'-element with the passed value and the passed name" do
+ output = @html.submit("Example", "test-name")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a submit-'input'-element with the passed value" do
- output = @html.submit("Example")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit("Example", "test-name") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a submit-'input'-element with the passed value" do
+ output = @html.submit("Example")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.submit("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
index 44b5a5e69f..37e13e3746 100644
--- a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
@@ -1,84 +1,87 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#text_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an text-'input'-element without a name" do
- output = @html.text_field
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#text_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.text_field { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an text-'input'-element without a name" do
+ output = @html.text_field
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an text-'input'-element with the passed name" do
- output = @html.text_field("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an text-'input'-element with the passed name" do
+ output = @html.text_field("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an text-'input'-element with the passed name and value" do
- output = @html.text_field("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an text-'input'-element with the passed name and value" do
+ output = @html.text_field("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value, size" do
- it "returns an text-'input'-element with the passed name, value and size" do
- output = @html.text_field("test", "some value", 60)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value", 60) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value, size" do
+ it "returns an text-'input'-element with the passed name, value and size" do
+ output = @html.text_field("test", "some value", 60)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
- describe "when passed name, value, size, maxlength" do
- it "returns an text-'input'-element with the passed name, value, size and maxlength" do
- output = @html.text_field("test", "some value", 60, 12)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value", 60) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value", 60, 12) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ describe "when passed name, value, size, maxlength" do
+ it "returns an text-'input'-element with the passed name, value, size and maxlength" do
+ output = @html.text_field("test", "some value", 60, 12)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value", 60, 12) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- output = @html.text_field("NAME" => "test", "VALUE" => "some value")
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value")
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
- output = @html.text_field("TYPE" => "hidden")
- output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true)
- end
+ output = @html.text_field("TYPE" => "hidden")
+ output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" }
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" }
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
index db84a973d2..99c6d3dd2d 100644
--- a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
@@ -1,73 +1,76 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'fixtures/common'
-describe "CGI::HtmlExtension#textarea" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an 'textarea'-element without a name" do
- output = @html.textarea
- output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "")
+ describe "CGI::HtmlExtension#textarea" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed no arguments" do
+ it "returns an 'textarea'-element without a name" do
+ output = @html.textarea
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "")
+ end
- describe "when passed name" do
- it "returns an 'textarea'-element with the passed name" do
- output = @html.textarea("test")
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test") { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed name" do
+ it "returns an 'textarea'-element with the passed name" do
+ output = @html.textarea("test")
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "")
+ end
- describe "when passed name, cols" do
- it "returns an 'textarea'-element with the passed name and the passed amount of columns" do
- output = @html.textarea("test", 40)
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test") { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test", 40) { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed name, cols" do
+ it "returns an 'textarea'-element with the passed name and the passed amount of columns" do
+ output = @html.textarea("test", 40)
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "")
+ end
- describe "when passed name, cols, rows" do
- it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do
- output = @html.textarea("test", 40, 5)
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test", 40) { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test", 40, 5) { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example")
+ describe "when passed name, cols, rows" do
+ it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do
+ output = @html.textarea("test", 40, 5)
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test", 40, 5) { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example")
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash as attributes" do
- @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>'
+ describe "when passed Hash" do
+ it "uses the passed Hash as attributes" do
+ @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>'
- attributes = {"ID" => "test-id", "NAME" => "test-name"}
- output = @html.textarea(attributes)
- output.should equal_element("TEXTAREA", attributes, "")
- end
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
+ output = @html.textarea(attributes)
+ output.should equal_element("TEXTAREA", attributes, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- attributes = {"ID" => "test-id", "NAME" => "test-name"}
- output = @html.textarea(attributes) { "test" }
- output.should equal_element("TEXTAREA", attributes, "test")
+ it "includes the return value of the passed block when passed a block" do
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
+ output = @html.textarea(attributes) { "test" }
+ output.should equal_element("TEXTAREA", attributes, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/http_header_spec.rb b/spec/ruby/library/cgi/http_header_spec.rb
index 4094bebed3..8d9f3fe9b8 100644
--- a/spec/ruby/library/cgi/http_header_spec.rb
+++ b/spec/ruby/library/cgi/http_header_spec.rb
@@ -1,8 +1,11 @@
require_relative '../../spec_helper'
-require 'cgi'
-require_relative 'shared/http_header'
+ruby_version_is ""..."4.0" do
+ require 'cgi'
-describe "CGI#http_header" do
- it_behaves_like :cgi_http_header, :http_header
+ require_relative 'shared/http_header'
+
+ describe "CGI#http_header" do
+ it_behaves_like :cgi_http_header, :http_header
+ end
end
diff --git a/spec/ruby/library/cgi/initialize_spec.rb b/spec/ruby/library/cgi/initialize_spec.rb
index 61bc971d49..b8ecf5cac2 100644
--- a/spec/ruby/library/cgi/initialize_spec.rb
+++ b/spec/ruby/library/cgi/initialize_spec.rb
@@ -1,133 +1,136 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI#initialize" do
- it "is private" do
- CGI.should have_private_instance_method(:initialize)
- end
-end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
-describe "CGI#initialize when passed no arguments" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.allocate
- end
-
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "extends self with CGI::QueryExtension" do
- @cgi.send(:initialize)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ describe "CGI#initialize" do
+ it "is private" do
+ CGI.should have_private_instance_method(:initialize)
+ end
end
- it "does not extend self with CGI::HtmlExtension" do
- @cgi.send(:initialize)
- @cgi.should_not be_kind_of(CGI::HtmlExtension)
- end
+ describe "CGI#initialize when passed no arguments" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.allocate
+ end
- it "does not extend self with any of the other HTML modules" do
- @cgi.send(:initialize)
- @cgi.should_not be_kind_of(CGI::HtmlExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "sets #cookies based on ENV['HTTP_COOKIE']" do
- begin
- old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay"
+ it "extends self with CGI::QueryExtension" do
@cgi.send(:initialize)
- @cgi.cookies.should == { "test"=>[ "test yay" ] }
- ensure
- ENV["HTTP_COOKIE"] = old_env
+ @cgi.should be_kind_of(CGI::QueryExtension)
end
- end
- it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do
- begin
- old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
- old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET"
+ it "does not extend self with CGI::HtmlExtension" do
@cgi.send(:initialize)
- @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
- ensure
- ENV["QUERY_STRING"] = old_env_query
- ENV["REQUEST_METHOD"] = old_env_method
+ @cgi.should_not be_kind_of(CGI::HtmlExtension)
end
- end
- it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do
- begin
- old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
- old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD"
+ it "does not extend self with any of the other HTML modules" do
@cgi.send(:initialize)
- @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
- ensure
- ENV["QUERY_STRING"] = old_env_query
- ENV["REQUEST_METHOD"] = old_env_method
+ @cgi.should_not be_kind_of(CGI::HtmlExtension)
+ @cgi.should_not be_kind_of(CGI::Html3)
+ @cgi.should_not be_kind_of(CGI::Html4)
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
end
- end
-end
-describe "CGI#initialize when passed type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.allocate
- end
+ it "sets #cookies based on ENV['HTTP_COOKIE']" do
+ begin
+ old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay"
+ @cgi.send(:initialize)
+ @cgi.cookies.should == { "test"=>[ "test yay" ] }
+ ensure
+ ENV["HTTP_COOKIE"] = old_env
+ end
+ end
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do
+ begin
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET"
+ @cgi.send(:initialize)
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
+ ensure
+ ENV["QUERY_STRING"] = old_env_query
+ ENV["REQUEST_METHOD"] = old_env_method
+ end
+ end
+
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do
+ begin
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD"
+ @cgi.send(:initialize)
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
+ ensure
+ ENV["QUERY_STRING"] = old_env_query
+ ENV["REQUEST_METHOD"] = old_env_method
+ end
+ end
end
+ describe "CGI#initialize when passed type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.allocate
+ end
- it "extends self with CGI::QueryExtension" do
- @cgi.send(:initialize, "test")
- @cgi.should be_kind_of(CGI::QueryExtension)
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do
- @cgi.send(:initialize, "html3")
- @cgi.should be_kind_of(CGI::Html3)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ it "extends self with CGI::QueryExtension" do
+ @cgi.send(:initialize, "test")
+ @cgi.should be_kind_of(CGI::QueryExtension)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do
- @cgi.send(:initialize, "html4")
- @cgi.should be_kind_of(CGI::Html4)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do
+ @cgi.send(:initialize, "html3")
+ @cgi.should be_kind_of(CGI::Html3)
+ @cgi.should be_kind_of(CGI::HtmlExtension)
+ @cgi.should be_kind_of(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ @cgi.should_not be_kind_of(CGI::Html4)
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do
- @cgi.send(:initialize, "html4Tr")
- @cgi.should be_kind_of(CGI::Html4Tr)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do
+ @cgi.send(:initialize, "html4")
+ @cgi.should be_kind_of(CGI::Html4)
+ @cgi.should be_kind_of(CGI::HtmlExtension)
+ @cgi.should be_kind_of(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ @cgi.should_not be_kind_of(CGI::Html3)
+ @cgi.should_not be_kind_of(CGI::Html4Tr)
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do
- @cgi.send(:initialize, "html4Fr")
- @cgi.should be_kind_of(CGI::Html4Tr)
- @cgi.should be_kind_of(CGI::Html4Fr)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do
+ @cgi.send(:initialize, "html4Tr")
+ @cgi.should be_kind_of(CGI::Html4Tr)
+ @cgi.should be_kind_of(CGI::HtmlExtension)
+ @cgi.should be_kind_of(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4)
+ @cgi.should_not be_kind_of(CGI::Html3)
+ @cgi.should_not be_kind_of(CGI::Html4)
+ @cgi.should_not be_kind_of(CGI::Html4Fr)
+ end
+
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do
+ @cgi.send(:initialize, "html4Fr")
+ @cgi.should be_kind_of(CGI::Html4Tr)
+ @cgi.should be_kind_of(CGI::Html4Fr)
+ @cgi.should be_kind_of(CGI::HtmlExtension)
+ @cgi.should be_kind_of(CGI::QueryExtension)
+
+ @cgi.should_not be_kind_of(CGI::Html3)
+ @cgi.should_not be_kind_of(CGI::Html4)
+ end
end
end
diff --git a/spec/ruby/library/cgi/out_spec.rb b/spec/ruby/library/cgi/out_spec.rb
index bc09f5bcbb..733e656ea1 100644
--- a/spec/ruby/library/cgi/out_spec.rb
+++ b/spec/ruby/library/cgi/out_spec.rb
@@ -1,51 +1,54 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI#out" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- $stdout, @old_stdout = IOStub.new, $stdout
- end
-
- after :each do
- $stdout = @old_stdout
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "it writes a HTMl header based on the passed argument to $stdout" do
- @cgi.out { "" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n"
- end
-
- it "appends the block's return value to the HTML header" do
- @cgi.out { "test!" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!"
- end
-
- it "automatically sets the Content-Length Header based on the block's return value" do
- @cgi.out { "0123456789" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789"
- end
-
- it "includes Cookies in the @output_cookies field" do
- @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
- @cgi.out { "" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
- end
-end
-
-describe "CGI#out when passed no block" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
-
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "raises a LocalJumpError" do
- -> { @cgi.out }.should raise_error(LocalJumpError)
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI#out" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ $stdout, @old_stdout = IOStub.new, $stdout
+ end
+
+ after :each do
+ $stdout = @old_stdout
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+ it "it writes a HTMl header based on the passed argument to $stdout" do
+ @cgi.out { "" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n"
+ end
+
+ it "appends the block's return value to the HTML header" do
+ @cgi.out { "test!" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!"
+ end
+
+ it "automatically sets the Content-Length Header based on the block's return value" do
+ @cgi.out { "0123456789" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789"
+ end
+
+ it "includes Cookies in the @output_cookies field" do
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
+ @cgi.out { "" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+ end
+
+ describe "CGI#out when passed no block" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+ it "raises a LocalJumpError" do
+ -> { @cgi.out }.should raise_error(LocalJumpError)
+ end
end
end
diff --git a/spec/ruby/library/cgi/parse_spec.rb b/spec/ruby/library/cgi/parse_spec.rb
index 04539b1226..f09270c195 100644
--- a/spec/ruby/library/cgi/parse_spec.rb
+++ b/spec/ruby/library/cgi/parse_spec.rb
@@ -1,24 +1,27 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI.parse when passed String" do
- it "parses a HTTP Query String into a Hash" do
- CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] }
- CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] }
- CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "parses query strings with semicolons in place of ampersands" do
- CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] }
- CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
- end
+ describe "CGI.parse when passed String" do
+ it "parses a HTTP Query String into a Hash" do
+ CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] }
+ CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] }
+ CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
+ end
- it "allows passing multiple values for one key" do
- CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] }
- CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] }
- end
+ it "parses query strings with semicolons in place of ampersands" do
+ CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] }
+ CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
+ end
+
+ it "allows passing multiple values for one key" do
+ CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] }
+ CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] }
+ end
- it "unescapes keys and values" do
- CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] }
+ it "unescapes keys and values" do
+ CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] }
+ end
end
end
diff --git a/spec/ruby/library/cgi/pretty_spec.rb b/spec/ruby/library/cgi/pretty_spec.rb
index a7b7505c15..9df1611037 100644
--- a/spec/ruby/library/cgi/pretty_spec.rb
+++ b/spec/ruby/library/cgi/pretty_spec.rb
@@ -1,24 +1,27 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI.pretty when passed html" do
- it "indents the passed html String with two spaces" do
- CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI.pretty when passed html" do
+ it "indents the passed html String with two spaces" do
+ CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS
<HTML>
<BODY>
</BODY>
</HTML>
EOS
+ end
end
-end
-describe "CGI.pretty when passed html, indentation_unit" do
- it "indents the passed html String with the passed indentation_unit" do
- CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS
+ describe "CGI.pretty when passed html, indentation_unit" do
+ it "indents the passed html String with the passed indentation_unit" do
+ CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS
<HTML>
\t<BODY>
\t</BODY>
</HTML>
EOS
+ end
end
end
diff --git a/spec/ruby/library/cgi/print_spec.rb b/spec/ruby/library/cgi/print_spec.rb
index 18ab8d673b..f4f461c5c0 100644
--- a/spec/ruby/library/cgi/print_spec.rb
+++ b/spec/ruby/library/cgi/print_spec.rb
@@ -1,26 +1,29 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI#print" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI#print" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
- it "passes all arguments to $stdout.print" do
- $stdout.should_receive(:print).with("test")
- @cgi.print("test")
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"])
- @cgi.print("one", "two", "three", ["four", "five"])
- end
+ it "passes all arguments to $stdout.print" do
+ $stdout.should_receive(:print).with("test")
+ @cgi.print("test")
+
+ $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"])
+ @cgi.print("one", "two", "three", ["four", "five"])
+ end
- it "returns the result of calling $stdout.print" do
- $stdout.should_receive(:print).with("test").and_return(:expected)
- @cgi.print("test").should == :expected
+ it "returns the result of calling $stdout.print" do
+ $stdout.should_receive(:print).with("test").and_return(:expected)
+ @cgi.print("test").should == :expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
index 0487569b9c..be05f0c175 100644
--- a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#accept_charset" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_charset" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_CHARSET']" do
- old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
- begin
- @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
- ensure
- ENV['HTTP_ACCEPT_CHARSET'] = old_value
+ it "returns ENV['HTTP_ACCEPT_CHARSET']" do
+ old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
+ begin
+ @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
+ ensure
+ ENV['HTTP_ACCEPT_CHARSET'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
index 35ff3c2b30..42eb4a49b5 100644
--- a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#accept_encoding" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_encoding" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_ENCODING']" do
- old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate"
- begin
- @cgi.accept_encoding.should == "gzip,deflate"
- ensure
- ENV['HTTP_ACCEPT_ENCODING'] = old_value
+ it "returns ENV['HTTP_ACCEPT_ENCODING']" do
+ old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate"
+ begin
+ @cgi.accept_encoding.should == "gzip,deflate"
+ ensure
+ ENV['HTTP_ACCEPT_ENCODING'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
index 4a15d58914..19f29c6345 100644
--- a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#accept_language" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_language" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do
- old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5"
- begin
- @cgi.accept_language.should == "en-us,en;q=0.5"
- ensure
- ENV['HTTP_ACCEPT_LANGUAGE'] = old_value
+ it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do
+ old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5"
+ begin
+ @cgi.accept_language.should == "en-us,en;q=0.5"
+ ensure
+ ENV['HTTP_ACCEPT_LANGUAGE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_spec.rb b/spec/ruby/library/cgi/queryextension/accept_spec.rb
index af5209ffbe..dcae39a736 100644
--- a/spec/ruby/library/cgi/queryextension/accept_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#accept" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT']" do
- old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
- begin
- @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
- ensure
- ENV['HTTP_ACCEPT'] = old_value
+ it "returns ENV['HTTP_ACCEPT']" do
+ old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
+ begin
+ @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
+ ensure
+ ENV['HTTP_ACCEPT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
index 25318269b1..75e9cdb27a 100644
--- a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#auth_type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#auth_type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['AUTH_TYPE']" do
- old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic"
- begin
- @cgi.auth_type.should == "Basic"
- ensure
- ENV['AUTH_TYPE'] = old_value
+ it "returns ENV['AUTH_TYPE']" do
+ old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic"
+ begin
+ @cgi.auth_type.should == "Basic"
+ ensure
+ ENV['AUTH_TYPE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
index 0471307c22..c4b727e671 100644
--- a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#cache_control" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#cache_control" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_CACHE_CONTROL']" do
- old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache"
- begin
- @cgi.cache_control.should == "no-cache"
- ensure
- ENV['HTTP_CACHE_CONTROL'] = old_value
+ it "returns ENV['HTTP_CACHE_CONTROL']" do
+ old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache"
+ begin
+ @cgi.cache_control.should == "no-cache"
+ ensure
+ ENV['HTTP_CACHE_CONTROL'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/content_length_spec.rb b/spec/ruby/library/cgi/queryextension/content_length_spec.rb
index de823f7119..a8b87e148c 100644
--- a/spec/ruby/library/cgi/queryextension/content_length_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/content_length_spec.rb
@@ -1,26 +1,29 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#content_length" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#content_length" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['CONTENT_LENGTH'] as Integer" do
- old_value = ENV['CONTENT_LENGTH']
- begin
- ENV['CONTENT_LENGTH'] = nil
- @cgi.content_length.should be_nil
+ it "returns ENV['CONTENT_LENGTH'] as Integer" do
+ old_value = ENV['CONTENT_LENGTH']
+ begin
+ ENV['CONTENT_LENGTH'] = nil
+ @cgi.content_length.should be_nil
- ENV['CONTENT_LENGTH'] = "100"
- @cgi.content_length.should eql(100)
- ensure
- ENV['CONTENT_LENGTH'] = old_value
+ ENV['CONTENT_LENGTH'] = "100"
+ @cgi.content_length.should eql(100)
+ ensure
+ ENV['CONTENT_LENGTH'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/content_type_spec.rb b/spec/ruby/library/cgi/queryextension/content_type_spec.rb
index 49b8389c87..d3cbdf0b14 100644
--- a/spec/ruby/library/cgi/queryextension/content_type_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/content_type_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#content_type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#content_type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['CONTENT_TYPE']" do
- old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html"
- begin
- @cgi.content_type.should == "text/html"
- ensure
- ENV['CONTENT_TYPE'] = old_value
+ it "returns ENV['CONTENT_TYPE']" do
+ old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html"
+ begin
+ @cgi.content_type.should == "text/html"
+ ensure
+ ENV['CONTENT_TYPE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/cookies_spec.rb b/spec/ruby/library/cgi/queryextension/cookies_spec.rb
index 4befd61ab7..266fe0c721 100644
--- a/spec/ruby/library/cgi/queryextension/cookies_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/cookies_spec.rb
@@ -1,10 +1,13 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#cookies" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI::QueryExtension#cookies" do
+ it "needs to be reviewed for spec completeness"
+ end
-describe "CGI::QueryExtension#cookies=" do
- it "needs to be reviewed for spec completeness"
+ describe "CGI::QueryExtension#cookies=" do
+ it "needs to be reviewed for spec completeness"
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
index 6ac5b46407..0b57387efc 100644
--- a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
@@ -1,27 +1,30 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#[]" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['QUERY_STRING'] = @old_query_string
- end
+ describe "CGI::QueryExtension#[]" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING']
+ @cgi = CGI.new
+ end
- it "it returns the value for the parameter with the given key" do
- @cgi["one"].should == "a"
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['QUERY_STRING'] = @old_query_string
+ end
- it "only returns the first value for parameters with multiple values" do
- @cgi["two"].should == "b"
- end
+ it "it returns the value for the parameter with the given key" do
+ @cgi["one"].should == "a"
+ end
+
+ it "only returns the first value for parameters with multiple values" do
+ @cgi["two"].should == "b"
+ end
- it "returns a String" do
- @cgi["one"].should be_kind_of(String)
+ it "returns a String" do
+ @cgi["one"].should be_kind_of(String)
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/from_spec.rb b/spec/ruby/library/cgi/queryextension/from_spec.rb
index 04a992cfc7..b341e0be10 100644
--- a/spec/ruby/library/cgi/queryextension/from_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/from_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#from" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#from" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_FROM']" do
- old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com"
- begin
- @cgi.from.should == "googlebot(at)googlebot.com"
- ensure
- ENV['HTTP_FROM'] = old_value
+ it "returns ENV['HTTP_FROM']" do
+ old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com"
+ begin
+ @cgi.from.should == "googlebot(at)googlebot.com"
+ ensure
+ ENV['HTTP_FROM'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
index 3ead5bd8bf..c82522326b 100644
--- a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#gateway_interface" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#gateway_interface" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['GATEWAY_INTERFACE']" do
- old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1"
- begin
- @cgi.gateway_interface.should == "CGI/1.1"
- ensure
- ENV['GATEWAY_INTERFACE'] = old_value
+ it "returns ENV['GATEWAY_INTERFACE']" do
+ old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1"
+ begin
+ @cgi.gateway_interface.should == "CGI/1.1"
+ ensure
+ ENV['GATEWAY_INTERFACE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/has_key_spec.rb b/spec/ruby/library/cgi/queryextension/has_key_spec.rb
index 525b45b507..43f7aae1b2 100644
--- a/spec/ruby/library/cgi/queryextension/has_key_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/has_key_spec.rb
@@ -1,7 +1,10 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'shared/has_key'
-describe "CGI::QueryExtension#has_key?" do
- it_behaves_like :cgi_query_extension_has_key_p, :has_key?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#has_key?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :has_key?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/host_spec.rb b/spec/ruby/library/cgi/queryextension/host_spec.rb
index e820e0afc3..e1047c942b 100644
--- a/spec/ruby/library/cgi/queryextension/host_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/host_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#host" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#host" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_HOST']" do
- old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost"
- begin
- @cgi.host.should == "localhost"
- ensure
- ENV['HTTP_HOST'] = old_value
+ it "returns ENV['HTTP_HOST']" do
+ old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost"
+ begin
+ @cgi.host.should == "localhost"
+ ensure
+ ENV['HTTP_HOST'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/include_spec.rb b/spec/ruby/library/cgi/queryextension/include_spec.rb
index 12365ea284..7275c309f9 100644
--- a/spec/ruby/library/cgi/queryextension/include_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/include_spec.rb
@@ -1,7 +1,10 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'shared/has_key'
-describe "CGI::QueryExtension#include?" do
- it_behaves_like :cgi_query_extension_has_key_p, :include?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#include?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :include?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/key_spec.rb b/spec/ruby/library/cgi/queryextension/key_spec.rb
index d0f1e4cee2..dc2f52fbe0 100644
--- a/spec/ruby/library/cgi/queryextension/key_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/key_spec.rb
@@ -1,7 +1,10 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require_relative 'shared/has_key'
-describe "CGI::QueryExtension#key?" do
- it_behaves_like :cgi_query_extension_has_key_p, :key?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#key?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :key?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/keys_spec.rb b/spec/ruby/library/cgi/queryextension/keys_spec.rb
index 14d77180fa..bb16914065 100644
--- a/spec/ruby/library/cgi/queryextension/keys_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/keys_spec.rb
@@ -1,20 +1,23 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#keys" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING']
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- @cgi = CGI.new
- end
+ describe "CGI::QueryExtension#keys" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING']
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['QUERY_STRING'] = @old_query_string
- end
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['QUERY_STRING'] = @old_query_string
+ end
- it "returns all parameter keys as an Array" do
- @cgi.keys.sort.should == ["one", "two"]
+ it "returns all parameter keys as an Array" do
+ @cgi.keys.sort.should == ["one", "two"]
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/multipart_spec.rb b/spec/ruby/library/cgi/queryextension/multipart_spec.rb
index ced4cb05a1..281791892c 100644
--- a/spec/ruby/library/cgi/queryextension/multipart_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/multipart_spec.rb
@@ -1,20 +1,22 @@
require_relative '../../../spec_helper'
-require 'cgi'
-require "stringio"
-describe "CGI::QueryExtension#multipart?" do
- before :each do
- @old_stdin = $stdin
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require "stringio"
- @old_request_method = ENV['REQUEST_METHOD']
- @old_content_type = ENV['CONTENT_TYPE']
- @old_content_length = ENV['CONTENT_LENGTH']
+ describe "CGI::QueryExtension#multipart?" do
+ before :each do
+ @old_stdin = $stdin
- ENV['REQUEST_METHOD'] = "POST"
- ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729"
- ENV["CONTENT_LENGTH"] = "222"
+ @old_request_method = ENV['REQUEST_METHOD']
+ @old_content_type = ENV['CONTENT_TYPE']
+ @old_content_length = ENV['CONTENT_LENGTH']
- $stdin = StringIO.new <<-EOS
+ ENV['REQUEST_METHOD'] = "POST"
+ ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729"
+ ENV["CONTENT_LENGTH"] = "222"
+
+ $stdin = StringIO.new <<-EOS
-----------------------------1137522503144128232716531729\r
Content-Disposition: form-data; name="file"; filename=""\r
Content-Type: application/octet-stream\r
@@ -23,18 +25,19 @@ Content-Type: application/octet-stream\r
-----------------------------1137522503144128232716531729--\r
EOS
- @cgi = CGI.new
- end
+ @cgi = CGI.new
+ end
- after :each do
- $stdin = @old_stdin
+ after :each do
+ $stdin = @old_stdin
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['CONTENT_TYPE'] = @old_content_type
- ENV['CONTENT_LENGTH'] = @old_content_length
- end
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['CONTENT_TYPE'] = @old_content_type
+ ENV['CONTENT_LENGTH'] = @old_content_length
+ end
- it "returns true if the current Request is a multipart request" do
- @cgi.multipart?.should be_true
+ it "returns true if the current Request is a multipart request" do
+ @cgi.multipart?.should be_true
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
index b6fe036042..4083e6a8cd 100644
--- a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#negotiate" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#negotiate" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_NEGOTIATE']" do
- old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans"
- begin
- @cgi.negotiate.should == "trans"
- ensure
- ENV['HTTP_NEGOTIATE'] = old_value
+ it "returns ENV['HTTP_NEGOTIATE']" do
+ old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans"
+ begin
+ @cgi.negotiate.should == "trans"
+ ensure
+ ENV['HTTP_NEGOTIATE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/params_spec.rb b/spec/ruby/library/cgi/queryextension/params_spec.rb
index f4449e3c8a..938028ea14 100644
--- a/spec/ruby/library/cgi/queryextension/params_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/params_spec.rb
@@ -1,37 +1,40 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#params" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['QUERY_STRING'] = @old_query_string
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#params" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING']
+ @cgi = CGI.new
+ end
- it "returns the parsed HTTP Query Params" do
- @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]}
- end
-end
+ after :each do
+ ENV['QUERY_STRING'] = @old_query_string
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
-describe "CGI::QueryExtension#params=" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
+ it "returns the parsed HTTP Query Params" do
+ @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]}
+ end
end
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#params=" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "sets the HTTP Query Params to the passed argument" do
- @cgi.params.should == {}
+ it "sets the HTTP Query Params to the passed argument" do
+ @cgi.params.should == {}
- @cgi.params = {"one"=>["a"], "two"=>["b", "c"]}
- @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]}
+ @cgi.params = {"one"=>["a"], "two"=>["b", "c"]}
+ @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]}
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/path_info_spec.rb b/spec/ruby/library/cgi/queryextension/path_info_spec.rb
index 9785df85f1..9b7834c514 100644
--- a/spec/ruby/library/cgi/queryextension/path_info_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/path_info_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#path_info" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#path_info" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['PATH_INFO']" do
- old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path"
- begin
- @cgi.path_info.should == "/test/path"
- ensure
- ENV['PATH_INFO'] = old_value
+ it "returns ENV['PATH_INFO']" do
+ old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path"
+ begin
+ @cgi.path_info.should == "/test/path"
+ ensure
+ ENV['PATH_INFO'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
index 417a749341..a773aaafdb 100644
--- a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#path_translated" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#path_translated" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['PATH_TRANSLATED']" do
- old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir"
- begin
- @cgi.path_translated.should == "/full/path/to/dir"
- ensure
- ENV['PATH_TRANSLATED'] = old_value
+ it "returns ENV['PATH_TRANSLATED']" do
+ old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir"
+ begin
+ @cgi.path_translated.should == "/full/path/to/dir"
+ ensure
+ ENV['PATH_TRANSLATED'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/pragma_spec.rb b/spec/ruby/library/cgi/queryextension/pragma_spec.rb
index 02d5c91221..be384182a5 100644
--- a/spec/ruby/library/cgi/queryextension/pragma_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/pragma_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#pragma" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#pragma" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_PRAGMA']" do
- old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache"
- begin
- @cgi.pragma.should == "no-cache"
- ensure
- ENV['HTTP_PRAGMA'] = old_value
+ it "returns ENV['HTTP_PRAGMA']" do
+ old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache"
+ begin
+ @cgi.pragma.should == "no-cache"
+ ensure
+ ENV['HTTP_PRAGMA'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/query_string_spec.rb b/spec/ruby/library/cgi/queryextension/query_string_spec.rb
index a6b454a7eb..64fbeaea10 100644
--- a/spec/ruby/library/cgi/queryextension/query_string_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/query_string_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#query_string" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#query_string" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['QUERY_STRING']" do
- old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b"
- begin
- @cgi.query_string.should == "one=a&two=b"
- ensure
- ENV['QUERY_STRING'] = old_value
+ it "returns ENV['QUERY_STRING']" do
+ old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b"
+ begin
+ @cgi.query_string.should == "one=a&two=b"
+ ensure
+ ENV['QUERY_STRING'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
index 3d7072e346..30d314aca1 100644
--- a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#raw_cookie2" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#raw_cookie2" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_COOKIE2']" do
- old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data"
- begin
- @cgi.raw_cookie2.should == "some_cookie=data"
- ensure
- ENV['HTTP_COOKIE2'] = old_value
+ it "returns ENV['HTTP_COOKIE2']" do
+ old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data"
+ begin
+ @cgi.raw_cookie2.should == "some_cookie=data"
+ ensure
+ ENV['HTTP_COOKIE2'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
index ede7b9ff87..affa504b39 100644
--- a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#raw_cookie" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#raw_cookie" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_COOKIE']" do
- old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data"
- begin
- @cgi.raw_cookie.should == "some_cookie=data"
- ensure
- ENV['HTTP_COOKIE'] = old_value
+ it "returns ENV['HTTP_COOKIE']" do
+ old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data"
+ begin
+ @cgi.raw_cookie.should == "some_cookie=data"
+ ensure
+ ENV['HTTP_COOKIE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/referer_spec.rb b/spec/ruby/library/cgi/queryextension/referer_spec.rb
index 6cd5dc96f8..53fc19ddd0 100644
--- a/spec/ruby/library/cgi/queryextension/referer_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/referer_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#referer" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#referer" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_REFERER']" do
- old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com"
- begin
- @cgi.referer.should == "example.com"
- ensure
- ENV['HTTP_REFERER'] = old_value
+ it "returns ENV['HTTP_REFERER']" do
+ old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com"
+ begin
+ @cgi.referer.should == "example.com"
+ ensure
+ ENV['HTTP_REFERER'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
index 0259402b23..7b5addc2d5 100644
--- a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#remote_addr" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_addr" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_ADDR']" do
- old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1"
- begin
- @cgi.remote_addr.should == "127.0.0.1"
- ensure
- ENV['REMOTE_ADDR'] = old_value
+ it "returns ENV['REMOTE_ADDR']" do
+ old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1"
+ begin
+ @cgi.remote_addr.should == "127.0.0.1"
+ ensure
+ ENV['REMOTE_ADDR'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
index cf77e0031b..2dfe59ca38 100644
--- a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#remote_host" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_host" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_HOST']" do
- old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host"
- begin
- @cgi.remote_host.should == "test.host"
- ensure
- ENV['REMOTE_HOST'] = old_value
+ it "returns ENV['REMOTE_HOST']" do
+ old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host"
+ begin
+ @cgi.remote_host.should == "test.host"
+ ensure
+ ENV['REMOTE_HOST'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
index 5b51d6b8ee..bb05fc7942 100644
--- a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#remote_ident" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_ident" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_IDENT']" do
- old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for"
- begin
- @cgi.remote_ident.should == "no-idea-what-this-is-for"
- ensure
- ENV['REMOTE_IDENT'] = old_value
+ it "returns ENV['REMOTE_IDENT']" do
+ old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for"
+ begin
+ @cgi.remote_ident.should == "no-idea-what-this-is-for"
+ ensure
+ ENV['REMOTE_IDENT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
index 1a93bb6561..29856302ab 100644
--- a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#remote_user" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_user" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_USER']" do
- old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username"
- begin
- @cgi.remote_user.should == "username"
- ensure
- ENV['REMOTE_USER'] = old_value
+ it "returns ENV['REMOTE_USER']" do
+ old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username"
+ begin
+ @cgi.remote_user.should == "username"
+ ensure
+ ENV['REMOTE_USER'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/request_method_spec.rb b/spec/ruby/library/cgi/queryextension/request_method_spec.rb
index eabdd6998b..7331b134d2 100644
--- a/spec/ruby/library/cgi/queryextension/request_method_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/request_method_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#request_method" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#request_method" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REQUEST_METHOD']" do
- old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET"
- begin
- @cgi.request_method.should == "GET"
- ensure
- ENV['REQUEST_METHOD'] = old_value
+ it "returns ENV['REQUEST_METHOD']" do
+ old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET"
+ begin
+ @cgi.request_method.should == "GET"
+ ensure
+ ENV['REQUEST_METHOD'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/script_name_spec.rb b/spec/ruby/library/cgi/queryextension/script_name_spec.rb
index 341b7b6fea..4b359a545f 100644
--- a/spec/ruby/library/cgi/queryextension/script_name_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/script_name_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#script_name" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#script_name" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SCRIPT_NAME']" do
- old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb"
- begin
- @cgi.script_name.should == "/path/to/script.rb"
- ensure
- ENV['SCRIPT_NAME'] = old_value
+ it "returns ENV['SCRIPT_NAME']" do
+ old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb"
+ begin
+ @cgi.script_name.should == "/path/to/script.rb"
+ ensure
+ ENV['SCRIPT_NAME'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_name_spec.rb b/spec/ruby/library/cgi/queryextension/server_name_spec.rb
index b12aaf8c5c..c1f7fb4c54 100644
--- a/spec/ruby/library/cgi/queryextension/server_name_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_name_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#server_name" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_name" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_NAME']" do
- old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost"
- begin
- @cgi.server_name.should == "localhost"
- ensure
- ENV['SERVER_NAME'] = old_value
+ it "returns ENV['SERVER_NAME']" do
+ old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost"
+ begin
+ @cgi.server_name.should == "localhost"
+ ensure
+ ENV['SERVER_NAME'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_port_spec.rb b/spec/ruby/library/cgi/queryextension/server_port_spec.rb
index 0e688a99bf..60c03ea639 100644
--- a/spec/ruby/library/cgi/queryextension/server_port_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_port_spec.rb
@@ -1,26 +1,29 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#server_port" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_port" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_PORT'] as Integer" do
- old_value = ENV['SERVER_PORT']
- begin
- ENV['SERVER_PORT'] = nil
- @cgi.server_port.should be_nil
+ it "returns ENV['SERVER_PORT'] as Integer" do
+ old_value = ENV['SERVER_PORT']
+ begin
+ ENV['SERVER_PORT'] = nil
+ @cgi.server_port.should be_nil
- ENV['SERVER_PORT'] = "3000"
- @cgi.server_port.should eql(3000)
- ensure
- ENV['SERVER_PORT'] = old_value
+ ENV['SERVER_PORT'] = "3000"
+ @cgi.server_port.should eql(3000)
+ ensure
+ ENV['SERVER_PORT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
index f9dcf3c5b8..fdbcc2108f 100644
--- a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#server_protocol" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_protocol" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_PROTOCOL']" do
- old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1"
- begin
- @cgi.server_protocol.should == "HTTP/1.1"
- ensure
- ENV['SERVER_PROTOCOL'] = old_value
+ it "returns ENV['SERVER_PROTOCOL']" do
+ old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1"
+ begin
+ @cgi.server_protocol.should == "HTTP/1.1"
+ ensure
+ ENV['SERVER_PROTOCOL'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_software_spec.rb b/spec/ruby/library/cgi/queryextension/server_software_spec.rb
index df349cdf2e..c5811a2268 100644
--- a/spec/ruby/library/cgi/queryextension/server_software_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_software_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#server_software" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_software" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_SOFTWARE']" do
- old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0"
- begin
- @cgi.server_software.should == "Server/1.0.0"
- ensure
- ENV['SERVER_SOFTWARE'] = old_value
+ it "returns ENV['SERVER_SOFTWARE']" do
+ old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0"
+ begin
+ @cgi.server_software.should == "Server/1.0.0"
+ ensure
+ ENV['SERVER_SOFTWARE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
index ec5ef187dd..3240352ef6 100644
--- a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
@@ -1,22 +1,25 @@
require_relative '../../../spec_helper'
-require 'cgi'
-describe "CGI::QueryExtension#user_agent" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#user_agent" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_USER_AGENT']" do
- old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
- begin
- @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
- ensure
- ENV['HTTP_USER_AGENT'] = old_value
+ it "returns ENV['HTTP_USER_AGENT']" do
+ old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
+ begin
+ @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
+ ensure
+ ENV['HTTP_USER_AGENT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/rfc1123_date_spec.rb b/spec/ruby/library/cgi/rfc1123_date_spec.rb
index 6904eeabaa..636185f22c 100644
--- a/spec/ruby/library/cgi/rfc1123_date_spec.rb
+++ b/spec/ruby/library/cgi/rfc1123_date_spec.rb
@@ -1,10 +1,13 @@
require_relative '../../spec_helper'
-require 'cgi'
-describe "CGI.rfc1123_date when passed Time" do
- it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do
- input = Time.at(1196524602)
- expected = 'Sat, 01 Dec 2007 15:56:42 GMT'
- CGI.rfc1123_date(input).should == expected
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI.rfc1123_date when passed Time" do
+ it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do
+ input = Time.at(1196524602)
+ expected = 'Sat, 01 Dec 2007 15:56:42 GMT'
+ CGI.rfc1123_date(input).should == expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/unescapeElement_spec.rb b/spec/ruby/library/cgi/unescapeElement_spec.rb
index ae4d50b076..db83f0d2fb 100644
--- a/spec/ruby/library/cgi/unescapeElement_spec.rb
+++ b/spec/ruby/library/cgi/unescapeElement_spec.rb
@@ -1,5 +1,11 @@
require_relative '../../spec_helper'
-require 'cgi'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.unescapeElement when passed String, elements, ..." do
it "unescapes only the tags of the passed elements in the passed String" do
diff --git a/spec/ruby/library/cgi/unescapeHTML_spec.rb b/spec/ruby/library/cgi/unescapeHTML_spec.rb
index 84b30c6aa6..e43dcc83e5 100644
--- a/spec/ruby/library/cgi/unescapeHTML_spec.rb
+++ b/spec/ruby/library/cgi/unescapeHTML_spec.rb
@@ -1,5 +1,9 @@
require_relative '../../spec_helper'
-require 'cgi'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.unescapeHTML" do
it "unescapes '&amp; &lt; &gt; &quot;' to '& < > \"'" do
diff --git a/spec/ruby/library/cgi/unescapeURIComponent_spec.rb b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb
new file mode 100644
index 0000000000..f80eb1626b
--- /dev/null
+++ b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb
@@ -0,0 +1,128 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
+
+describe "CGI.unescapeURIComponent" do
+ it "decodes any percent-encoded octets to their corresponding bytes according to RFC 3986" do
+ string = (0x00..0xff).map { |i| "%%%02x" % i }.join
+ expected = (0x00..0xff).map { |i| i.chr }.join.force_encoding(Encoding::UTF_8)
+ CGI.unescapeURIComponent(string).should == expected
+ end
+
+ it "disregards case of characters in a percent-encoding triplet" do
+ CGI.unescapeURIComponent("%CE%B2abc").should == "βabc"
+ CGI.unescapeURIComponent("%ce%b2ABC").should == "βABC"
+ end
+
+ it "leaves any non-percent-encoded characters as-is" do
+ string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ:/?#[]@!$&'()*+,;=\t\x0D\xFFβᛉ▒90%"
+ decoded = CGI.unescapeURIComponent(string)
+ decoded.should == string
+ string.should_not.equal?(decoded)
+ end
+
+ it "leaves sequences which can't be a percent-encoded octet as-is" do
+ string = "%AZ%B"
+ decoded = CGI.unescapeURIComponent(string)
+ decoded.should == string
+ string.should_not.equal?(decoded)
+ end
+
+ it "creates a String with the specified target Encoding" do
+ string = CGI.unescapeURIComponent("%D2%3C%3CABC", Encoding::ISO_8859_1)
+ string.encoding.should == Encoding::ISO_8859_1
+ string.should == "Ã’<<ABC".encode("ISO-8859-1")
+ end
+
+ it "accepts a string name of an Encoding" do
+ CGI.unescapeURIComponent("%D2%3C%3CABC", "ISO-8859-1").should == "Ã’<<ABC".encode("ISO-8859-1")
+ end
+
+ it "raises ArgumentError if specified encoding is unknown" do
+ -> { CGI.unescapeURIComponent("ABC", "ISO-JOKE-1") }.should raise_error(ArgumentError, "unknown encoding name - ISO-JOKE-1")
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "uses CGI.accept_charset as the default target encoding" do
+ original_charset = CGI.accept_charset
+ CGI.accept_charset = "ISO-8859-1"
+ decoded = CGI.unescapeURIComponent("%D2%3C%3CABC")
+ decoded.should == "Ã’<<ABC".encode("ISO-8859-1")
+ decoded.encoding.should == Encoding::ISO_8859_1
+ ensure
+ CGI.accept_charset = original_charset
+ end
+
+ it "has CGI.accept_charset as UTF-8 by default" do
+ decoded = CGI.unescapeURIComponent("%CE%B2ABC")
+ decoded.should == "βABC"
+ decoded.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ ruby_version_is "4.0" do
+ # "cgi/escape" does not have methods to access @@accept_charset.
+ # Full "cgi" gem provides them, allowing to possibly change it.
+ it "uses CGI's @@accept_charset as the default target encoding" do
+ original_charset = CGI.class_variable_get(:@@accept_charset)
+ CGI.class_variable_set(:@@accept_charset, "ISO-8859-1")
+ decoded = CGI.unescapeURIComponent("%D2%3C%3CABC")
+ decoded.should == "Ã’<<ABC".encode("ISO-8859-1")
+ decoded.encoding.should == Encoding::ISO_8859_1
+ ensure
+ CGI.class_variable_set(:@@accept_charset, original_charset)
+ end
+
+ it "has CGI's @@accept_charset as UTF-8 by default" do
+ decoded = CGI.unescapeURIComponent("%CE%B2ABC")
+ decoded.should == "βABC"
+ decoded.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ context "when source string specifies octets invalid in target encoding" do
+ it "uses source string's encoding" do
+ string = "%A2%A6%A3".encode(Encoding::SHIFT_JIS)
+ decoded = CGI.unescapeURIComponent(string, Encoding::US_ASCII)
+ decoded.encoding.should == Encoding::SHIFT_JIS
+ decoded.should == "「ヲ」".encode(Encoding::SHIFT_JIS)
+ decoded.valid_encoding?.should be_true
+ end
+
+ it "uses source string's encoding even if it's also invalid" do
+ string = "%FF".encode(Encoding::US_ASCII)
+ decoded = CGI.unescapeURIComponent(string, Encoding::SHIFT_JIS)
+ decoded.encoding.should == Encoding::US_ASCII
+ decoded.should == "\xFF".dup.force_encoding(Encoding::US_ASCII)
+ decoded.valid_encoding?.should be_false
+ end
+ end
+
+ it "decodes an empty string as an empty string with target encoding" do
+ string = "".encode(Encoding::BINARY)
+ decoded = CGI.unescapeURIComponent(string, "UTF-8")
+ decoded.should == ""
+ decoded.encoding.should == Encoding::UTF_8
+ string.should_not.equal?(decoded)
+ end
+
+ it "raises a TypeError with nil" do
+ -> {
+ CGI.unescapeURIComponent(nil)
+ }.should raise_error(TypeError, "no implicit conversion of nil into String")
+ end
+
+ it "uses implicit type conversion to String" do
+ object = Object.new
+ def object.to_str
+ "a%20b"
+ end
+
+ CGI.unescapeURIComponent(object).should == "a b"
+ end
+end
diff --git a/spec/ruby/library/cgi/unescape_spec.rb b/spec/ruby/library/cgi/unescape_spec.rb
index c593e24b4a..aa731b9367 100644
--- a/spec/ruby/library/cgi/unescape_spec.rb
+++ b/spec/ruby/library/cgi/unescape_spec.rb
@@ -1,6 +1,12 @@
# -*- encoding: utf-8 -*-
require_relative '../../spec_helper'
-require 'cgi'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.unescape" do
it "url-decodes the passed argument" do
diff --git a/spec/ruby/library/coverage/result_spec.rb b/spec/ruby/library/coverage/result_spec.rb
index bc999a5369..0101eb6a64 100644
--- a/spec/ruby/library/coverage/result_spec.rb
+++ b/spec/ruby/library/coverage/result_spec.rb
@@ -34,39 +34,37 @@ describe 'Coverage.result' do
}
end
- ruby_version_is "3.2" do
- it 'returns results for each mode separately when enabled :all modes' do
- Coverage.start(:all)
- require @class_file.chomp('.rb')
- result = Coverage.result
-
- result.should == {
- @class_file => {
+ it 'returns results for each mode separately when enabled :all modes' do
+ Coverage.start(:all)
+ require @class_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @class_file => {
+ lines: [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ],
+ branches: {},
+ methods: {
+ [SomeClass, :some_method, 6, 2, 11, 5] => 0
+ }
+ }
+ }
+ end
+
+ it 'returns results for each mode separately when enabled any mode explicitly' do
+ Coverage.start(lines: true)
+ require @class_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @class_file =>
+ {
lines: [
nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
- ],
- branches: {},
- methods: {
- [SomeClass, :some_method, 6, 2, 11, 5] => 0
- }
+ ]
}
- }
- end
-
- it 'returns results for each mode separately when enabled any mode explicitly' do
- Coverage.start(lines: true)
- require @class_file.chomp('.rb')
- result = Coverage.result
-
- result.should == {
- @class_file =>
- {
- lines: [
- nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
- ]
- }
- }
- end
+ }
end
it 'no requires/loads should give empty hash' do
@@ -113,48 +111,32 @@ describe 'Coverage.result' do
Coverage.result.should_not include(@config_file)
end
- ruby_version_is '3.1'...'3.2' do
- it 'returns the correct results when eval is used' do
- Coverage.start
- require @eval_code_file.chomp('.rb')
- result = Coverage.result
-
- result.should == {
- @eval_code_file => [
- 1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1
- ]
- }
- end
- end
+ it 'returns the correct results when eval coverage is enabled' do
+ Coverage.supported?(:eval).should == true
- ruby_version_is '3.2' do
- it 'returns the correct results when eval coverage is enabled' do
- Coverage.supported?(:eval).should == true
-
- Coverage.start(lines: true, eval: true)
- require @eval_code_file.chomp('.rb')
- result = Coverage.result
+ Coverage.start(lines: true, eval: true)
+ require @eval_code_file.chomp('.rb')
+ result = Coverage.result
- result.should == {
- @eval_code_file => {
- lines: [1, nil, 1, nil, 1, 1, nil, nil, nil, nil, 1]
- }
+ result.should == {
+ @eval_code_file => {
+ lines: [1, nil, 1, nil, 1, 1, nil, nil, nil, nil, 1]
}
- end
+ }
+ end
- it 'returns the correct results when eval coverage is disabled' do
- Coverage.supported?(:eval).should == true
+ it 'returns the correct results when eval coverage is disabled' do
+ Coverage.supported?(:eval).should == true
- Coverage.start(lines: true, eval: false)
- require @eval_code_file.chomp('.rb')
- result = Coverage.result
+ Coverage.start(lines: true, eval: false)
+ require @eval_code_file.chomp('.rb')
+ result = Coverage.result
- result.should == {
- @eval_code_file => {
- lines: [1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1]
- }
+ result.should == {
+ @eval_code_file => {
+ lines: [1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1]
}
- end
+ }
end
it "disables coverage measurement when stop option is not specified" do
diff --git a/spec/ruby/library/coverage/start_spec.rb b/spec/ruby/library/coverage/start_spec.rb
index 757837a462..c921b85401 100644
--- a/spec/ruby/library/coverage/start_spec.rb
+++ b/spec/ruby/library/coverage/start_spec.rb
@@ -27,63 +27,61 @@ describe 'Coverage.start' do
}.should raise_error(RuntimeError, 'coverage measurement is already setup')
end
- ruby_version_is '3.2' do
- it "accepts :all optional argument" do
- Coverage.start(:all)
- Coverage.should.running?
- end
-
- it "accepts lines: optional keyword argument" do
- Coverage.start(lines: true)
- Coverage.should.running?
- end
-
- it "accepts branches: optional keyword argument" do
- Coverage.start(branches: true)
- Coverage.should.running?
- end
-
- it "accepts methods: optional keyword argument" do
- Coverage.start(methods: true)
- Coverage.should.running?
- end
-
- it "accepts eval: optional keyword argument" do
- Coverage.start(eval: true)
- Coverage.should.running?
- end
-
- it "accepts oneshot_lines: optional keyword argument" do
- Coverage.start(oneshot_lines: true)
- Coverage.should.running?
- end
-
- it "ignores unknown keyword arguments" do
- Coverage.start(foo: true)
- Coverage.should.running?
- end
-
- it "expects a Hash if not passed :all" do
- -> {
- Coverage.start(42)
- }.should raise_error(TypeError, "no implicit conversion of Integer into Hash")
- end
-
- it "does not accept both lines: and oneshot_lines: keyword arguments" do
- -> {
- Coverage.start(lines: true, oneshot_lines: true)
- }.should raise_error(RuntimeError, "cannot enable lines and oneshot_lines simultaneously")
- end
-
- it "enables the coverage measurement if passed options with `false` value" do
- Coverage.start(lines: false, branches: false, methods: false, eval: false, oneshot_lines: false)
- Coverage.should.running?
- end
-
- it "measures coverage within eval" do
- Coverage.start(lines: true, eval: true)
- eval("Object.new\n"*3, binding, "test.rb", 1)
- Coverage.result["test.rb"].should == {lines: [1, 1, 1]}
- end
+ it "accepts :all optional argument" do
+ Coverage.start(:all)
+ Coverage.should.running?
+ end
+
+ it "accepts lines: optional keyword argument" do
+ Coverage.start(lines: true)
+ Coverage.should.running?
+ end
+
+ it "accepts branches: optional keyword argument" do
+ Coverage.start(branches: true)
+ Coverage.should.running?
+ end
+
+ it "accepts methods: optional keyword argument" do
+ Coverage.start(methods: true)
+ Coverage.should.running?
+ end
+
+ it "accepts eval: optional keyword argument" do
+ Coverage.start(eval: true)
+ Coverage.should.running?
+ end
+
+ it "accepts oneshot_lines: optional keyword argument" do
+ Coverage.start(oneshot_lines: true)
+ Coverage.should.running?
+ end
+
+ it "ignores unknown keyword arguments" do
+ Coverage.start(foo: true)
+ Coverage.should.running?
+ end
+
+ it "expects a Hash if not passed :all" do
+ -> {
+ Coverage.start(42)
+ }.should raise_error(TypeError, "no implicit conversion of Integer into Hash")
+ end
+
+ it "does not accept both lines: and oneshot_lines: keyword arguments" do
+ -> {
+ Coverage.start(lines: true, oneshot_lines: true)
+ }.should raise_error(RuntimeError, "cannot enable lines and oneshot_lines simultaneously")
+ end
+
+ it "enables the coverage measurement if passed options with `false` value" do
+ Coverage.start(lines: false, branches: false, methods: false, eval: false, oneshot_lines: false)
+ Coverage.should.running?
+ end
+
+ it "measures coverage within eval" do
+ Coverage.start(lines: true, eval: true)
+ eval("Object.new\n"*3, binding, "test.rb", 1)
+ Coverage.result["test.rb"].should == {lines: [1, 1, 1]}
end
end
diff --git a/spec/ruby/library/coverage/supported_spec.rb b/spec/ruby/library/coverage/supported_spec.rb
index 78b3784ee0..9226548c1f 100644
--- a/spec/ruby/library/coverage/supported_spec.rb
+++ b/spec/ruby/library/coverage/supported_spec.rb
@@ -2,31 +2,29 @@ require_relative '../../spec_helper'
require 'coverage'
describe "Coverage.supported?" do
- ruby_version_is "3.2" do
- it "returns true or false if coverage measurement is supported for the given mode" do
- [true, false].should.include?(Coverage.supported?(:lines))
- [true, false].should.include?(Coverage.supported?(:branches))
- [true, false].should.include?(Coverage.supported?(:methods))
- [true, false].should.include?(Coverage.supported?(:eval))
- end
+ it "returns true or false if coverage measurement is supported for the given mode" do
+ [true, false].should.include?(Coverage.supported?(:lines))
+ [true, false].should.include?(Coverage.supported?(:branches))
+ [true, false].should.include?(Coverage.supported?(:methods))
+ [true, false].should.include?(Coverage.supported?(:eval))
+ end
- it "returns false for not existing modes" do
- Coverage.supported?(:foo).should == false
- Coverage.supported?(:bar).should == false
- end
+ it "returns false for not existing modes" do
+ Coverage.supported?(:foo).should == false
+ Coverage.supported?(:bar).should == false
+ end
- it "raise TypeError if argument is not Symbol" do
- -> {
- Coverage.supported?("lines")
- }.should raise_error(TypeError, "wrong argument type String (expected Symbol)")
+ it "raise TypeError if argument is not Symbol" do
+ -> {
+ Coverage.supported?("lines")
+ }.should raise_error(TypeError, "wrong argument type String (expected Symbol)")
- -> {
- Coverage.supported?([])
- }.should raise_error(TypeError, "wrong argument type Array (expected Symbol)")
+ -> {
+ Coverage.supported?([])
+ }.should raise_error(TypeError, "wrong argument type Array (expected Symbol)")
- -> {
- Coverage.supported?(1)
- }.should raise_error(TypeError, "wrong argument type Integer (expected Symbol)")
- end
+ -> {
+ Coverage.supported?(1)
+ }.should raise_error(TypeError, "wrong argument type Integer (expected Symbol)")
end
end
diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb
index 92579e35c7..b9dd6b8816 100644
--- a/spec/ruby/library/date/deconstruct_keys_spec.rb
+++ b/spec/ruby/library/date/deconstruct_keys_spec.rb
@@ -2,43 +2,41 @@ require_relative '../../spec_helper'
require 'date'
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
-version_is date_version, "3.3" do #ruby_version_is "3.2" do
- describe "Date#deconstruct_keys" do
- it "returns whole hash for nil as an argument" do
- d = Date.new(2022, 10, 5)
- d.deconstruct_keys(nil).should == { year: 2022, month: 10, day: 5, yday: 278, wday: 3 }
- end
-
- it "returns only specified keys" do
- d = Date.new(2022, 10, 5)
- d.deconstruct_keys([:year, :month]).should == { year: 2022, month: 10 }
- end
-
- it "requires one argument" do
- -> {
- Date.new(2022, 10, 5).deconstruct_keys
- }.should raise_error(ArgumentError)
- end
-
- it "it raises error when argument is neither nil nor array" do
- d = Date.new(2022, 10, 5)
-
- -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
- -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
- -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
- -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
- end
-
- it "returns {} when passed []" do
- Date.new(2022, 10, 5).deconstruct_keys([]).should == {}
- end
-
- it "ignores non-Symbol keys" do
- Date.new(2022, 10, 5).deconstruct_keys(['year', []]).should == {}
- end
-
- it "ignores not existing Symbol keys" do
- Date.new(2022, 10, 5).deconstruct_keys([:year, :a]).should == { year: 2022 }
- end
+describe "Date#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = Date.new(2022, 10, 5)
+ d.deconstruct_keys(nil).should == { year: 2022, month: 10, day: 5, yday: 278, wday: 3 }
+ end
+
+ it "returns only specified keys" do
+ d = Date.new(2022, 10, 5)
+ d.deconstruct_keys([:year, :month]).should == { year: 2022, month: 10 }
+ end
+
+ it "requires one argument" do
+ -> {
+ Date.new(2022, 10, 5).deconstruct_keys
+ }.should raise_error(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = Date.new(2022, 10, 5)
+
+ -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ Date.new(2022, 10, 5).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ Date.new(2022, 10, 5).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys" do
+ Date.new(2022, 10, 5).deconstruct_keys([:year, :a]).should == { year: 2022 }
end
end
diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
index 77ceaa51c4..154c024a23 100644
--- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb
+++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
@@ -2,45 +2,43 @@ require_relative '../../spec_helper'
require 'date'
date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
-version_is date_version, "3.3" do #ruby_version_is "3.2" do
- describe "DateTime#deconstruct_keys" do
- it "returns whole hash for nil as an argument" do
- d = DateTime.new(2022, 10, 5, 13, 30)
- res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
- min: 30, sec: 0, sec_fraction: (0/1), zone: "+00:00" }
- d.deconstruct_keys(nil).should == res
- end
-
- it "returns only specified keys" do
- d = DateTime.new(2022, 10, 5, 13, 39)
- d.deconstruct_keys([:zone, :hour]).should == { zone: "+00:00", hour: 13 }
- end
-
- it "requires one argument" do
- -> {
- DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys
- }.should raise_error(ArgumentError)
- end
-
- it "it raises error when argument is neither nil nor array" do
- d = DateTime.new(2022, 10, 5, 13, 30)
-
- -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
- -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
- -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
- -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
- end
-
- it "returns {} when passed []" do
- DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
- end
-
- it "ignores non-Symbol keys" do
- DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
- end
-
- it "ignores not existing Symbol keys" do
- DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([:year, :a]).should == { year: 2022 }
- end
+describe "DateTime#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = DateTime.new(2022, 10, 5, 13, 30)
+ res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
+ min: 30, sec: 0, sec_fraction: (0/1), zone: "+00:00" }
+ d.deconstruct_keys(nil).should == res
+ end
+
+ it "returns only specified keys" do
+ d = DateTime.new(2022, 10, 5, 13, 39)
+ d.deconstruct_keys([:zone, :hour]).should == { zone: "+00:00", hour: 13 }
+ end
+
+ it "requires one argument" do
+ -> {
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys
+ }.should raise_error(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = DateTime.new(2022, 10, 5, 13, 30)
+
+ -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([:year, :a]).should == { year: 2022 }
end
end
diff --git a/spec/ruby/library/datetime/time/to_datetime_spec.rb b/spec/ruby/library/datetime/time/to_datetime_spec.rb
index 1125dbe851..5589725238 100644
--- a/spec/ruby/library/datetime/time/to_datetime_spec.rb
+++ b/spec/ruby/library/datetime/time/to_datetime_spec.rb
@@ -15,17 +15,15 @@ describe "Time#to_datetime" do
datetime.sec.should == 59
end
- version_is date_version, '3.2.3' do #ruby_version_is '3.2' do
- it "returns a DateTime representing the same instant before Gregorian" do
- time = Time.utc(1582, 10, 14, 23, 58, 59)
- datetime = time.to_datetime
- datetime.year.should == 1582
- datetime.month.should == 10
- datetime.day.should == 4
- datetime.hour.should == 23
- datetime.min.should == 58
- datetime.sec.should == 59
- end
+ it "returns a DateTime representing the same instant before Gregorian" do
+ time = Time.utc(1582, 10, 14, 23, 58, 59)
+ datetime = time.to_datetime
+ datetime.year.should == 1582
+ datetime.month.should == 10
+ datetime.day.should == 4
+ datetime.hour.should == 23
+ datetime.min.should == 58
+ datetime.sec.should == 59
end
it "roundtrips" do
diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb
index 09e6192e7f..58bb363653 100644
--- a/spec/ruby/library/datetime/to_time_spec.rb
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -19,17 +19,15 @@ describe "DateTime#to_time" do
time.sec.should == 59
end
- version_is date_version, '3.2.3' do #ruby_version_is "3.2" do
- it "returns a Time representing the same instant before Gregorian" do
- datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
- time = datetime.to_time.utc
- time.year.should == 1582
- time.month.should == 10
- time.day.should == 14
- time.hour.should == 23
- time.min.should == 58
- time.sec.should == 59
- end
+ it "returns a Time representing the same instant before Gregorian" do
+ datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
+ time = datetime.to_time.utc
+ time.year.should == 1582
+ time.month.should == 10
+ time.day.should == 14
+ time.hour.should == 23
+ time.min.should == 58
+ time.sec.should == 59
end
it "preserves the same time regardless of local time or zone" do
diff --git a/spec/ruby/library/digest/md5/shared/constants.rb b/spec/ruby/library/digest/md5/shared/constants.rb
index e807b96f9f..664dd18e9c 100644
--- a/spec/ruby/library/digest/md5/shared/constants.rb
+++ b/spec/ruby/library/digest/md5/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/md5'
module MD5Constants
diff --git a/spec/ruby/library/digest/sha1/shared/constants.rb b/spec/ruby/library/digest/sha1/shared/constants.rb
index 169438747f..d77c05a968 100644
--- a/spec/ruby/library/digest/sha1/shared/constants.rb
+++ b/spec/ruby/library/digest/sha1/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha1'
diff --git a/spec/ruby/library/digest/sha256/shared/constants.rb b/spec/ruby/library/digest/sha256/shared/constants.rb
index 351679f344..afe8f11426 100644
--- a/spec/ruby/library/digest/sha256/shared/constants.rb
+++ b/spec/ruby/library/digest/sha256/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
diff --git a/spec/ruby/library/digest/sha384/shared/constants.rb b/spec/ruby/library/digest/sha384/shared/constants.rb
index 2050f03f2b..a78d571d26 100644
--- a/spec/ruby/library/digest/sha384/shared/constants.rb
+++ b/spec/ruby/library/digest/sha384/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
diff --git a/spec/ruby/library/digest/sha512/shared/constants.rb b/spec/ruby/library/digest/sha512/shared/constants.rb
index 2765a1ec16..91787381ee 100644
--- a/spec/ruby/library/digest/sha512/shared/constants.rb
+++ b/spec/ruby/library/digest/sha512/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb
index ec1be5c234..f8192bff99 100644
--- a/spec/ruby/library/erb/new_spec.rb
+++ b/spec/ruby/library/erb/new_spec.rb
@@ -139,17 +139,19 @@ END
->{ ERB.new("<%= list %>").result }.should raise_error(NameError)
end
- describe "warning about arguments" do
- it "warns when passed safe_level and later arguments" do
- -> {
- ERB.new(@eruby_str, nil, '%')
- }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
- end
-
- it "does not warn when passed arguments as keyword argument" do
- -> {
- ERB.new(@eruby_str, trim_mode: '%')
- }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
+ version_is ERB.const_get(:VERSION, false), ""..."6.0.0" do
+ describe "warning about arguments" do
+ it "warns when passed safe_level and later arguments" do
+ -> {
+ ERB.new(@eruby_str, nil, '%')
+ }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
+ end
+
+ it "does not warn when passed arguments as keyword argument" do
+ -> {
+ ERB.new(@eruby_str, trim_mode: '%')
+ }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
+ end
end
end
end
diff --git a/spec/ruby/library/io-wait/wait_readable_spec.rb b/spec/ruby/library/io-wait/wait_readable_spec.rb
index df25fdb931..d7473f029f 100644
--- a/spec/ruby/library/io-wait/wait_readable_spec.rb
+++ b/spec/ruby/library/io-wait/wait_readable_spec.rb
@@ -1,9 +1,5 @@
require_relative '../../spec_helper'
-ruby_version_is ''...'3.2' do
- require 'io/wait'
-end
-
describe "IO#wait_readable" do
before :each do
@io = File.new(__FILE__ )
diff --git a/spec/ruby/library/io-wait/wait_spec.rb b/spec/ruby/library/io-wait/wait_spec.rb
index 6ab41e9f08..6a3890a401 100644
--- a/spec/ruby/library/io-wait/wait_spec.rb
+++ b/spec/ruby/library/io-wait/wait_spec.rb
@@ -1,10 +1,6 @@
require_relative '../../spec_helper'
require_relative '../../fixtures/io'
-ruby_version_is ''...'3.2' do
- require 'io/wait'
-end
-
describe "IO#wait" do
before :each do
@io = File.new(__FILE__ )
@@ -25,26 +21,13 @@ describe "IO#wait" do
end
context "[events, timeout] passed" do
- ruby_version_is ""..."3.2" do
- it "returns self when the READABLE event is ready during the timeout" do
- @w.write('data to read')
- @r.wait(IO::READABLE, 2).should.equal?(@r)
- end
-
- it "returns self when the WRITABLE event is ready during the timeout" do
- @w.wait(IO::WRITABLE, 0).should.equal?(@w)
- end
+ it "returns events mask when the READABLE event is ready during the timeout" do
+ @w.write('data to read')
+ @r.wait(IO::READABLE, 2).should == IO::READABLE
end
- ruby_version_is "3.2" do
- it "returns events mask when the READABLE event is ready during the timeout" do
- @w.write('data to read')
- @r.wait(IO::READABLE, 2).should == IO::READABLE
- end
-
- it "returns events mask when the WRITABLE event is ready during the timeout" do
- @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE
- end
+ it "returns events mask when the WRITABLE event is ready during the timeout" do
+ @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE
end
it "waits for the READABLE event to be ready" do
@@ -76,11 +59,9 @@ describe "IO#wait" do
-> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream")
end
- ruby_version_is "3.2" do
- it "raises ArgumentError when events is not positive" do
- -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!")
- -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!")
- end
+ it "raises ArgumentError when events is not positive" do
+ -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!")
+ -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!")
end
it "changes thread status to 'sleep' when waits for READABLE event" do
@@ -159,31 +140,23 @@ describe "IO#wait" do
@io.wait(0, :r, :w, :rw).should == @io
end
- # It works at least since 2.7 but by some reason may fail on 3.1
- ruby_version_is "3.2" do
- it "accepts timeout and mode in any order" do
- @io.wait(0, :r).should == @io
- @io.wait(:r, 0).should == @io
- @io.wait(:r, 0, :w).should == @io
- end
+ it "accepts timeout and mode in any order" do
+ @io.wait(0, :r).should == @io
+ @io.wait(:r, 0).should == @io
+ @io.wait(:r, 0, :w).should == @io
end
it "raises ArgumentError when passed wrong Symbol value as mode argument" do
-> { @io.wait(0, :wrong) }.should raise_error(ArgumentError, "unsupported mode: wrong")
end
- # It works since 3.0 but by some reason may fail on 3.1
- ruby_version_is "3.2" do
- it "raises ArgumentError when several Integer arguments passed" do
- -> { @w.wait(0, 10, :r) }.should raise_error(ArgumentError, "timeout given more than once")
- end
+ it "raises ArgumentError when several Integer arguments passed" do
+ -> { @w.wait(0, 10, :r) }.should raise_error(ArgumentError, "timeout given more than once")
end
- ruby_version_is "3.2" do
- it "raises IOError when io is closed (closed stream (IOError))" do
- @io.close
- -> { @io.wait(0, :r) }.should raise_error(IOError, "closed stream")
- end
+ it "raises IOError when io is closed (closed stream (IOError))" do
+ @io.close
+ -> { @io.wait(0, :r) }.should raise_error(IOError, "closed stream")
end
end
end
diff --git a/spec/ruby/library/io-wait/wait_writable_spec.rb b/spec/ruby/library/io-wait/wait_writable_spec.rb
index 8639dd717b..2017817caa 100644
--- a/spec/ruby/library/io-wait/wait_writable_spec.rb
+++ b/spec/ruby/library/io-wait/wait_writable_spec.rb
@@ -1,10 +1,6 @@
require_relative '../../spec_helper'
require_relative '../../fixtures/io'
-ruby_version_is ''...'3.2' do
- require 'io/wait'
-end
-
describe "IO#wait_writable" do
it "waits for the IO to become writable with no timeout" do
STDOUT.wait_writable.should == STDOUT
diff --git a/spec/ruby/library/net-http/HTTPServerException_spec.rb b/spec/ruby/library/net-http/HTTPServerException_spec.rb
index 5e0a833fee..020d3cce85 100644
--- a/spec/ruby/library/net-http/HTTPServerException_spec.rb
+++ b/spec/ruby/library/net-http/HTTPServerException_spec.rb
@@ -3,10 +3,10 @@ require 'net/http'
describe "Net::HTTPServerException" do
it "is a subclass of Net::ProtoServerError and is warned as deprecated" do
- -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
+ -> { eval("Net::HTTPServerException").should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
end
it "includes the Net::HTTPExceptions module and is warned as deprecated" do
- -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
+ -> { eval("Net::HTTPServerException").should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
end
end
diff --git a/spec/ruby/library/net-http/http/post_spec.rb b/spec/ruby/library/net-http/http/post_spec.rb
index ac020bd6be..b8b8d16ad1 100644
--- a/spec/ruby/library/net-http/http/post_spec.rb
+++ b/spec/ruby/library/net-http/http/post_spec.rb
@@ -25,9 +25,11 @@ describe "Net::HTTP.post" do
response.should be_kind_of(Net::HTTPResponse)
end
- it "sends Content-Type: application/x-www-form-urlencoded by default" do
- response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
- response.body.should include({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}"))
+ ruby_version_is ""..."4.0" do
+ it "sends Content-Type: application/x-www-form-urlencoded by default" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
+ response.body.should include({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}"))
+ end
end
it "does not support HTTP Basic Auth" do
diff --git a/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb
index 7de03d7da0..a09f9d5bec 100644
--- a/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb
+++ b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb
@@ -31,18 +31,20 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do
end
describe "when a request body is set" do
- it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.body = "Some Content"
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
- str.should =~ %r[Content-Length: 12\r\n]
- str[-16..-1].should == "\r\n\r\nSome Content"
+ ruby_version_is ""..."4.0" do
+ it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.body = "Some Content"
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
+ str.should =~ %r[Content-Length: 12\r\n]
+ str[-16..-1].should == "\r\n\r\nSome Content"
+ end
end
it "correctly sets the 'Content-Length' header and includes the body" do
@@ -62,19 +64,21 @@ describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do
end
describe "when a body stream is set" do
- it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
- "Content-Length" => "10")
- request.body_stream = StringIO.new("a" * 20)
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
- str.should =~ %r[Content-Length: 10\r\n]
- str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
+ ruby_version_is ""..."4.0" do
+ it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
+ "Content-Length" => "10")
+ request.body_stream = StringIO.new("a" * 20)
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
+ str.should =~ %r[Content-Length: 10\r\n]
+ str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
+ end
end
it "sends the whole stream, regardless of the 'Content-Length' header" do
diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
index 612430e067..0f1e2aa8b9 100644
--- a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
+++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
@@ -2,6 +2,20 @@ require_relative '../../spec_helper'
require 'objspace'
describe "ObjectSpace.trace_object_allocations" do
+ def has_class_frame?
+ Class.new {
+ attr_reader :c
+
+ def initialize
+ @c = caller_locations.first.label =~ /new/
+ end
+ }.new.c
+ end
+
+ def obj_class_path
+ has_class_frame? ? "Class" : nil
+ end
+
it "runs a block" do
ScratchPad.clear
ObjectSpace.trace_object_allocations do
@@ -13,7 +27,7 @@ describe "ObjectSpace.trace_object_allocations" do
it "records info for allocation_class_path" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
a = [1, 2, 3]
ObjectSpace.allocation_class_path(a).should == nil
end
@@ -31,7 +45,7 @@ describe "ObjectSpace.trace_object_allocations" do
it "records info for allocation_method_id" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_method_id(o).should == :new
+ ObjectSpace.allocation_method_id(o).should == (has_class_frame? ? :new : nil)
a = [1, 2, 3]
ObjectSpace.allocation_method_id(a).should == nil
end
@@ -58,7 +72,7 @@ describe "ObjectSpace.trace_object_allocations" do
it "can be cleared using trace_object_allocations_clear" do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ObjectSpace.trace_object_allocations_clear
ObjectSpace.allocation_class_path(o).should be_nil
end
@@ -69,14 +83,14 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations do
o = Object.new
end
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
it "can be used without a block using trace_object_allocations_start and _stop" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
a = [1, 2, 3]
ObjectSpace.allocation_class_path(a).should == nil
ensure
@@ -91,14 +105,14 @@ describe "ObjectSpace.trace_object_allocations" do
ensure
ObjectSpace.trace_object_allocations_stop
end
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
it "can be nested" do
ObjectSpace.trace_object_allocations do
ObjectSpace.trace_object_allocations do
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
end
end
end
@@ -109,7 +123,7 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ensure
ObjectSpace.trace_object_allocations_stop
end
@@ -122,7 +136,7 @@ describe "ObjectSpace.trace_object_allocations" do
ObjectSpace.trace_object_allocations_start
begin
o = Object.new
- ObjectSpace.allocation_class_path(o).should == "Class"
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
ObjectSpace.trace_object_allocations_stop
ensure
ObjectSpace.trace_object_allocations_stop
diff --git a/spec/ruby/library/openssl/digest/initialize_spec.rb b/spec/ruby/library/openssl/digest/initialize_spec.rb
index 1cd0409c4d..b5911716ca 100644
--- a/spec/ruby/library/openssl/digest/initialize_spec.rb
+++ b/spec/ruby/library/openssl/digest/initialize_spec.rb
@@ -23,18 +23,14 @@ describe "OpenSSL::Digest#initialize" do
OpenSSL::Digest.new("sha512").name.should == "SHA512"
end
- it "throws an error when called with an unknown digest" do
- -> { OpenSSL::Digest.new("wd40") }.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/)
+ version_is OpenSSL::VERSION, "4.0.0" do
+ it "throws an error when called with an unknown digest" do
+ -> { OpenSSL::Digest.new("wd40") }.should raise_error(OpenSSL::Digest::DigestError, /wd40/)
+ end
end
it "cannot be called with a symbol" do
- -> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError, /wrong argument type Symbol/)
- end
-
- it "does not call #to_str on the argument" do
- name = mock("digest name")
- name.should_not_receive(:to_str)
- -> { OpenSSL::Digest.new(name) }.should raise_error(TypeError, /wrong argument type/)
+ -> { OpenSSL::Digest.new(:SHA1) }.should raise_error(TypeError)
end
end
@@ -62,7 +58,7 @@ describe "OpenSSL::Digest#initialize" do
end
it "cannot be called with a digest class" do
- -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError, /wrong argument type Class/)
+ -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should raise_error(TypeError)
end
context "when called without an initial String argument" do
diff --git a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
index 40f8597275..1112972060 100644
--- a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
+++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
@@ -107,21 +107,15 @@ describe "OpenSSL::KDF.pbkdf2_hmac" do
it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest" do
-> {
OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: Object.new)
- }.should raise_error(TypeError, "wrong argument type Object (expected OpenSSL/Digest)")
+ }.should raise_error(TypeError)
end
- it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest, it does not try to call #to_str" do
- hash = mock("hash")
- hash.should_not_receive(:to_str)
- -> {
- OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: hash)
- }.should raise_error(TypeError, "wrong argument type MockObject (expected OpenSSL/Digest)")
- end
-
- it "raises a RuntimeError for unknown digest algorithms" do
- -> {
- OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40")
- }.should raise_error(RuntimeError, /Unsupported digest algorithm \(wd40\)/)
+ version_is OpenSSL::VERSION, "4.0.0" do
+ it "raises a OpenSSL::Digest::DigestError for unknown digest algorithms" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40")
+ }.should raise_error(OpenSSL::Digest::DigestError, /wd40/)
+ end
end
it "treats salt as a required keyword" do
diff --git a/spec/ruby/library/openssl/kdf/scrypt_spec.rb b/spec/ruby/library/openssl/kdf/scrypt_spec.rb
index 5dc9f2f281..e01b8bca8a 100644
--- a/spec/ruby/library/openssl/kdf/scrypt_spec.rb
+++ b/spec/ruby/library/openssl/kdf/scrypt_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../../spec_helper'
require 'openssl'
-guard -> { OpenSSL::KDF.respond_to?(:scrypt) } do
+# LibreSSL seems not to support scrypt
+guard -> { OpenSSL::OPENSSL_VERSION.start_with?('OpenSSL') and OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000 } do
describe "OpenSSL::KDF.scrypt" do
before :each do
@defaults = {
diff --git a/spec/ruby/library/openssl/shared/constants.rb b/spec/ruby/library/openssl/shared/constants.rb
index 0bed4156a1..836f75011b 100644
--- a/spec/ruby/library/openssl/shared/constants.rb
+++ b/spec/ruby/library/openssl/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
module HMACConstants
Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
diff --git a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
index 522aad22e6..521a750bf7 100644
--- a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
+++ b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb
@@ -2,22 +2,16 @@ require_relative '../../spec_helper'
require 'rbconfig'
describe "RbConfig::CONFIG['UNICODE_EMOJI_VERSION']" do
- ruby_version_is ""..."3.2" do
- it "is 13.1" do
- RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "13.1"
- end
- end
-
- ruby_version_is "3.2"..."3.4" do
+ ruby_version_is ""..."3.4" do
it "is 15.0" do
RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "15.0"
end
end
# Caution: ruby_version_is means is_or_later
- ruby_version_is "3.5" do
- it "is 16.0" do
- RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "16.0"
+ ruby_version_is "4.0" do
+ it "is 17.0" do
+ RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "17.0"
end
end
end
diff --git a/spec/ruby/library/rbconfig/unicode_version_spec.rb b/spec/ruby/library/rbconfig/unicode_version_spec.rb
index 0c8372b9da..5cdde74f79 100644
--- a/spec/ruby/library/rbconfig/unicode_version_spec.rb
+++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb
@@ -2,22 +2,16 @@ require_relative '../../spec_helper'
require 'rbconfig'
describe "RbConfig::CONFIG['UNICODE_VERSION']" do
- ruby_version_is ""..."3.2" do
- it "is 13.0.0" do
- RbConfig::CONFIG['UNICODE_VERSION'].should == "13.0.0"
- end
- end
-
- ruby_version_is "3.2"..."3.4" do
+ ruby_version_is ""..."3.4" do
it "is 15.0.0" do
RbConfig::CONFIG['UNICODE_VERSION'].should == "15.0.0"
end
end
# Caution: ruby_version_is means is_or_later
- ruby_version_is "3.5" do
- it "is 16.0.0" do
- RbConfig::CONFIG['UNICODE_VERSION'].should == "16.0.0"
+ ruby_version_is "4.0" do
+ it "is 17.0.0" do
+ RbConfig::CONFIG['UNICODE_VERSION'].should == "17.0.0"
end
end
end
diff --git a/spec/ruby/library/set/flatten_merge_spec.rb b/spec/ruby/library/set/flatten_merge_spec.rb
deleted file mode 100644
index f2c99a9481..0000000000
--- a/spec/ruby/library/set/flatten_merge_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require_relative '../../spec_helper'
-require 'set'
-
-describe "Set#flatten_merge" do
- it "is protected" do
- Set.should have_protected_instance_method("flatten_merge")
- end
-
- it "flattens the passed Set and merges it into self" do
- set1 = Set[1, 2]
- set2 = Set[3, 4, Set[5, 6]]
-
- set1.send(:flatten_merge, set2).should == Set[1, 2, 3, 4, 5, 6]
- end
-
- it "raises an ArgumentError when trying to flatten a recursive Set" do
- set1 = Set[1, 2, 3]
- set2 = Set[5, 6, 7]
- set2 << set2
-
- -> { set1.send(:flatten_merge, set2) }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/library/set/set_spec.rb b/spec/ruby/library/set/set_spec.rb
deleted file mode 100644
index 2a4edc6dfc..0000000000
--- a/spec/ruby/library/set/set_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_relative '../../spec_helper'
-
-describe 'Set' do
- ruby_version_is '3.2' do
- it 'is available without explicit requiring' do
- output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
- puts Set.new([1, 2, 3])
- RUBY
- output.chomp.should == "#<Set: {1, 2, 3}>"
- end
- end
-end
diff --git a/spec/ruby/library/set/shared/inspect.rb b/spec/ruby/library/set/shared/inspect.rb
deleted file mode 100644
index adb6ddb4c9..0000000000
--- a/spec/ruby/library/set/shared/inspect.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-describe :set_inspect, shared: true do
- it "returns a String representation of self" do
- Set[].send(@method).should be_kind_of(String)
- Set[nil, false, true].send(@method).should be_kind_of(String)
- Set[1, 2, 3].send(@method).should be_kind_of(String)
- Set["1", "2", "3"].send(@method).should be_kind_of(String)
- Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String)
- end
-
- it "does include the elements of the set" do
- Set["1"].send(@method).should == '#<Set: {"1"}>'
- end
-
- it "puts spaces between the elements" do
- Set["1", "2"].send(@method).should include('", "')
- end
-
- it "correctly handles cyclic-references" do
- set1 = Set[]
- set2 = Set[set1]
- set1 << set2
- set1.send(@method).should be_kind_of(String)
- set1.send(@method).should include("#<Set: {...}>")
- end
-end
diff --git a/spec/ruby/library/set/sortedset/sortedset_spec.rb b/spec/ruby/library/set/sortedset/sortedset_spec.rb
deleted file mode 100644
index 67993dee29..0000000000
--- a/spec/ruby/library/set/sortedset/sortedset_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_relative '../../../spec_helper'
-require 'set'
-
-describe "SortedSet" do
- it "raises error including message that it has been extracted from the set stdlib" do
- -> {
- SortedSet
- }.should raise_error(RuntimeError) { |e|
- e.message.should.include?("The `SortedSet` class has been extracted from the `set` library")
- }
- end
-end
diff --git a/spec/ruby/library/socket/addrinfo/afamily_spec.rb b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
index 7229dab9de..5d075be057 100644
--- a/spec/ruby/library/socket/addrinfo/afamily_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/afamily_spec.rb
@@ -23,15 +23,13 @@ describe "Addrinfo#afamily" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns Socket::AF_UNIX" do
- @addrinfo.afamily.should == Socket::AF_UNIX
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns Socket::AF_UNIX" do
+ @addrinfo.afamily.should == Socket::AF_UNIX
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
index 2bc3b6a2e3..3c2f9f73d8 100644
--- a/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb
@@ -50,38 +50,36 @@ describe 'Addrinfo#family_addrinfo' do
end
end
- with_feature :unix_socket do
- describe 'with a UNIX Addrinfo' do
- before do
- @source = Addrinfo.unix('cats')
- end
+ describe 'with a UNIX Addrinfo' do
+ before do
+ @source = Addrinfo.unix('cats')
+ end
- it 'raises ArgumentError if more than 1 argument is given' do
- -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError)
- end
+ it 'raises ArgumentError if more than 1 argument is given' do
+ -> { @source.family_addrinfo('foo', 'bar') }.should raise_error(ArgumentError)
+ end
- it 'returns an Addrinfo when a UNIX socket path is given' do
- addr = @source.family_addrinfo('dogs')
+ it 'returns an Addrinfo when a UNIX socket path is given' do
+ addr = @source.family_addrinfo('dogs')
- addr.should be_an_instance_of(Addrinfo)
- end
+ addr.should be_an_instance_of(Addrinfo)
+ end
- describe 'the returned Addrinfo' do
- before do
- @addr = @source.family_addrinfo('dogs')
- end
+ describe 'the returned Addrinfo' do
+ before do
+ @addr = @source.family_addrinfo('dogs')
+ end
- it 'uses AF_UNIX as the address family' do
- @addr.afamily.should == Socket::AF_UNIX
- end
+ it 'uses AF_UNIX as the address family' do
+ @addr.afamily.should == Socket::AF_UNIX
+ end
- it 'uses PF_UNIX as the protocol family' do
- @addr.pfamily.should == Socket::PF_UNIX
- end
+ it 'uses PF_UNIX as the protocol family' do
+ @addr.pfamily.should == Socket::PF_UNIX
+ end
- it 'uses the given socket path' do
- @addr.unix_path.should == 'dogs'
- end
+ it 'uses the given socket path' do
+ @addr.unix_path.should == 'dogs'
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
index 76579de74c..43b5a2000a 100644
--- a/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb
@@ -22,19 +22,17 @@ describe 'Addrinfo#getnameinfo' do
platform_is :linux do
platform_is_not :android do
- with_feature :unix_socket do
- describe 'using a UNIX Addrinfo' do
- before do
- @addr = Addrinfo.unix('cats')
- @host = Socket.gethostname
- end
+ describe 'using a UNIX Addrinfo' do
+ before do
+ @addr = Addrinfo.unix('cats')
+ @host = Socket.gethostname
+ end
- it 'returns the hostname and UNIX socket path' do
- host, path = @addr.getnameinfo
+ it 'returns the hostname and UNIX socket path' do
+ host, path = @addr.getnameinfo
- host.should == @host
- path.should == 'cats'
- end
+ host.should == @host
+ path.should == 'cats'
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/initialize_spec.rb b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
index b7477efc79..1f16531aaa 100644
--- a/spec/ruby/library/socket/addrinfo/initialize_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/initialize_spec.rb
@@ -17,7 +17,7 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 25
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the UNSPEC pfamily" do
@addrinfo.pfamily.should == Socket::PF_UNSPEC
end
@@ -53,7 +53,7 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 25
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET6 pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET6
end
@@ -83,7 +83,7 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 25
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET6 pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET6
end
@@ -113,7 +113,7 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 25
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET6 pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET6
end
@@ -147,11 +147,11 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 46102
end
- it "returns the Socket::PF_INET pfamily" do
+ it "returns the INET pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET
end
- it "returns the INET6 afamily" do
+ it "returns the INET afamily" do
@addrinfo.afamily.should == Socket::AF_INET
end
@@ -217,11 +217,11 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 46102
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET
end
- it "returns the INET6 afamily" do
+ it "returns the INET afamily" do
@addrinfo.afamily.should == Socket::AF_INET
end
@@ -247,11 +247,11 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 46102
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET
end
- it "returns the INET6 afamily" do
+ it "returns the INET afamily" do
@addrinfo.afamily.should == Socket::AF_INET
end
@@ -311,11 +311,11 @@ describe "Addrinfo#initialize" do
@addrinfo.ip_port.should == 46102
end
- it "returns the Socket::UNSPEC pfamily" do
+ it "returns the INET pfamily" do
@addrinfo.pfamily.should == Socket::PF_INET
end
- it "returns the INET6 afamily" do
+ it "returns the INET afamily" do
@addrinfo.afamily.should == Socket::AF_INET
end
@@ -514,13 +514,13 @@ describe "Addrinfo#initialize" do
@sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
end
- it 'returns an Addrinfo with :PF_INET family' do
+ it 'returns an Addrinfo with :PF_INET family' do
addr = Addrinfo.new(@sockaddr, :PF_INET)
addr.pfamily.should == Socket::PF_INET
end
- it 'returns an Addrinfo with :INET family' do
+ it 'returns an Addrinfo with :INET family' do
addr = Addrinfo.new(@sockaddr, :INET)
addr.pfamily.should == Socket::PF_INET
@@ -544,13 +544,13 @@ describe "Addrinfo#initialize" do
@sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
end
- it 'returns an Addrinfo with "PF_INET" family' do
+ it 'returns an Addrinfo with "PF_INET" family' do
addr = Addrinfo.new(@sockaddr, 'PF_INET')
addr.pfamily.should == Socket::PF_INET
end
- it 'returns an Addrinfo with "INET" family' do
+ it 'returns an Addrinfo with "INET" family' do
addr = Addrinfo.new(@sockaddr, 'INET')
addr.pfamily.should == Socket::PF_INET
@@ -569,23 +569,21 @@ describe "Addrinfo#initialize" do
end
end
- with_feature :unix_socket do
- describe 'using separate arguments for a Unix socket' do
- before do
- @sockaddr = Socket.pack_sockaddr_un('socket')
- end
+ describe 'using separate arguments for a Unix socket' do
+ before do
+ @sockaddr = Socket.pack_sockaddr_un('socket')
+ end
- it 'returns an Addrinfo with the correct unix path' do
- Addrinfo.new(@sockaddr).unix_path.should == 'socket'
- end
+ it 'returns an Addrinfo with the correct unix path' do
+ Addrinfo.new(@sockaddr).unix_path.should == 'socket'
+ end
- it 'returns an Addrinfo with the correct protocol family' do
- Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC
- end
+ it 'returns an Addrinfo with the correct protocol family' do
+ Addrinfo.new(@sockaddr).pfamily.should == Socket::PF_UNSPEC
+ end
- it 'returns an Addrinfo with the correct address family' do
- Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX
- end
+ it 'returns an Addrinfo with the correct address family' do
+ Addrinfo.new(@sockaddr).afamily.should == Socket::AF_UNIX
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
index 70ca4dd4d7..6b18c79469 100644
--- a/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb
@@ -32,19 +32,17 @@ describe 'Addrinfo#inspect_sockaddr' do
end
end
- with_feature :unix_socket do
- describe 'using a UNIX path' do
- it 'returns a String containing the UNIX path' do
- addr = Addrinfo.unix('/foo/bar')
+ describe 'using a UNIX path' do
+ it 'returns a String containing the UNIX path' do
+ addr = Addrinfo.unix('/foo/bar')
- addr.inspect_sockaddr.should == '/foo/bar'
- end
+ addr.inspect_sockaddr.should == '/foo/bar'
+ end
- it 'returns a String containing the UNIX path when using a relative path' do
- addr = Addrinfo.unix('foo')
+ it 'returns a String containing the UNIX path when using a relative path' do
+ addr = Addrinfo.unix('foo')
- addr.inspect_sockaddr.should == 'UNIX foo'
- end
+ addr.inspect_sockaddr.should == 'UNIX foo'
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/inspect_spec.rb b/spec/ruby/library/socket/addrinfo/inspect_spec.rb
index 98e1e83ffa..1442af6162 100644
--- a/spec/ruby/library/socket/addrinfo/inspect_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/inspect_spec.rb
@@ -41,25 +41,23 @@ describe 'Addrinfo#inspect' do
end
end
- with_feature :unix_socket do
- describe 'using a UNIX Addrinfo' do
- it 'returns a String' do
- addr = Addrinfo.unix('/foo')
+ describe 'using a UNIX Addrinfo' do
+ it 'returns a String' do
+ addr = Addrinfo.unix('/foo')
- addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>'
- end
+ addr.inspect.should == '#<Addrinfo: /foo SOCK_STREAM>'
+ end
- it 'returns a String when using a relative UNIX path' do
- addr = Addrinfo.unix('foo')
+ it 'returns a String when using a relative UNIX path' do
+ addr = Addrinfo.unix('foo')
- addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>'
- end
+ addr.inspect.should == '#<Addrinfo: UNIX foo SOCK_STREAM>'
+ end
- it 'returns a String when using a DGRAM socket' do
- addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM)
+ it 'returns a String when using a DGRAM socket' do
+ addr = Addrinfo.unix('/foo', Socket::SOCK_DGRAM)
- addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>'
- end
+ addr.inspect.should == '#<Addrinfo: /foo SOCK_DGRAM>'
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
index 4522cf5cfd..193432e861 100644
--- a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
@@ -21,15 +21,13 @@ describe "Addrinfo#ip_address" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "raises an exception" do
- -> { @addrinfo.ip_address }.should raise_error(SocketError)
- end
+ it "raises an exception" do
+ -> { @addrinfo.ip_address }.should raise_error(SocketError)
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
index 4118607db0..f10ce35143 100644
--- a/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_port_spec.rb
@@ -21,15 +21,13 @@ describe "Addrinfo#ip_port" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "raises an exception" do
- -> { @addrinfo.ip_port }.should raise_error(SocketError)
- end
+ it "raises an exception" do
+ -> { @addrinfo.ip_port }.should raise_error(SocketError)
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_spec.rb b/spec/ruby/library/socket/addrinfo/ip_spec.rb
index 80e7a62df7..09b9341605 100644
--- a/spec/ruby/library/socket/addrinfo/ip_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_spec.rb
@@ -22,15 +22,13 @@ describe "Addrinfo#ip?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns false" do
- @addrinfo.ip?.should be_false
- end
+ it "returns false" do
+ @addrinfo.ip?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
index 6c81c48d1c..58260c4557 100644
--- a/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb
@@ -21,15 +21,13 @@ describe "Addrinfo#ip_unpack" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "raises an exception" do
- -> { @addrinfo.ip_unpack }.should raise_error(SocketError)
- end
+ it "raises an exception" do
+ -> { @addrinfo.ip_unpack }.should raise_error(SocketError)
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
index 10ad084fc9..3a584d4f52 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb
@@ -29,15 +29,13 @@ describe "Addrinfo#ipv4_loopback?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns false" do
- @addrinfo.ipv4_loopback?.should be_false
- end
+ it "returns false" do
+ @addrinfo.ipv4_loopback?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
index f7fead8640..e4b4cfcc84 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb
@@ -15,15 +15,13 @@ describe "Addrinfo#ipv4_multicast?" do
Addrinfo.ip('::1').should_not.ipv4_multicast?
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns false" do
- @addrinfo.ipv4_multicast?.should be_false
- end
+ it "returns false" do
+ @addrinfo.ipv4_multicast?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
index e5a33b4953..97218b5ba3 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb
@@ -33,15 +33,13 @@ describe "Addrinfo#ipv4_private?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns false" do
- @addrinfo.ipv4_private?.should be_false
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv4_private?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
index 7cba8209b6..61f7759b10 100644
--- a/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv4_spec.rb
@@ -21,15 +21,13 @@ describe "Addrinfo#ipv4?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns false" do
- @addrinfo.ipv4?.should be_false
- end
+ it "returns false" do
+ @addrinfo.ipv4?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
index 9ff8f107bf..ffc75185ea 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb
@@ -31,15 +31,13 @@ describe "Addrinfo#ipv6_loopback?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns false" do
- @addrinfo.ipv6_loopback?.should be_false
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6_loopback?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
index 2c987b5921..99d4e8cf4d 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb
@@ -34,15 +34,13 @@ describe "Addrinfo#ipv6_multicast?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns false" do
- @addrinfo.ipv6_multicast?.should be_false
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns false" do
+ @addrinfo.ipv6_multicast?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
index 131e38849c..436d5e930b 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_spec.rb
@@ -21,15 +21,13 @@ describe "Addrinfo#ipv6?" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns false" do
- @addrinfo.ipv6?.should be_false
- end
+ it "returns false" do
+ @addrinfo.ipv6?.should be_false
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
index 6dfaf531ae..29050bec20 100644
--- a/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb
@@ -62,7 +62,7 @@ guard -> { SocketSpecs.ipv6_available? } do
Addrinfo.ip('192.168.1.1').ipv6_to_ipv4.should be_nil
end
- with_feature :unix_socket do
+ describe 'for a unix socket' do
it 'returns nil for a UNIX Addrinfo' do
Addrinfo.unix('foo').ipv6_to_ipv4.should be_nil
end
diff --git a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
index 2d69a33b53..e2c3497f7f 100644
--- a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb
@@ -42,40 +42,38 @@ describe 'Addrinfo#marshal_dump' do
end
end
- with_feature :unix_socket do
- describe 'using a UNIX Addrinfo' do
+ describe 'using a UNIX Addrinfo' do
+ before do
+ @addr = Addrinfo.unix('foo')
+ end
+
+ it 'returns an Array' do
+ @addr.marshal_dump.should be_an_instance_of(Array)
+ end
+
+ describe 'the returned Array' do
before do
- @addr = Addrinfo.unix('foo')
+ @array = @addr.marshal_dump
end
- it 'returns an Array' do
- @addr.marshal_dump.should be_an_instance_of(Array)
+ it 'includes the address family as the 1st value' do
+ @array[0].should == 'AF_UNIX'
end
- describe 'the returned Array' do
- before do
- @array = @addr.marshal_dump
- end
-
- it 'includes the address family as the 1st value' do
- @array[0].should == 'AF_UNIX'
- end
-
- it 'includes the UNIX path as the 2nd value' do
- @array[1].should == @addr.unix_path
- end
+ it 'includes the UNIX path as the 2nd value' do
+ @array[1].should == @addr.unix_path
+ end
- it 'includes the protocol family as the 3rd value' do
- @array[2].should == 'PF_UNIX'
- end
+ it 'includes the protocol family as the 3rd value' do
+ @array[2].should == 'PF_UNIX'
+ end
- it 'includes the socket type as the 4th value' do
- @array[3].should == 'SOCK_STREAM'
- end
+ it 'includes the socket type as the 4th value' do
+ @array[3].should == 'SOCK_STREAM'
+ end
- it 'includes the protocol as the 5th value' do
- @array[4].should == 0
- end
+ it 'includes the protocol as the 5th value' do
+ @array[4].should == 0
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
index aa20865224..02cef90115 100644
--- a/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/marshal_load_spec.rb
@@ -18,18 +18,16 @@ describe 'Addrinfo#marshal_load' do
end
end
- with_feature :unix_socket do
- describe 'using a UNIX socket' do
- it 'returns a new Addrinfo' do
- source = Addrinfo.unix('foo')
- addr = Marshal.load(Marshal.dump(source))
+ describe 'using a UNIX socket' do
+ it 'returns a new Addrinfo' do
+ source = Addrinfo.unix('foo')
+ addr = Marshal.load(Marshal.dump(source))
- addr.afamily.should == source.afamily
- addr.pfamily.should == source.pfamily
- addr.socktype.should == source.socktype
- addr.protocol.should == source.protocol
- addr.unix_path.should == source.unix_path
- end
+ addr.afamily.should == source.afamily
+ addr.pfamily.should == source.pfamily
+ addr.socktype.should == source.socktype
+ addr.protocol.should == source.protocol
+ addr.unix_path.should == source.unix_path
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
index 984744a964..da530b7fdc 100644
--- a/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/pfamily_spec.rb
@@ -29,15 +29,13 @@ describe "Addrinfo#pfamily" do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns Socket::PF_UNIX" do
- @addrinfo.pfamily.should == Socket::PF_UNIX
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns Socket::PF_UNIX" do
+ @addrinfo.pfamily.should == Socket::PF_UNIX
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/protocol_spec.rb b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
index ea143fc4a8..f6ffc9acf9 100644
--- a/spec/ruby/library/socket/addrinfo/protocol_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/protocol_spec.rb
@@ -10,15 +10,13 @@ describe "Addrinfo#protocol" do
Addrinfo.tcp('::1', 80).protocol.should == Socket::IPPROTO_TCP
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns 0" do
- @addrinfo.protocol.should == 0
- end
+ it "returns 0" do
+ @addrinfo.protocol.should == 0
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
index 4f7cf439a0..70d6bfbbfe 100644
--- a/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
+++ b/spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb
@@ -19,15 +19,13 @@ describe :socket_addrinfo_to_sockaddr, shared: true do
end
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
-
- it "returns a sockaddr packed structure" do
- @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock')
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
+
+ it "returns a sockaddr packed structure" do
+ @addrinfo.send(@method).should == Socket.sockaddr_un('/tmp/sock')
end
end
diff --git a/spec/ruby/library/socket/addrinfo/socktype_spec.rb b/spec/ruby/library/socket/addrinfo/socktype_spec.rb
index b994bea140..e5f02cd759 100644
--- a/spec/ruby/library/socket/addrinfo/socktype_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/socktype_spec.rb
@@ -9,15 +9,13 @@ describe "Addrinfo#socktype" do
Addrinfo.tcp('127.0.0.1', 80).socktype.should == Socket::SOCK_STREAM
end
- with_feature :unix_socket do
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns Socket::SOCK_STREAM" do
- @addrinfo.socktype.should == Socket::SOCK_STREAM
- end
+ it "returns Socket::SOCK_STREAM" do
+ @addrinfo.socktype.should == Socket::SOCK_STREAM
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
index 6bfb56a4ac..2a9076a354 100644
--- a/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/unix_path_spec.rb
@@ -1,37 +1,35 @@
require_relative '../spec_helper'
-with_feature :unix_socket do
- describe "Addrinfo#unix_path" do
- describe "for an ipv4 socket" do
+describe "Addrinfo#unix_path" do
+ describe "for an ipv4 socket" do
- before :each do
- @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
- end
-
- it "raises an exception" do
- -> { @addrinfo.unix_path }.should raise_error(SocketError)
- end
+ before :each do
+ @addrinfo = Addrinfo.tcp("127.0.0.1", 80)
+ end
+ it "raises an exception" do
+ -> { @addrinfo.unix_path }.should raise_error(SocketError)
end
- describe "for an ipv6 socket" do
- before :each do
- @addrinfo = Addrinfo.tcp("::1", 80)
- end
+ end
- it "raises an exception" do
- -> { @addrinfo.unix_path }.should raise_error(SocketError)
- end
+ describe "for an ipv6 socket" do
+ before :each do
+ @addrinfo = Addrinfo.tcp("::1", 80)
end
- describe "for a unix socket" do
- before :each do
- @addrinfo = Addrinfo.unix("/tmp/sock")
- end
+ it "raises an exception" do
+ -> { @addrinfo.unix_path }.should raise_error(SocketError)
+ end
+ end
+
+ describe "for a unix socket" do
+ before :each do
+ @addrinfo = Addrinfo.unix("/tmp/sock")
+ end
- it "returns the socket path" do
- @addrinfo.unix_path.should == "/tmp/sock"
- end
+ it "returns the socket path" do
+ @addrinfo.unix_path.should == "/tmp/sock"
end
end
end
diff --git a/spec/ruby/library/socket/addrinfo/unix_spec.rb b/spec/ruby/library/socket/addrinfo/unix_spec.rb
index 4596ece17e..7597533a76 100644
--- a/spec/ruby/library/socket/addrinfo/unix_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/unix_spec.rb
@@ -1,36 +1,34 @@
require_relative '../spec_helper'
-with_feature :unix_socket do
- describe 'Addrinfo.unix' do
- it 'returns an Addrinfo instance' do
- Addrinfo.unix('socket').should be_an_instance_of(Addrinfo)
- end
+describe 'Addrinfo.unix' do
+ it 'returns an Addrinfo instance' do
+ Addrinfo.unix('socket').should be_an_instance_of(Addrinfo)
+ end
- it 'sets the IP address' do
- Addrinfo.unix('socket').unix_path.should == 'socket'
- end
+ it 'sets the IP address' do
+ Addrinfo.unix('socket').unix_path.should == 'socket'
+ end
- it 'sets the address family' do
- Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX
- end
+ it 'sets the address family' do
+ Addrinfo.unix('socket').afamily.should == Socket::AF_UNIX
+ end
- it 'sets the protocol family' do
- Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX
- end
+ it 'sets the protocol family' do
+ Addrinfo.unix('socket').pfamily.should == Socket::PF_UNIX
+ end
- it 'sets the socket type' do
- Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM
- end
+ it 'sets the socket type' do
+ Addrinfo.unix('socket').socktype.should == Socket::SOCK_STREAM
+ end
- it 'sets a custom socket type' do
- addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM)
+ it 'sets a custom socket type' do
+ addr = Addrinfo.unix('socket', Socket::SOCK_DGRAM)
- addr.socktype.should == Socket::SOCK_DGRAM
- end
+ addr.socktype.should == Socket::SOCK_DGRAM
+ end
- it 'sets the socket protocol to 0' do
- Addrinfo.unix('socket').protocol.should == 0
- end
+ it 'sets the socket protocol to 0' do
+ Addrinfo.unix('socket').protocol.should == 0
end
end
diff --git a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb
index 1a1c9982d9..2e318fcb85 100644
--- a/spec/ruby/library/socket/basicsocket/connect_address_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/connect_address_spec.rb
@@ -94,61 +94,59 @@ describe 'Socket#connect_address' do
end
end
- with_feature :unix_socket do
- platform_is_not :aix do
- describe 'using an unbound UNIX socket' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- @client = UNIXSocket.new(@path)
- end
-
- after do
- @client.close
- @server.close
- rm_r(@path)
- end
-
- it 'raises SocketError' do
- -> { @client.connect_address }.should raise_error(SocketError)
- end
- end
- end
-
- describe 'using a bound UNIX socket' do
+ platform_is_not :aix do
+ describe 'using an unbound UNIX socket' do
before do
@path = SocketSpecs.socket_path
- @sock = UNIXServer.new(@path)
+ @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
end
after do
- @sock.close
+ @client.close
+ @server.close
rm_r(@path)
end
- it 'returns an Addrinfo' do
- @sock.connect_address.should be_an_instance_of(Addrinfo)
+ it 'raises SocketError' do
+ -> { @client.connect_address }.should raise_error(SocketError)
end
+ end
+ end
- it 'uses the correct socket path' do
- @sock.connect_address.unix_path.should == @path
- end
+ describe 'using a bound UNIX socket' do
+ before do
+ @path = SocketSpecs.socket_path
+ @sock = UNIXServer.new(@path)
+ end
- it 'uses AF_UNIX as the address family' do
- @sock.connect_address.afamily.should == Socket::AF_UNIX
- end
+ after do
+ @sock.close
+ rm_r(@path)
+ end
- it 'uses PF_UNIX as the protocol family' do
- @sock.connect_address.pfamily.should == Socket::PF_UNIX
- end
+ it 'returns an Addrinfo' do
+ @sock.connect_address.should be_an_instance_of(Addrinfo)
+ end
- it 'uses SOCK_STREAM as the socket type' do
- @sock.connect_address.socktype.should == Socket::SOCK_STREAM
- end
+ it 'uses the correct socket path' do
+ @sock.connect_address.unix_path.should == @path
+ end
- it 'uses 0 as the protocol' do
- @sock.connect_address.protocol.should == 0
- end
+ it 'uses AF_UNIX as the address family' do
+ @sock.connect_address.afamily.should == Socket::AF_UNIX
+ end
+
+ it 'uses PF_UNIX as the protocol family' do
+ @sock.connect_address.pfamily.should == Socket::PF_UNIX
+ end
+
+ it 'uses SOCK_STREAM as the socket type' do
+ @sock.connect_address.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'uses 0 as the protocol' do
+ @sock.connect_address.protocol.should == 0
end
end
end
diff --git a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb
index 6179211d96..2e03cd3684 100644
--- a/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/getpeereid_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe 'BasicSocket#getpeereid' do
- with_feature :unix_socket do
+ platform_is_not :windows do
describe 'using a UNIXSocket' do
before do
@path = SocketSpecs.socket_path
diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb
index 40033a5f5d..a51920f52a 100644
--- a/spec/ruby/library/socket/basicsocket/recv_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
index 1e8d84e1c9..f686e67326 100644
--- a/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
+++ b/spec/ruby/library/socket/basicsocket/setsockopt_spec.rb
@@ -315,22 +315,20 @@ describe 'BasicSocket#setsockopt' do
end
end
- with_feature :unix_socket do
- describe 'using a UNIX socket' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- end
+ describe 'using a UNIX socket' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
- after do
- @server.close
- rm_r @path
- end
+ after do
+ @server.close
+ rm_r @path
+ end
- it 'sets a boolean option' do
- @server.setsockopt(:SOCKET, :REUSEADDR, true)
- @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
- end
+ it 'sets a boolean option' do
+ @server.setsockopt(:SOCKET, :REUSEADDR, true)
+ @server.getsockopt(:SOCKET, :REUSEADDR).bool.should == true
end
end
end
diff --git a/spec/ruby/library/socket/shared/address.rb b/spec/ruby/library/socket/shared/address.rb
index f3be9cfb99..49ba17c400 100644
--- a/spec/ruby/library/socket/shared/address.rb
+++ b/spec/ruby/library/socket/shared/address.rb
@@ -129,41 +129,51 @@ describe :socket_local_remote_address, shared: true do
end
end
- with_feature :unix_socket do
- describe 'using UNIXSocket' do
- before :each do
- @path = SocketSpecs.socket_path
- @s = UNIXServer.new(@path)
- @a = UNIXSocket.new(@path)
- @b = @s.accept
- @addr = @object.call(@a)
- end
+ describe 'using UNIXSocket' do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @s = UNIXServer.new(@path)
+ @a = UNIXSocket.new(@path)
+ @b = @s.accept
+ @addr = @object.call(@a)
+ end
- after :each do
- [@b, @a, @s].each(&:close)
- rm_r(@path)
- end
+ after :each do
+ [@b, @a, @s].each(&:close)
+ rm_r(@path)
+ end
- it 'uses AF_UNIX as the address family' do
- @addr.afamily.should == Socket::AF_UNIX
- end
+ it 'uses AF_UNIX as the address family' do
+ @addr.afamily.should == Socket::AF_UNIX
+ end
- it 'uses PF_UNIX as the protocol family' do
- @addr.pfamily.should == Socket::PF_UNIX
- end
+ it 'uses PF_UNIX as the protocol family' do
+ @addr.pfamily.should == Socket::PF_UNIX
+ end
- it 'uses SOCK_STREAM as the socket type' do
- @addr.socktype.should == Socket::SOCK_STREAM
+ it 'uses SOCK_STREAM as the socket type' do
+ @addr.socktype.should == Socket::SOCK_STREAM
+ end
+
+ it 'uses the correct socket path' do
+ if @method == :local_address
+ @addr.unix_path.should == ""
+ else
+ @addr.unix_path.should == @path
end
+ end
- it 'uses the correct socket path' do
+ platform_is_not :windows do
+ it 'equals address of peer socket' do
if @method == :local_address
- @addr.unix_path.should == ""
+ @addr.to_s.should == @b.remote_address.to_s
else
- @addr.unix_path.should == @path
+ @addr.to_s.should == @b.local_address.to_s
end
end
+ end
+ guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do
it 'equals address of peer socket' do
if @method == :local_address
@addr.to_s.should == @b.remote_address.to_s
@@ -171,23 +181,23 @@ describe :socket_local_remote_address, shared: true do
@addr.to_s.should == @b.local_address.to_s
end
end
+ end
- it 'returns an Addrinfo' do
- @addr.should be_an_instance_of(Addrinfo)
- end
+ it 'returns an Addrinfo' do
+ @addr.should be_an_instance_of(Addrinfo)
+ end
- it 'uses 0 as the protocol' do
- @addr.protocol.should == 0
- end
+ it 'uses 0 as the protocol' do
+ @addr.protocol.should == 0
+ end
- it 'can be used to connect to the server' do
- skip if @method == :local_address
- b = @addr.connect
- begin
- b.remote_address.to_s.should == @addr.to_s
- ensure
- b.close
- end
+ it 'can be used to connect to the server' do
+ skip if @method == :local_address
+ b = @addr.connect
+ begin
+ b.remote_address.to_s.should == @addr.to_s
+ ensure
+ b.close
end
end
end
diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb
index f309aa02c7..4bfcf4edb9 100644
--- a/spec/ruby/library/socket/shared/pack_sockaddr.rb
+++ b/spec/ruby/library/socket/shared/pack_sockaddr.rb
@@ -47,23 +47,21 @@ describe :socket_pack_sockaddr_in, shared: true do
end
describe :socket_pack_sockaddr_un, shared: true do
- with_feature :unix_socket do
- it 'should be idempotent' do
- bytes = Socket.public_send(@method, '/tmp/foo').bytes
- bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111]
- bytes[10..-1].all?(&:zero?).should == true
- end
+ it 'should be idempotent' do
+ bytes = Socket.public_send(@method, '/tmp/foo').bytes
+ bytes[2..9].should == [47, 116, 109, 112, 47, 102, 111, 111]
+ bytes[10..-1].all?(&:zero?).should == true
+ end
- it "packs and unpacks" do
- sockaddr_un = Socket.public_send(@method, '/tmp/s')
- Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s'
- end
+ it "packs and unpacks" do
+ sockaddr_un = Socket.public_send(@method, '/tmp/s')
+ Socket.unpack_sockaddr_un(sockaddr_un).should == '/tmp/s'
+ end
- it "handles correctly paths with multibyte chars" do
- sockaddr_un = Socket.public_send(@method, '/home/ваÑÑ/sock')
- path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8')
- path.should == '/home/ваÑÑ/sock'
- end
+ it "handles correctly paths with multibyte chars" do
+ sockaddr_un = Socket.public_send(@method, '/home/ваÑÑ/sock')
+ path = Socket.unpack_sockaddr_un(sockaddr_un).encode('UTF-8', 'UTF-8')
+ path.should == '/home/ваÑÑ/sock'
end
platform_is :linux do
@@ -84,7 +82,7 @@ describe :socket_pack_sockaddr_un, shared: true do
end
end
- platform_is_not :windows, :aix do
+ platform_is_not :aix do
it "raises ArgumentError for paths that are too long" do
# AIX doesn't raise error
long_path = 'a' * 110
diff --git a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
index 9f049597d0..6576af52ee 100644
--- a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
+++ b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb
@@ -106,6 +106,24 @@ describe "Socket.getaddrinfo" do
]
res.each { |a| expected.should include(a) }
end
+
+ ruby_version_is ""..."3.3" do
+ it "raises SocketError when fails to resolve address" do
+ -> {
+ Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX")
+ }.should raise_error(SocketError)
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "raises ResolutionError when fails to resolve address" do
+ -> {
+ Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX")
+ }.should raise_error(Socket::ResolutionError) { |e|
+ [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code)
+ }
+ end
+ end
end
end
diff --git a/spec/ruby/library/socket/socket/gethostbyname_spec.rb b/spec/ruby/library/socket/socket/gethostbyname_spec.rb
index 0858e255e4..618ef85387 100644
--- a/spec/ruby/library/socket/socket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/socket/gethostbyname_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../spec_helper'
require_relative '../fixtures/classes'
diff --git a/spec/ruby/library/socket/socket/getnameinfo_spec.rb b/spec/ruby/library/socket/socket/getnameinfo_spec.rb
index 4f13bf484d..af4a10c9c2 100644
--- a/spec/ruby/library/socket/socket/getnameinfo_spec.rb
+++ b/spec/ruby/library/socket/socket/getnameinfo_spec.rb
@@ -60,6 +60,24 @@ describe "Socket.getnameinfo" do
name_info = Socket.getnameinfo ["AF_INET", 9, 'foo', '127.0.0.1']
name_info[1].should == 'discard'
end
+
+ ruby_version_is ""..."3.3" do
+ it "raises SocketError when fails to resolve address" do
+ -> {
+ Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"])
+ }.should raise_error(SocketError)
+ end
+ end
+
+ ruby_version_is "3.3" do
+ it "raises ResolutionError when fails to resolve address" do
+ -> {
+ Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"])
+ }.should raise_error(Socket::ResolutionError) { |e|
+ [Socket::EAI_FAMILY, Socket::EAI_FAIL].should.include?(e.error_code)
+ }
+ end
+ end
end
describe 'Socket.getnameinfo' do
diff --git a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb
index fc030e75b9..cd22ea56cf 100644
--- a/spec/ruby/library/socket/socket/udp_server_loop_spec.rb
+++ b/spec/ruby/library/socket/socket/udp_server_loop_spec.rb
@@ -50,10 +50,10 @@ describe 'Socket.udp_server_loop' do
end
end
+ thread.join
+
msg.should == 'hello'
src.should be_an_instance_of(Socket::UDPSource)
-
- thread.join
end
end
end
diff --git a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb b/spec/ruby/library/socket/socket/unix_server_loop_spec.rb
index 0f34d4a50b..6192bc8bf6 100644
--- a/spec/ruby/library/socket/socket/unix_server_loop_spec.rb
+++ b/spec/ruby/library/socket/socket/unix_server_loop_spec.rb
@@ -1,58 +1,56 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'Socket.unix_server_loop' do
- before do
- @path = SocketSpecs.socket_path
- end
+describe 'Socket.unix_server_loop' do
+ before do
+ @path = SocketSpecs.socket_path
+ end
- after do
- rm_r(@path) if File.file?(@path)
- end
+ after do
+ rm_r(@path) if File.file?(@path)
+ end
- describe 'when no connections are available' do
- it 'blocks the caller' do
- -> { Socket.unix_server_loop(@path) }.should block_caller
- end
+ describe 'when no connections are available' do
+ it 'blocks the caller' do
+ -> { Socket.unix_server_loop(@path) }.should block_caller
end
+ end
- describe 'when a connection is available' do
- before do
- @client = nil
- end
+ describe 'when a connection is available' do
+ before do
+ @client = nil
+ end
- after do
- @sock.close if @sock
- @client.close if @client
- end
+ after do
+ @sock.close if @sock
+ @client.close if @client
+ end
- it 'yields a Socket and an Addrinfo' do
- @sock, addr = nil
+ it 'yields a Socket and an Addrinfo' do
+ @sock, addr = nil
- thread = Thread.new do
- Socket.unix_server_loop(@path) do |socket, addrinfo|
- @sock = socket
- addr = addrinfo
+ thread = Thread.new do
+ Socket.unix_server_loop(@path) do |socket, addrinfo|
+ @sock = socket
+ addr = addrinfo
- break
- end
+ break
end
+ end
- SocketSpecs.loop_with_timeout do
- begin
- @client = Socket.unix(@path)
- rescue SystemCallError
- sleep 0.01
- :retry
- end
+ SocketSpecs.loop_with_timeout do
+ begin
+ @client = Socket.unix(@path)
+ rescue SystemCallError
+ sleep 0.01
+ :retry
end
+ end
- thread.join
+ thread.join
- @sock.should be_an_instance_of(Socket)
- addr.should be_an_instance_of(Addrinfo)
- end
+ @sock.should be_an_instance_of(Socket)
+ addr.should be_an_instance_of(Addrinfo)
end
end
end
diff --git a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb b/spec/ruby/library/socket/socket/unix_server_socket_spec.rb
index fc357740fa..34c3b96d07 100644
--- a/spec/ruby/library/socket/socket/unix_server_socket_spec.rb
+++ b/spec/ruby/library/socket/socket/unix_server_socket_spec.rb
@@ -1,48 +1,46 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'Socket.unix_server_socket' do
+describe 'Socket.unix_server_socket' do
+ before do
+ @path = SocketSpecs.socket_path
+ end
+
+ after do
+ rm_r(@path)
+ end
+
+ describe 'when no block is given' do
before do
- @path = SocketSpecs.socket_path
+ @socket = nil
end
after do
- rm_r(@path)
+ @socket.close
end
- describe 'when no block is given' do
- before do
- @socket = nil
- end
-
- after do
- @socket.close
- end
+ it 'returns a Socket' do
+ @socket = Socket.unix_server_socket(@path)
- it 'returns a Socket' do
- @socket = Socket.unix_server_socket(@path)
-
- @socket.should be_an_instance_of(Socket)
- end
+ @socket.should be_an_instance_of(Socket)
end
+ end
- describe 'when a block is given' do
- it 'yields a Socket' do
- Socket.unix_server_socket(@path) do |sock|
- sock.should be_an_instance_of(Socket)
- end
+ describe 'when a block is given' do
+ it 'yields a Socket' do
+ Socket.unix_server_socket(@path) do |sock|
+ sock.should be_an_instance_of(Socket)
end
+ end
- it 'closes the Socket when the block returns' do
- socket = nil
-
- Socket.unix_server_socket(@path) do |sock|
- socket = sock
- end
+ it 'closes the Socket when the block returns' do
+ socket = nil
- socket.should be_an_instance_of(Socket)
+ Socket.unix_server_socket(@path) do |sock|
+ socket = sock
end
+
+ socket.should be_an_instance_of(Socket)
end
end
end
diff --git a/spec/ruby/library/socket/socket/unix_spec.rb b/spec/ruby/library/socket/socket/unix_spec.rb
index 4bff59bd4b..2a5d77f96f 100644
--- a/spec/ruby/library/socket/socket/unix_spec.rb
+++ b/spec/ruby/library/socket/socket/unix_spec.rb
@@ -1,45 +1,43 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'Socket.unix' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- @socket = nil
- end
+describe 'Socket.unix' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @socket = nil
+ end
- after do
- @server.close
- @socket.close if @socket
+ after do
+ @server.close
+ @socket.close if @socket
- rm_r(@path)
- end
+ rm_r(@path)
+ end
- describe 'when no block is given' do
- it 'returns a Socket' do
- @socket = Socket.unix(@path)
+ describe 'when no block is given' do
+ it 'returns a Socket' do
+ @socket = Socket.unix(@path)
- @socket.should be_an_instance_of(Socket)
- end
+ @socket.should be_an_instance_of(Socket)
end
+ end
- describe 'when a block is given' do
- it 'yields a Socket' do
- Socket.unix(@path) do |sock|
- sock.should be_an_instance_of(Socket)
- end
+ describe 'when a block is given' do
+ it 'yields a Socket' do
+ Socket.unix(@path) do |sock|
+ sock.should be_an_instance_of(Socket)
end
+ end
- it 'closes the Socket when the block returns' do
- socket = nil
-
- Socket.unix(@path) do |sock|
- socket = sock
- end
+ it 'closes the Socket when the block returns' do
+ socket = nil
- socket.should.closed?
+ Socket.unix(@path) do |sock|
+ socket = sock
end
+
+ socket.should.closed?
end
end
end
diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
index 79ec68cd18..935b5cb543 100644
--- a/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
+++ b/spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb
@@ -32,15 +32,13 @@ describe "Socket.unpack_sockaddr_in" do
end
end
- with_feature :unix_socket do
- it "raises an ArgumentError when the sin_family is not AF_INET" do
- sockaddr = Socket.sockaddr_un '/tmp/x'
- -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when the sin_family is not AF_INET" do
+ sockaddr = Socket.sockaddr_un '/tmp/x'
+ -> { Socket.unpack_sockaddr_in sockaddr }.should raise_error(ArgumentError)
+ end
- it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do
- addrinfo = Addrinfo.unix('/tmp/sock')
- -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when passed addrinfo is not AF_INET/AF_INET6" do
+ addrinfo = Addrinfo.unix('/tmp/sock')
+ -> { Socket.unpack_sockaddr_in(addrinfo) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
index 12f970f89b..6e0f11de3d 100644
--- a/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
+++ b/spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb
@@ -1,26 +1,24 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'Socket.unpack_sockaddr_un' do
- it 'decodes sockaddr to unix path' do
- sockaddr = Socket.sockaddr_un('/tmp/sock')
- Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock'
- end
+describe 'Socket.unpack_sockaddr_un' do
+ it 'decodes sockaddr to unix path' do
+ sockaddr = Socket.sockaddr_un('/tmp/sock')
+ Socket.unpack_sockaddr_un(sockaddr).should == '/tmp/sock'
+ end
- it 'returns unix path from a passed Addrinfo' do
- addrinfo = Addrinfo.unix('/tmp/sock')
- Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock'
- end
+ it 'returns unix path from a passed Addrinfo' do
+ addrinfo = Addrinfo.unix('/tmp/sock')
+ Socket.unpack_sockaddr_un(addrinfo).should == '/tmp/sock'
+ end
- it 'raises an ArgumentError when the sa_family is not AF_UNIX' do
- sockaddr = Socket.sockaddr_in(0, '127.0.0.1')
- -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError)
- end
+ it 'raises an ArgumentError when the sa_family is not AF_UNIX' do
+ sockaddr = Socket.sockaddr_in(0, '127.0.0.1')
+ -> { Socket.unpack_sockaddr_un(sockaddr) }.should raise_error(ArgumentError)
+ end
- it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do
- addrinfo = Addrinfo.tcp('127.0.0.1', 0)
- -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError)
- end
+ it 'raises an ArgumentError when passed addrinfo is not AF_UNIX' do
+ addrinfo = Addrinfo.tcp('127.0.0.1', 0)
+ -> { Socket.unpack_sockaddr_un(addrinfo) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb
index 1121542dd5..b33663e02d 100644
--- a/spec/ruby/library/socket/spec_helper.rb
+++ b/spec/ruby/library/socket/spec_helper.rb
@@ -2,7 +2,6 @@ require_relative '../../spec_helper'
require 'socket'
MSpec.enable_feature :sock_packet if Socket.const_defined?(:SOCK_PACKET)
-MSpec.enable_feature :unix_socket unless PlatformGuard.windows?
MSpec.enable_feature :udp_cork if Socket.const_defined?(:UDP_CORK)
MSpec.enable_feature :tcp_cork if Socket.const_defined?(:TCP_CORK)
MSpec.enable_feature :pktinfo if Socket.const_defined?(:IP_PKTINFO)
diff --git a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
index f0e98778f5..5a2c704f35 100644
--- a/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
+++ b/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb
@@ -2,7 +2,7 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
# TODO: verify these for windows
-describe "TCPSocket#gethostbyname" do
+describe "TCPSocket.gethostbyname" do
before :each do
suppress_warning do
@host_info = TCPSocket.gethostbyname(SocketSpecs.hostname)
@@ -52,7 +52,7 @@ describe "TCPSocket#gethostbyname" do
end
end
-describe 'TCPSocket#gethostbyname' do
+describe 'TCPSocket.gethostbyname' do
it 'returns an Array' do
suppress_warning do
TCPSocket.gethostbyname('127.0.0.1').should be_an_instance_of(Array)
diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb
index 90f8d7e6a2..0e405253c8 100644
--- a/spec/ruby/library/socket/tcpsocket/shared/new.rb
+++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb
@@ -14,26 +14,13 @@ describe :tcpsocket_new, shared: true do
}
end
- ruby_version_is ""..."3.2" do
- it 'raises Errno::ETIMEDOUT with :connect_timeout when no server is listening on the given address' do
- -> {
- TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
- }.should raise_error(Errno::ETIMEDOUT)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
- end
-
- ruby_version_is "3.2" do
- it 'raises IO::TimeoutError with :connect_timeout when no server is listening on the given address' do
- -> {
- TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
- }.should raise_error(IO::TimeoutError)
- rescue Errno::ENETUNREACH
- # In the case all network interfaces down.
- # raise_error cannot deal with multiple expected exceptions
- end
+ it 'raises IO::TimeoutError with :connect_timeout when no server is listening on the given address' do
+ -> {
+ TCPSocket.send(@method, "192.0.2.1", 80, connect_timeout: 0)
+ }.should raise_error(IO::TimeoutError)
+ rescue Errno::ENETUNREACH
+ # In the case all network interfaces down.
+ # raise_error cannot deal with multiple expected exceptions
end
describe "with a running server" do
@@ -66,14 +53,23 @@ describe :tcpsocket_new, shared: true do
end
it "connects to a server when passed local_host and local_port arguments" do
- server = TCPServer.new(SocketSpecs.hostname, 0)
+ retries = 0
+ max_retries = 3
+
begin
- available_port = server.addr[1]
- ensure
- server.close
+ retries += 1
+ server = TCPServer.new(SocketSpecs.hostname, 0)
+ begin
+ available_port = server.addr[1]
+ ensure
+ server.close
+ end
+ @socket = TCPSocket.send(@method, @hostname, @server.port,
+ @hostname, available_port)
+ rescue Errno::EADDRINUSE
+ raise if retries >= max_retries
+ retry
end
- @socket = TCPSocket.send(@method, @hostname, @server.port,
- @hostname, available_port)
@socket.should be_an_instance_of(TCPSocket)
end
diff --git a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
index dba3de7359..f67941b296 100644
--- a/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb
@@ -1,87 +1,85 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXServer#accept_nonblock" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @client = UNIXSocket.open(@path)
+describe "UNIXServer#accept_nonblock" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @client = UNIXSocket.open(@path)
- @socket = @server.accept_nonblock
- @client.send("foobar", 0)
- end
+ @socket = @server.accept_nonblock
+ @client.send("foobar", 0)
+ end
- after :each do
- @socket.close
- @client.close
- @server.close
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @socket.close
+ @client.close
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
- it "accepts a connection in a non-blocking way" do
- data = @socket.recvfrom(6).first
- data.should == "foobar"
- end
+ it "accepts a connection in a non-blocking way" do
+ data = @socket.recvfrom(6).first
+ data.should == "foobar"
+ end
- it "returns a UNIXSocket" do
- @socket.should be_kind_of(UNIXSocket)
- end
+ it "returns a UNIXSocket" do
+ @socket.should be_kind_of(UNIXSocket)
+ end
+
+ it 'returns :wait_readable in exceptionless mode' do
+ @server.accept_nonblock(exception: false).should == :wait_readable
+ end
+end
- it 'returns :wait_readable in exceptionless mode' do
- @server.accept_nonblock(exception: false).should == :wait_readable
+describe 'UNIXServer#accept_nonblock' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'raises IO::WaitReadable' do
+ -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
end
end
- describe 'UNIXServer#accept_nonblock' do
+ describe 'with a client' do
before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
end
after do
- @server.close
- rm_r(@path)
+ @client.close
+ @socket.close if @socket
end
- describe 'without a client' do
- it 'raises IO::WaitReadable' do
- -> { @server.accept_nonblock }.should raise_error(IO::WaitReadable)
+ describe 'without any data' do
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept_nonblock
+ @socket.should be_an_instance_of(UNIXSocket)
end
end
- describe 'with a client' do
+ describe 'with data available' do
before do
- @client = UNIXSocket.new(@path)
- end
-
- after do
- @client.close
- @socket.close if @socket
+ @client.write('hello')
end
- describe 'without any data' do
- it 'returns a UNIXSocket' do
- @socket = @server.accept_nonblock
- @socket.should be_an_instance_of(UNIXSocket)
- end
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept_nonblock
+ @socket.should be_an_instance_of(UNIXSocket)
end
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns a UNIXSocket' do
+ describe 'the returned UNIXSocket' do
+ it 'can read the data written' do
@socket = @server.accept_nonblock
- @socket.should be_an_instance_of(UNIXSocket)
- end
-
- describe 'the returned UNIXSocket' do
- it 'can read the data written' do
- @socket = @server.accept_nonblock
- @socket.recv(5).should == 'hello'
- end
+ @socket.recv(5).should == 'hello'
end
end
end
diff --git a/spec/ruby/library/socket/unixserver/accept_spec.rb b/spec/ruby/library/socket/unixserver/accept_spec.rb
index 1305bc6220..cc2c922b6f 100644
--- a/spec/ruby/library/socket/unixserver/accept_spec.rb
+++ b/spec/ruby/library/socket/unixserver/accept_spec.rb
@@ -1,126 +1,124 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXServer#accept" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- end
+describe "UNIXServer#accept" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ end
- after :each do
- @server.close if @server
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @server.close if @server
+ SocketSpecs.rm_socket @path
+ end
- it "accepts what is written by the client" do
- client = UNIXSocket.open(@path)
+ it "accepts what is written by the client" do
+ client = UNIXSocket.open(@path)
- client.send('hello', 0)
+ client.send('hello', 0)
- sock = @server.accept
- begin
- data, info = sock.recvfrom(5)
+ sock = @server.accept
+ begin
+ data, info = sock.recvfrom(5)
- data.should == 'hello'
- info.should_not be_empty
- ensure
- sock.close
- client.close
- end
+ data.should == 'hello'
+ info.should_not be_empty
+ ensure
+ sock.close
+ client.close
end
+ end
- it "can be interrupted by Thread#kill" do
- t = Thread.new {
- @server.accept
- }
- Thread.pass while t.status and t.status != "sleep"
-
- # kill thread, ensure it dies in a reasonable amount of time
- t.kill
- a = 0
- while t.alive? and a < 5000
- sleep 0.001
- a += 1
- end
- a.should < 5000
+ it "can be interrupted by Thread#kill" do
+ t = Thread.new {
+ @server.accept
+ }
+ Thread.pass while t.status and t.status != "sleep"
+
+ # kill thread, ensure it dies in a reasonable amount of time
+ t.kill
+ a = 0
+ while t.alive? and a < 5000
+ sleep 0.001
+ a += 1
end
+ a.should < 5000
+ end
- it "can be interrupted by Thread#raise" do
- t = Thread.new {
- -> {
- @server.accept
- }.should raise_error(Exception, "interrupted")
- }
+ it "can be interrupted by Thread#raise" do
+ t = Thread.new {
+ -> {
+ @server.accept
+ }.should raise_error(Exception, "interrupted")
+ }
- Thread.pass while t.status and t.status != "sleep"
- t.raise Exception, "interrupted"
- t.join
- end
+ Thread.pass while t.status and t.status != "sleep"
+ t.raise Exception, "interrupted"
+ t.join
end
end
-with_feature :unix_socket do
- describe 'UNIXServer#accept' do
+describe 'UNIXServer#accept' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'blocks the calling thread' do
+ -> { @server.accept }.should block_caller
+ end
+ end
+
+ describe 'with a client' do
before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
end
after do
- @server.close
- rm_r(@path)
+ @client.close
+ @socket.close if @socket
end
- describe 'without a client' do
- it 'blocks the calling thread' do
- -> { @server.accept }.should block_caller
+ describe 'without any data' do
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept
+ @socket.should be_an_instance_of(UNIXSocket)
end
end
- describe 'with a client' do
+ describe 'with data available' do
before do
- @client = UNIXSocket.new(@path)
- end
-
- after do
- @client.close
- @socket.close if @socket
+ @client.write('hello')
end
- describe 'without any data' do
- it 'returns a UNIXSocket' do
- @socket = @server.accept
- @socket.should be_an_instance_of(UNIXSocket)
- end
+ it 'returns a UNIXSocket' do
+ @socket = @server.accept
+ @socket.should be_an_instance_of(UNIXSocket)
end
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns a UNIXSocket' do
+ describe 'the returned UNIXSocket' do
+ it 'can read the data written' do
@socket = @server.accept
- @socket.should be_an_instance_of(UNIXSocket)
+ @socket.recv(5).should == 'hello'
end
- describe 'the returned UNIXSocket' do
- it 'can read the data written' do
- @socket = @server.accept
- @socket.recv(5).should == 'hello'
- end
-
+ platform_is_not :windows do
it "is set to nonblocking" do
require 'io/nonblock'
@socket = @server.accept
@socket.should.nonblock?
end
+ end
- it "is set to close on exec" do
- @socket = @server.accept
- @socket.should.close_on_exec?
- end
+ it "is set to close on exec" do
+ @socket = @server.accept
+ @socket.should.close_on_exec?
end
end
end
diff --git a/spec/ruby/library/socket/unixserver/for_fd_spec.rb b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
index 8cc55ef391..be1c2df4d7 100644
--- a/spec/ruby/library/socket/unixserver/for_fd_spec.rb
+++ b/spec/ruby/library/socket/unixserver/for_fd_spec.rb
@@ -1,23 +1,21 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXServer.for_fd" do
- before :each do
- @unix_path = SocketSpecs.socket_path
- @unix = UNIXServer.new(@unix_path)
- end
+describe "UNIXServer.for_fd" do
+ before :each do
+ @unix_path = SocketSpecs.socket_path
+ @unix = UNIXServer.new(@unix_path)
+ end
- after :each do
- @unix.close if @unix
- SocketSpecs.rm_socket @unix_path
- end
+ after :each do
+ @unix.close if @unix
+ SocketSpecs.rm_socket @unix_path
+ end
- it "can calculate the path" do
- b = UNIXServer.for_fd(@unix.fileno)
- b.autoclose = false
+ it "can calculate the path" do
+ b = UNIXServer.for_fd(@unix.fileno)
+ b.autoclose = false
- b.path.should == @unix_path
- end
+ b.path.should == @unix_path
end
end
diff --git a/spec/ruby/library/socket/unixserver/initialize_spec.rb b/spec/ruby/library/socket/unixserver/initialize_spec.rb
index 0cc49ef1eb..3728a307b0 100644
--- a/spec/ruby/library/socket/unixserver/initialize_spec.rb
+++ b/spec/ruby/library/socket/unixserver/initialize_spec.rb
@@ -1,28 +1,26 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXServer#initialize' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- end
+describe 'UNIXServer#initialize' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
- after do
- @server.close if @server
- rm_r @path
- end
+ after do
+ @server.close if @server
+ rm_r @path
+ end
- it 'returns a new UNIXServer' do
- @server.should be_an_instance_of(UNIXServer)
- end
+ it 'returns a new UNIXServer' do
+ @server.should be_an_instance_of(UNIXServer)
+ end
- it 'sets the socket to binmode' do
- @server.binmode?.should be_true
- end
+ it 'sets the socket to binmode' do
+ @server.binmode?.should be_true
+ end
- it 'raises Errno::EADDRINUSE when the socket is already in use' do
- -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE)
- end
+ it 'raises Errno::EADDRINUSE when the socket is already in use' do
+ -> { UNIXServer.new(@path) }.should raise_error(Errno::EADDRINUSE)
end
end
diff --git a/spec/ruby/library/socket/unixserver/listen_spec.rb b/spec/ruby/library/socket/unixserver/listen_spec.rb
index b90b3bbb09..7938d648c4 100644
--- a/spec/ruby/library/socket/unixserver/listen_spec.rb
+++ b/spec/ruby/library/socket/unixserver/listen_spec.rb
@@ -1,21 +1,19 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXServer#listen' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- end
+describe 'UNIXServer#listen' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
- after do
- @server.close
+ after do
+ @server.close
- rm_r(@path)
- end
+ rm_r(@path)
+ end
- it 'returns 0' do
- @server.listen(1).should == 0
- end
+ it 'returns 0' do
+ @server.listen(1).should == 0
end
end
diff --git a/spec/ruby/library/socket/unixserver/new_spec.rb b/spec/ruby/library/socket/unixserver/new_spec.rb
index a160e3ce5c..7d0c7bf76e 100644
--- a/spec/ruby/library/socket/unixserver/new_spec.rb
+++ b/spec/ruby/library/socket/unixserver/new_spec.rb
@@ -1,14 +1,12 @@
require_relative '../spec_helper'
require_relative 'shared/new'
-with_feature :unix_socket do
- describe "UNIXServer.new" do
- it_behaves_like :unixserver_new, :new
+describe "UNIXServer.new" do
+ it_behaves_like :unixserver_new, :new
- it "does not use the given block and warns to use UNIXServer::open" do
- -> {
- @server = UNIXServer.new(@path) { raise }
- }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/)
- end
+ it "does not use the given block and warns to use UNIXServer::open" do
+ -> {
+ @server = UNIXServer.new(@path) { raise }
+ }.should complain(/warning: UNIXServer::new\(\) does not take block; use UNIXServer::open\(\) instead/)
end
end
diff --git a/spec/ruby/library/socket/unixserver/open_spec.rb b/spec/ruby/library/socket/unixserver/open_spec.rb
index 16453dd3bd..c49df802d0 100644
--- a/spec/ruby/library/socket/unixserver/open_spec.rb
+++ b/spec/ruby/library/socket/unixserver/open_spec.rb
@@ -2,25 +2,23 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/new'
-with_feature :unix_socket do
- describe "UNIXServer.open" do
- it_behaves_like :unixserver_new, :open
+describe "UNIXServer.open" do
+ it_behaves_like :unixserver_new, :open
- before :each do
- @path = SocketSpecs.socket_path
- end
+ before :each do
+ @path = SocketSpecs.socket_path
+ end
- after :each do
- @server.close if @server
- @server = nil
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @server.close if @server
+ @server = nil
+ SocketSpecs.rm_socket @path
+ end
- it "yields the new UNIXServer object to the block, if given" do
- UNIXServer.open(@path) do |unix|
- unix.path.should == @path
- unix.addr.should == ["AF_UNIX", @path]
- end
+ it "yields the new UNIXServer object to the block, if given" do
+ UNIXServer.open(@path) do |unix|
+ unix.path.should == @path
+ unix.addr.should == ["AF_UNIX", @path]
end
end
end
diff --git a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
index e59731878a..c4a4ecc824 100644
--- a/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
+++ b/spec/ruby/library/socket/unixserver/sysaccept_spec.rb
@@ -1,51 +1,49 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXServer#sysaccept' do
+describe 'UNIXServer#sysaccept' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ end
+
+ after do
+ @server.close
+
+ rm_r(@path)
+ end
+
+ describe 'without a client' do
+ it 'blocks the calling thread' do
+ -> { @server.sysaccept }.should block_caller
+ end
+ end
+
+ describe 'with a client' do
before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
end
after do
- @server.close
-
- rm_r(@path)
+ Socket.for_fd(@fd).close if @fd
+ @client.close
end
- describe 'without a client' do
- it 'blocks the calling thread' do
- -> { @server.sysaccept }.should block_caller
+ describe 'without any data' do
+ it 'returns an Integer' do
+ @fd = @server.sysaccept
+ @fd.should be_kind_of(Integer)
end
end
- describe 'with a client' do
+ describe 'with data available' do
before do
- @client = UNIXSocket.new(@path)
- end
-
- after do
- Socket.for_fd(@fd).close if @fd
- @client.close
+ @client.write('hello')
end
- describe 'without any data' do
- it 'returns an Integer' do
- @fd = @server.sysaccept
- @fd.should be_kind_of(Integer)
- end
- end
-
- describe 'with data available' do
- before do
- @client.write('hello')
- end
-
- it 'returns an Integer' do
- @fd = @server.sysaccept
- @fd.should be_kind_of(Integer)
- end
+ it 'returns an Integer' do
+ @fd = @server.sysaccept
+ @fd.should be_kind_of(Integer)
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/addr_spec.rb b/spec/ruby/library/socket/unixsocket/addr_spec.rb
index d93e061312..1afe9b12dc 100644
--- a/spec/ruby/library/socket/unixsocket/addr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/addr_spec.rb
@@ -1,35 +1,33 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXSocket#addr" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @client = UNIXSocket.open(@path)
- end
+describe "UNIXSocket#addr" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @client = UNIXSocket.open(@path)
+ end
- after :each do
- @client.close
- @server.close
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @client.close
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
- it "returns an array" do
- @client.addr.should be_kind_of(Array)
- end
+ it "returns an array" do
+ @client.addr.should be_kind_of(Array)
+ end
- it "returns the address family of this socket in an array" do
- @client.addr[0].should == "AF_UNIX"
- @server.addr[0].should == "AF_UNIX"
- end
+ it "returns the address family of this socket in an array" do
+ @client.addr[0].should == "AF_UNIX"
+ @server.addr[0].should == "AF_UNIX"
+ end
- it "returns the path of the socket in an array if it's a server" do
- @server.addr[1].should == @path
- end
+ it "returns the path of the socket in an array if it's a server" do
+ @server.addr[1].should == @path
+ end
- it "returns an empty string for path if it's a client" do
- @client.addr[1].should == ""
- end
+ it "returns an empty string for path if it's a client" do
+ @client.addr[1].should == ""
end
end
diff --git a/spec/ruby/library/socket/unixsocket/initialize_spec.rb b/spec/ruby/library/socket/unixsocket/initialize_spec.rb
index bf7896ab0e..5dccfcc745 100644
--- a/spec/ruby/library/socket/unixsocket/initialize_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/initialize_spec.rb
@@ -1,48 +1,56 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXSocket#initialize' do
- describe 'using a non existing path' do
+describe 'UNIXSocket#initialize' do
+ describe 'using a non existing path' do
+ platform_is_not :windows do
it 'raises Errno::ENOENT' do
-> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ENOENT)
end
end
- describe 'using an existing socket path' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- @socket = UNIXSocket.new(@path)
+ platform_is :windows do
+ # Why, Windows, why?
+ it 'raises Errno::ECONNREFUSED' do
+ -> { UNIXSocket.new(SocketSpecs.socket_path) }.should raise_error(Errno::ECONNREFUSED)
end
+ end
+ end
- after do
- @socket.close
- @server.close
- rm_r(@path)
- end
+ describe 'using an existing socket path' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @socket = UNIXSocket.new(@path)
+ end
- it 'returns a new UNIXSocket' do
- @socket.should be_an_instance_of(UNIXSocket)
- end
+ after do
+ @socket.close
+ @server.close
+ rm_r(@path)
+ end
- it 'sets the socket path to an empty String' do
- @socket.path.should == ''
- end
+ it 'returns a new UNIXSocket' do
+ @socket.should be_an_instance_of(UNIXSocket)
+ end
- it 'sets the socket to binmode' do
- @socket.binmode?.should be_true
- end
+ it 'sets the socket path to an empty String' do
+ @socket.path.should == ''
+ end
+
+ it 'sets the socket to binmode' do
+ @socket.binmode?.should be_true
+ end
+ platform_is_not :windows do
it 'sets the socket to nonblock' do
require 'io/nonblock'
@socket.should.nonblock?
end
+ end
- it 'sets the socket to close on exec' do
- @socket.should.close_on_exec?
- end
-
+ it 'sets the socket to close on exec' do
+ @socket.should.close_on_exec?
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/inspect_spec.rb b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
index a542ba6db5..77bb521069 100644
--- a/spec/ruby/library/socket/unixsocket/inspect_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/inspect_spec.rb
@@ -1,17 +1,15 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXSocket#inspect" do
- it "returns sockets fd for unnamed sockets" do
- begin
- s1, s2 = UNIXSocket.socketpair
- s1.inspect.should == "#<UNIXSocket:fd #{s1.fileno}>"
- s2.inspect.should == "#<UNIXSocket:fd #{s2.fileno}>"
- ensure
- s1.close
- s2.close
- end
+describe "UNIXSocket#inspect" do
+ it "returns sockets fd for unnamed sockets" do
+ begin
+ s1, s2 = UNIXSocket.socketpair
+ s1.inspect.should == "#<UNIXSocket:fd #{s1.fileno}>"
+ s2.inspect.should == "#<UNIXSocket:fd #{s2.fileno}>"
+ ensure
+ s1.close
+ s2.close
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/local_address_spec.rb b/spec/ruby/library/socket/unixsocket/local_address_spec.rb
index 734253e7f5..0fdec38293 100644
--- a/spec/ruby/library/socket/unixsocket/local_address_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/local_address_spec.rb
@@ -1,94 +1,92 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXSocket#local_address' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- @client = UNIXSocket.new(@path)
- end
+describe 'UNIXSocket#local_address' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
+ end
- after do
- @client.close
- @server.close
+ after do
+ @client.close
+ @server.close
- rm_r(@path)
- end
-
- it 'returns an Addrinfo' do
- @client.local_address.should be_an_instance_of(Addrinfo)
- end
+ rm_r(@path)
+ end
- describe 'the returned Addrinfo' do
- platform_is_not :aix do
- it 'uses AF_UNIX as the address family' do
- @client.local_address.afamily.should == Socket::AF_UNIX
- end
+ it 'returns an Addrinfo' do
+ @client.local_address.should be_an_instance_of(Addrinfo)
+ end
- it 'uses PF_UNIX as the protocol family' do
- @client.local_address.pfamily.should == Socket::PF_UNIX
- end
+ describe 'the returned Addrinfo' do
+ platform_is_not :aix do
+ it 'uses AF_UNIX as the address family' do
+ @client.local_address.afamily.should == Socket::AF_UNIX
end
- it 'uses SOCK_STREAM as the socket type' do
- @client.local_address.socktype.should == Socket::SOCK_STREAM
+ it 'uses PF_UNIX as the protocol family' do
+ @client.local_address.pfamily.should == Socket::PF_UNIX
end
+ end
- platform_is_not :aix do
- it 'uses an empty socket path' do
- @client.local_address.unix_path.should == ''
- end
- end
+ it 'uses SOCK_STREAM as the socket type' do
+ @client.local_address.socktype.should == Socket::SOCK_STREAM
+ end
- it 'uses 0 as the protocol' do
- @client.local_address.protocol.should == 0
+ platform_is_not :aix do
+ it 'uses an empty socket path' do
+ @client.local_address.unix_path.should == ''
end
end
- end
- describe 'UNIXSocket#local_address with a UNIX socket pair' do
- before :each do
- @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
+ it 'uses 0 as the protocol' do
+ @client.local_address.protocol.should == 0
end
+ end
+end
- after :each do
- @sock.close
- @sock2.close
- end
+describe 'UNIXSocket#local_address with a UNIX socket pair' do
+ before :each do
+ @sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
+ end
- it 'returns an Addrinfo' do
- @sock.local_address.should be_an_instance_of(Addrinfo)
- end
+ after :each do
+ @sock.close
+ @sock2.close
+ end
- describe 'the returned Addrinfo' do
- it 'uses AF_UNIX as the address family' do
- @sock.local_address.afamily.should == Socket::AF_UNIX
- end
+ it 'returns an Addrinfo' do
+ @sock.local_address.should be_an_instance_of(Addrinfo)
+ end
- it 'uses PF_UNIX as the protocol family' do
- @sock.local_address.pfamily.should == Socket::PF_UNIX
- end
+ describe 'the returned Addrinfo' do
+ it 'uses AF_UNIX as the address family' do
+ @sock.local_address.afamily.should == Socket::AF_UNIX
+ end
- it 'uses SOCK_STREAM as the socket type' do
- @sock.local_address.socktype.should == Socket::SOCK_STREAM
- end
+ it 'uses PF_UNIX as the protocol family' do
+ @sock.local_address.pfamily.should == Socket::PF_UNIX
+ end
- it 'raises SocketError for #ip_address' do
- -> {
- @sock.local_address.ip_address
- }.should raise_error(SocketError, "need IPv4 or IPv6 address")
- end
+ it 'uses SOCK_STREAM as the socket type' do
+ @sock.local_address.socktype.should == Socket::SOCK_STREAM
+ end
- it 'raises SocketError for #ip_port' do
- -> {
- @sock.local_address.ip_port
- }.should raise_error(SocketError, "need IPv4 or IPv6 address")
- end
+ it 'raises SocketError for #ip_address' do
+ -> {
+ @sock.local_address.ip_address
+ }.should raise_error(SocketError, "need IPv4 or IPv6 address")
+ end
- it 'uses 0 as the protocol' do
- @sock.local_address.protocol.should == 0
- end
+ it 'raises SocketError for #ip_port' do
+ -> {
+ @sock.local_address.ip_port
+ }.should raise_error(SocketError, "need IPv4 or IPv6 address")
+ end
+
+ it 'uses 0 as the protocol' do
+ @sock.local_address.protocol.should == 0
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/new_spec.rb b/spec/ruby/library/socket/unixsocket/new_spec.rb
index 6d8ea6dcfe..fea2c1e2b7 100644
--- a/spec/ruby/library/socket/unixsocket/new_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/new_spec.rb
@@ -1,14 +1,12 @@
require_relative '../spec_helper'
require_relative 'shared/new'
-with_feature :unix_socket do
- describe "UNIXSocket.new" do
- it_behaves_like :unixsocket_new, :new
+describe "UNIXSocket.new" do
+ it_behaves_like :unixsocket_new, :new
- it "does not use the given block and warns to use UNIXSocket::open" do
- -> {
- @client = UNIXSocket.new(@path) { raise }
- }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/)
- end
+ it "does not use the given block and warns to use UNIXSocket::open" do
+ -> {
+ @client = UNIXSocket.new(@path) { raise }
+ }.should complain(/warning: UNIXSocket::new\(\) does not take block; use UNIXSocket::open\(\) instead/)
end
end
diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb
index 61def30abb..b5e8c6c23a 100644
--- a/spec/ruby/library/socket/unixsocket/open_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/open_spec.rb
@@ -2,27 +2,25 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/new'
-with_feature :unix_socket do
- describe "UNIXSocket.open" do
- it_behaves_like :unixsocket_new, :open
- end
+describe "UNIXSocket.open" do
+ it_behaves_like :unixsocket_new, :open
+end
- describe "UNIXSocket.open" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- end
+describe "UNIXSocket.open" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ end
- after :each do
- @server.close
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
- it "opens a unix socket on the specified file and yields it to the block" do
- UNIXSocket.open(@path) do |client|
- client.addr[0].should == "AF_UNIX"
- client.should_not.closed?
- end
+ it "opens a unix socket on the specified file and yields it to the block" do
+ UNIXSocket.open(@path) do |client|
+ client.addr[0].should == "AF_UNIX"
+ client.should_not.closed?
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/pair_spec.rb b/spec/ruby/library/socket/unixsocket/pair_spec.rb
index b0a3b2af99..9690142668 100644
--- a/spec/ruby/library/socket/unixsocket/pair_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/pair_spec.rb
@@ -3,18 +3,16 @@ require_relative '../fixtures/classes'
require_relative '../shared/partially_closable_sockets'
require_relative 'shared/pair'
-with_feature :unix_socket do
- describe "UNIXSocket.pair" do
- it_should_behave_like :unixsocket_pair
- it_should_behave_like :partially_closable_sockets
+describe "UNIXSocket.pair" do
+ it_should_behave_like :unixsocket_pair
+ it_should_behave_like :partially_closable_sockets
- before :each do
- @s1, @s2 = UNIXSocket.pair
- end
+ before :each do
+ @s1, @s2 = UNIXSocket.pair
+ end
- after :each do
- @s1.close
- @s2.close
- end
+ after :each do
+ @s1.close
+ @s2.close
end
end
diff --git a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
index ef7d0f0b2a..108a6c3063 100644
--- a/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/partially_closable_spec.rb
@@ -2,22 +2,20 @@ require_relative '../spec_helper'
require_relative '../fixtures/classes'
require_relative '../shared/partially_closable_sockets'
-with_feature :unix_socket do
- describe "UNIXSocket partial closability" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @s1 = UNIXSocket.new(@path)
- @s2 = @server.accept
- end
-
- after :each do
- @server.close
- @s1.close
- @s2.close
- SocketSpecs.rm_socket @path
- end
+describe "UNIXSocket partial closability" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @s1 = UNIXSocket.new(@path)
+ @s2 = @server.accept
+ end
- it_should_behave_like :partially_closable_sockets
+ after :each do
+ @server.close
+ @s1.close
+ @s2.close
+ SocketSpecs.rm_socket @path
end
+
+ it_should_behave_like :partially_closable_sockets
end
diff --git a/spec/ruby/library/socket/unixsocket/path_spec.rb b/spec/ruby/library/socket/unixsocket/path_spec.rb
index a608378e4f..ffe7e4bea2 100644
--- a/spec/ruby/library/socket/unixsocket/path_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/path_spec.rb
@@ -1,26 +1,24 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXSocket#path" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @client = UNIXSocket.open(@path)
- end
+describe "UNIXSocket#path" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @client = UNIXSocket.open(@path)
+ end
- after :each do
- @client.close
- @server.close
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @client.close
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
- it "returns the path of the socket if it's a server" do
- @server.path.should == @path
- end
+ it "returns the path of the socket if it's a server" do
+ @server.path.should == @path
+ end
- it "returns an empty string for path if it's a client" do
- @client.path.should == ""
- end
+ it "returns an empty string for path if it's a client" do
+ @client.path.should == ""
end
end
diff --git a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
index 72bc96b1fe..10cab13b42 100644
--- a/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/peeraddr_spec.rb
@@ -1,28 +1,26 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXSocket#peeraddr" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @client = UNIXSocket.open(@path)
- end
+describe "UNIXSocket#peeraddr" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @client = UNIXSocket.open(@path)
+ end
- after :each do
- @client.close
- @server.close
- SocketSpecs.rm_socket @path
- end
+ after :each do
+ @client.close
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
- it "returns the address family and path of the server end of the connection" do
- @client.peeraddr.should == ["AF_UNIX", @path]
- end
+ it "returns the address family and path of the server end of the connection" do
+ @client.peeraddr.should == ["AF_UNIX", @path]
+ end
- it "raises an error in server sockets" do
- -> {
- @server.peeraddr
- }.should raise_error(Errno::ENOTCONN)
- end
+ it "raises an error in server sockets" do
+ -> {
+ @server.peeraddr
+ }.should raise_error(Errno::ENOTCONN)
end
end
diff --git a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
index 1dbc4538e3..f0b408f309 100644
--- a/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recv_io_spec.rb
@@ -1,7 +1,7 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
+platform_is_not :windows do
describe "UNIXSocket#recv_io" do
before :each do
@path = SocketSpecs.socket_path
diff --git a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
index d849fdc302..9ae3777961 100644
--- a/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/recvfrom_spec.rb
@@ -1,59 +1,105 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe "UNIXSocket#recvfrom" do
- before :each do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.open(@path)
- @client = UNIXSocket.open(@path)
+describe "UNIXSocket#recvfrom" do
+ before :each do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.open(@path)
+ @client = UNIXSocket.open(@path)
+ end
+
+ after :each do
+ @client.close
+ @server.close
+ SocketSpecs.rm_socket @path
+ end
+
+ it "receives len bytes from sock, returning an array containing sent data as first element" do
+ @client.send("foobar", 0)
+ sock = @server.accept
+ sock.recvfrom(6).first.should == "foobar"
+ sock.close
+ end
+
+ context "when called on a server's socket" do
+ platform_is_not :windows do
+ it "returns an array containing basic information on the client as second element" do
+ @client.send("foobar", 0)
+ sock = @server.accept
+ data = sock.recvfrom(6)
+ data.last.should == ["AF_UNIX", ""]
+ sock.close
+ end
end
- after :each do
- @client.close
- @server.close
- SocketSpecs.rm_socket @path
+ guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do
+ it "returns an array containing basic information on the client as second element" do
+ @client.send("foobar", 0)
+ sock = @server.accept
+ data = sock.recvfrom(6)
+ data.last.should == ["AF_UNIX", ""]
+ sock.close
+ end
end
+ end
- it "receives len bytes from sock" do
- @client.send("foobar", 0)
- sock = @server.accept
- sock.recvfrom(6).first.should == "foobar"
- sock.close
+ context "when called on a client's socket" do
+ platform_is :linux do
+ it "returns an array containing server's address as second element" do
+ @client.send("", 0)
+ sock = @server.accept
+ sock.send("barfoo", 0)
+ @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path]
+ sock.close
+ end
end
- it "returns an array with data and information on the sender" do
- @client.send("foobar", 0)
- sock = @server.accept
- data = sock.recvfrom(6)
- data.first.should == "foobar"
- data.last.should == ["AF_UNIX", ""]
- sock.close
+ guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do
+ it "returns an array containing server's address as second element" do
+ @client.send("", 0)
+ sock = @server.accept
+ sock.send("barfoo", 0)
+ # This may not be correct, depends on what underlying recvfrom actually returns.
+ @client.recvfrom(6).last.should == ["AF_UNIX", @server.local_address.unix_path]
+ sock.close
+ end
end
- it "allows an output buffer as third argument" do
- buffer = +''
+ platform_is :darwin do
+ it "returns an array containing basic information on the server as second element" do
+ @client.send("", 0)
+ sock = @server.accept
+ sock.send("barfoo", 0)
+ @client.recvfrom(6).last.should == ["AF_UNIX", ""]
+ sock.close
+ end
+ end
+ end
- @client.send("foobar", 0)
- sock = @server.accept
- message, = sock.recvfrom(6, 0, buffer)
- sock.close
+ it "allows an output buffer as third argument" do
+ buffer = +''
- message.should.equal?(buffer)
- buffer.should == "foobar"
- end
+ @client.send("foobar", 0)
+ sock = @server.accept
+ message, = sock.recvfrom(6, 0, buffer)
+ sock.close
- it "preserves the encoding of the given buffer" do
- buffer = ''.encode(Encoding::ISO_8859_1)
+ message.should.equal?(buffer)
+ buffer.should == "foobar"
+ end
- @client.send("foobar", 0)
- sock = @server.accept
- sock.recvfrom(6, 0, buffer)
- sock.close
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
- buffer.encoding.should == Encoding::ISO_8859_1
- end
+ @client.send("foobar", 0)
+ sock = @server.accept
+ sock.recvfrom(6, 0, buffer)
+ sock.close
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+
+ platform_is_not :windows do
it "uses different message options" do
@client.send("foobar", Socket::MSG_PEEK)
sock = @server.accept
@@ -65,24 +111,34 @@ with_feature :unix_socket do
sock.close
end
end
+end
- describe 'UNIXSocket#recvfrom' do
- describe 'using a socket pair' do
- before do
- @client, @server = UNIXSocket.socketpair
- @client.write('hello')
- end
+describe 'UNIXSocket#recvfrom' do
+ describe 'using a socket pair' do
+ before do
+ @client, @server = UNIXSocket.socketpair
+ @client.write('hello')
+ end
- after do
- @client.close
- @server.close
+ after do
+ @client.close
+ @server.close
+ end
+
+ platform_is_not :windows do
+ it 'returns an Array containing the data and address information' do
+ @server.recvfrom(5).should == ['hello', ['AF_UNIX', '']]
end
+ end
+ guard -> { platform_is :windows and ruby_bug "#21702", ""..."4.2" } do
it 'returns an Array containing the data and address information' do
@server.recvfrom(5).should == ['hello', ['AF_UNIX', '']]
end
end
+ end
+ platform_is_not :windows do
# These specs are taken from the rdoc examples on UNIXSocket#recvfrom.
describe 'using a UNIX socket constructed using UNIXSocket.for_fd' do
before do
diff --git a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
index 0b416254d0..84bdff0a6a 100644
--- a/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/remote_address_spec.rb
@@ -1,45 +1,43 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
- describe 'UNIXSocket#remote_address' do
- before do
- @path = SocketSpecs.socket_path
- @server = UNIXServer.new(@path)
- @client = UNIXSocket.new(@path)
- end
+describe 'UNIXSocket#remote_address' do
+ before do
+ @path = SocketSpecs.socket_path
+ @server = UNIXServer.new(@path)
+ @client = UNIXSocket.new(@path)
+ end
- after do
- @client.close
- @server.close
+ after do
+ @client.close
+ @server.close
- rm_r(@path)
- end
+ rm_r(@path)
+ end
- it 'returns an Addrinfo' do
- @client.remote_address.should be_an_instance_of(Addrinfo)
- end
+ it 'returns an Addrinfo' do
+ @client.remote_address.should be_an_instance_of(Addrinfo)
+ end
- describe 'the returned Addrinfo' do
- it 'uses AF_UNIX as the address family' do
- @client.remote_address.afamily.should == Socket::AF_UNIX
- end
+ describe 'the returned Addrinfo' do
+ it 'uses AF_UNIX as the address family' do
+ @client.remote_address.afamily.should == Socket::AF_UNIX
+ end
- it 'uses PF_UNIX as the protocol family' do
- @client.remote_address.pfamily.should == Socket::PF_UNIX
- end
+ it 'uses PF_UNIX as the protocol family' do
+ @client.remote_address.pfamily.should == Socket::PF_UNIX
+ end
- it 'uses SOCK_STREAM as the socket type' do
- @client.remote_address.socktype.should == Socket::SOCK_STREAM
- end
+ it 'uses SOCK_STREAM as the socket type' do
+ @client.remote_address.socktype.should == Socket::SOCK_STREAM
+ end
- it 'uses the correct socket path' do
- @client.remote_address.unix_path.should == @path
- end
+ it 'uses the correct socket path' do
+ @client.remote_address.unix_path.should == @path
+ end
- it 'uses 0 as the protocol' do
- @client.remote_address.protocol.should == 0
- end
+ it 'uses 0 as the protocol' do
+ @client.remote_address.protocol.should == 0
end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/send_io_spec.rb b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
index 80f3550c6d..52186ec3cf 100644
--- a/spec/ruby/library/socket/unixsocket/send_io_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/send_io_spec.rb
@@ -1,7 +1,7 @@
require_relative '../spec_helper'
require_relative '../fixtures/classes'
-with_feature :unix_socket do
+platform_is_not :windows do
describe "UNIXSocket#send_io" do
before :each do
@path = SocketSpecs.socket_path
diff --git a/spec/ruby/library/socket/unixsocket/shared/pair.rb b/spec/ruby/library/socket/unixsocket/shared/pair.rb
index ade7fc9852..d68ee466bf 100644
--- a/spec/ruby/library/socket/unixsocket/shared/pair.rb
+++ b/spec/ruby/library/socket/unixsocket/shared/pair.rb
@@ -12,18 +12,36 @@ describe :unixsocket_pair, shared: true do
@s2.gets.should == "foo\n"
end
- it "sets the socket paths to empty Strings" do
- @s1.path.should == ""
- @s2.path.should == ""
- end
+ platform_is_not :windows do
+ it "sets the socket paths to empty Strings" do
+ @s1.path.should == ""
+ @s2.path.should == ""
+ end
+
+ it "sets the socket addresses to empty Strings" do
+ @s1.addr.should == ["AF_UNIX", ""]
+ @s2.addr.should == ["AF_UNIX", ""]
+ end
- it "sets the socket addresses to empty Strings" do
- @s1.addr.should == ["AF_UNIX", ""]
- @s2.addr.should == ["AF_UNIX", ""]
+ it "sets the socket peer addresses to empty Strings" do
+ @s1.peeraddr.should == ["AF_UNIX", ""]
+ @s2.peeraddr.should == ["AF_UNIX", ""]
+ end
end
- it "sets the socket peer addresses to empty Strings" do
- @s1.peeraddr.should == ["AF_UNIX", ""]
- @s2.peeraddr.should == ["AF_UNIX", ""]
+ platform_is :windows do
+ it "emulates unnamed sockets with a temporary file with a path" do
+ @s1.addr.should == ["AF_UNIX", @s1.path]
+ @s2.peeraddr.should == ["AF_UNIX", @s1.path]
+ end
+
+ it "sets the peer address of first socket to an empty string" do
+ @s1.peeraddr.should == ["AF_UNIX", ""]
+ end
+
+ it "sets the address and path of second socket to an empty string" do
+ @s2.addr.should == ["AF_UNIX", ""]
+ @s2.path.should == ""
+ end
end
end
diff --git a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
index 5f34008df3..c61fc00be4 100644
--- a/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
+++ b/spec/ruby/library/socket/unixsocket/socketpair_spec.rb
@@ -3,18 +3,16 @@ require_relative '../fixtures/classes'
require_relative '../shared/partially_closable_sockets'
require_relative 'shared/pair'
-with_feature :unix_socket do
- describe "UNIXSocket.socketpair" do
- it_should_behave_like :unixsocket_pair
- it_should_behave_like :partially_closable_sockets
+describe "UNIXSocket.socketpair" do
+ it_should_behave_like :unixsocket_pair
+ it_should_behave_like :partially_closable_sockets
- before :each do
- @s1, @s2 = UNIXSocket.socketpair
- end
+ before :each do
+ @s1, @s2 = UNIXSocket.socketpair
+ end
- after :each do
- @s1.close
- @s2.close
- end
+ after :each do
+ @s1.close
+ @s2.close
end
end
diff --git a/spec/ruby/library/stringio/each_line_spec.rb b/spec/ruby/library/stringio/each_line_spec.rb
index c68f7dae82..4ac0db7c45 100644
--- a/spec/ruby/library/stringio/each_line_spec.rb
+++ b/spec/ruby/library/stringio/each_line_spec.rb
@@ -21,3 +21,7 @@ end
describe "StringIO#each_line when passed limit" do
it_behaves_like :stringio_each_limit, :each_line
end
+
+describe "StringIO#each when passed separator and limit" do
+ it_behaves_like :stringio_each_separator_and_limit, :each_line
+end
diff --git a/spec/ruby/library/stringio/each_spec.rb b/spec/ruby/library/stringio/each_spec.rb
index 2c30ed5cda..7eb322f3ff 100644
--- a/spec/ruby/library/stringio/each_spec.rb
+++ b/spec/ruby/library/stringio/each_spec.rb
@@ -25,3 +25,7 @@ end
describe "StringIO#each when passed limit" do
it_behaves_like :stringio_each_limit, :each
end
+
+describe "StringIO#each when passed separator and limit" do
+ it_behaves_like :stringio_each_separator_and_limit, :each
+end
diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb
index eea03a5af3..5a9f440a0f 100644
--- a/spec/ruby/library/stringio/fileno_spec.rb
+++ b/spec/ruby/library/stringio/fileno_spec.rb
@@ -1,6 +1,5 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/classes'
-require_relative 'shared/each'
+require 'stringio'
describe "StringIO#fileno" do
it "returns nil" do
diff --git a/spec/ruby/library/stringio/gets_spec.rb b/spec/ruby/library/stringio/gets_spec.rb
index 4af7704a41..ac876f0b4f 100644
--- a/spec/ruby/library/stringio/gets_spec.rb
+++ b/spec/ruby/library/stringio/gets_spec.rb
@@ -1,250 +1,61 @@
require_relative '../../spec_helper'
require "stringio"
+require_relative "shared/gets"
-describe "StringIO#gets when passed [separator]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read till the next occurrence of the passed separator" do
- @io.gets(">").should == "this>"
- @io.gets(">").should == "is>"
- @io.gets(">").should == "an>"
- @io.gets(">").should == "example"
- end
-
- it "sets $_ to the read content" do
- @io.gets(">")
- $_.should == "this>"
- @io.gets(">")
- $_.should == "is>"
- @io.gets(">")
- $_.should == "an>"
- @io.gets(">")
- $_.should == "example"
- @io.gets(">")
- $_.should be_nil
- end
-
- it "accepts string as separator" do
- @io.gets("is>")
- $_.should == "this>"
- @io.gets("an>")
- $_.should == "is>an>"
- @io.gets("example")
- $_.should == "example"
- @io.gets("ple")
- $_.should be_nil
- end
-
- it "updates self's lineno by one" do
- @io.gets(">")
- @io.lineno.should eql(1)
-
- @io.gets(">")
- @io.lineno.should eql(2)
-
- @io.gets(">")
- @io.lineno.should eql(3)
- end
-
- it "returns the next paragraph when the passed separator is an empty String" do
- io = StringIO.new("this is\n\nan example")
- io.gets("").should == "this is\n\n"
- io.gets("").should == "an example"
- end
-
- it "returns the remaining content starting at the current position when passed nil" do
- io = StringIO.new("this is\n\nan example")
- io.pos = 5
- io.gets(nil).should == "is\n\nan example"
- end
+describe "StringIO#gets" do
+ describe "when passed [separator]" do
+ it_behaves_like :stringio_gets_separator, :gets
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return(">")
- @io.gets(obj).should == "this>"
- end
-end
-
-describe "StringIO#gets when passed no argument" do
- before :each do
- @io = StringIO.new("this is\nan example\nfor StringIO#gets")
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "returns the data read till the next occurrence of $/ or till eof" do
- @io.gets.should == "this is\n"
-
- begin
- old_sep = $/
- suppress_warning {$/ = " "}
- @io.gets.should == "an "
- @io.gets.should == "example\nfor "
- @io.gets.should == "StringIO#gets"
- ensure
- suppress_warning {$/ = old_sep}
+ @io.pos = 36
+ @io.gets(">").should be_nil
+ @io.gets(">").should be_nil
end
end
- it "sets $_ to the read content" do
- @io.gets
- $_.should == "this is\n"
- @io.gets
- $_.should == "an example\n"
- @io.gets
- $_.should == "for StringIO#gets"
- @io.gets
- $_.should be_nil
- end
-
- it "updates self's position" do
- @io.gets
- @io.pos.should eql(8)
-
- @io.gets
- @io.pos.should eql(19)
-
- @io.gets
- @io.pos.should eql(36)
- end
-
- it "updates self's lineno" do
- @io.gets
- @io.lineno.should eql(1)
-
- @io.gets
- @io.lineno.should eql(2)
-
- @io.gets
- @io.lineno.should eql(3)
- end
-
- it "returns nil if self is at the end" do
- @io.pos = 36
- @io.gets.should be_nil
- @io.gets.should be_nil
- end
-end
-
-describe "StringIO#gets when passed [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read until the limit is met" do
- @io.gets(4).should == "this"
- @io.gets(3).should == ">is"
- @io.gets(5).should == ">an>e"
- @io.gets(6).should == "xample"
- end
-
- it "sets $_ to the read content" do
- @io.gets(4)
- $_.should == "this"
- @io.gets(3)
- $_.should == ">is"
- @io.gets(5)
- $_.should == ">an>e"
- @io.gets(6)
- $_.should == "xample"
- @io.gets(3)
- $_.should be_nil
- end
-
- it "updates self's lineno by one" do
- @io.gets(3)
- @io.lineno.should eql(1)
-
- @io.gets(3)
- @io.lineno.should eql(2)
-
- @io.gets(3)
- @io.lineno.should eql(3)
- end
-
- it "tries to convert the passed limit to an Integer using #to_int" do
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(4)
- @io.gets(obj).should == "this"
- end
-
- it "returns a blank string when passed a limit of 0" do
- @io.gets(0).should == ""
- end
-
- it "ignores it when passed a negative limit" do
- @io.gets(-4).should == "this>is>an>example"
- end
-end
+ describe "when passed [limit]" do
+ it_behaves_like :stringio_gets_limit, :gets
-describe "StringIO#gets when passed [separator] and [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read until the limit is consumed or the separator is met" do
- @io.gets('>', 8).should == "this>"
- @io.gets('>', 2).should == "is"
- @io.gets('>', 10).should == ">"
- @io.gets('>', 6).should == "an>"
- @io.gets('>', 5).should == "examp"
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "sets $_ to the read content" do
- @io.gets('>', 8)
- $_.should == "this>"
- @io.gets('>', 2)
- $_.should == "is"
- @io.gets('>', 10)
- $_.should == ">"
- @io.gets('>', 6)
- $_.should == "an>"
- @io.gets('>', 5)
- $_.should == "examp"
+ @io.pos = 36
+ @io.gets(3).should be_nil
+ @io.gets(3).should be_nil
+ end
end
- it "updates self's lineno by one" do
- @io.gets('>', 3)
- @io.lineno.should eql(1)
+ describe "when passed [separator] and [limit]" do
+ it_behaves_like :stringio_gets_separator_and_limit, :gets
- @io.gets('>', 3)
- @io.lineno.should eql(2)
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.gets('>', 3)
- @io.lineno.should eql(3)
+ @io.pos = 36
+ @io.gets(">", 3).should be_nil
+ @io.gets(">", 3).should be_nil
+ end
end
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return('>')
- @io.gets(obj, 5).should == "this>"
- end
+ describe "when passed no argument" do
+ it_behaves_like :stringio_gets_no_argument, :gets
- it "does not raise TypeError if passed separator is nil" do
- @io.gets(nil, 5).should == "this>"
- end
+ it "returns nil if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "tries to convert the passed limit to an Integer using #to_int" do
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- @io.gets('>', obj).should == "this>"
+ @io.pos = 36
+ @io.gets.should be_nil
+ @io.gets.should be_nil
+ end
end
-end
-
-describe "StringIO#gets when in write-only mode" do
- it "raises an IOError" do
- io = StringIO.new(+"xyz", "w")
- -> { io.gets }.should raise_error(IOError)
- io = StringIO.new("xyz")
- io.close_read
- -> { io.gets }.should raise_error(IOError)
+ describe "when passed [chomp]" do
+ it_behaves_like :stringio_gets_chomp, :gets
end
-end
-describe "StringIO#gets when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.gets(chomp: true).should == "this>is>an>example"
+ describe "when in write-only mode" do
+ it_behaves_like :stringio_gets_write_only, :gets
end
end
diff --git a/spec/ruby/library/stringio/readline_spec.rb b/spec/ruby/library/stringio/readline_spec.rb
index b16a16e23f..085360707f 100644
--- a/spec/ruby/library/stringio/readline_spec.rb
+++ b/spec/ruby/library/stringio/readline_spec.rb
@@ -1,150 +1,58 @@
require_relative '../../spec_helper'
+require "stringio"
require_relative 'fixtures/classes'
+require_relative "shared/gets"
+describe "StringIO#readline" do
+ describe "when passed [separator]" do
+ it_behaves_like :stringio_gets_separator, :readline
-describe "StringIO#readline when passed [separator]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
-
- it "returns the data read till the next occurrence of the passed separator" do
- @io.readline(">").should == "this>"
- @io.readline(">").should == "is>"
- @io.readline(">").should == "an>"
- @io.readline(">").should == "example"
- end
-
- it "sets $_ to the read content" do
- @io.readline(">")
- $_.should == "this>"
- @io.readline(">")
- $_.should == "is>"
- @io.readline(">")
- $_.should == "an>"
- @io.readline(">")
- $_.should == "example"
- end
-
- it "updates self's lineno by one" do
- @io.readline(">")
- @io.lineno.should eql(1)
-
- @io.readline(">")
- @io.lineno.should eql(2)
-
- @io.readline(">")
- @io.lineno.should eql(3)
- end
-
- it "returns the next paragraph when the passed separator is an empty String" do
- io = StringIO.new("this is\n\nan example")
- io.readline("").should == "this is\n\n"
- io.readline("").should == "an example"
- end
-
- it "returns the remaining content starting at the current position when passed nil" do
- io = StringIO.new("this is\n\nan example")
- io.pos = 5
- io.readline(nil).should == "is\n\nan example"
- end
-
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return(">")
- @io.readline(obj).should == "this>"
- end
-end
-
-describe "StringIO#readline when passed no argument" do
- before :each do
- @io = StringIO.new("this is\nan example\nfor StringIO#readline")
- end
-
- it "returns the data read till the next occurrence of $/ or till eof" do
- @io.readline.should == "this is\n"
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- begin
- old_sep = $/
- suppress_warning {$/ = " "}
- @io.readline.should == "an "
- @io.readline.should == "example\nfor "
- @io.readline.should == "StringIO#readline"
- ensure
- suppress_warning {$/ = old_sep}
+ @io.pos = 36
+ -> { @io.readline(">") }.should raise_error(IOError)
end
end
- it "sets $_ to the read content" do
- @io.readline
- $_.should == "this is\n"
- @io.readline
- $_.should == "an example\n"
- @io.readline
- $_.should == "for StringIO#readline"
- end
+ describe "when passed [limit]" do
+ it_behaves_like :stringio_gets_limit, :readline
- it "updates self's position" do
- @io.readline
- @io.pos.should eql(8)
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.readline
- @io.pos.should eql(19)
-
- @io.readline
- @io.pos.should eql(40)
+ @io.pos = 36
+ -> { @io.readline(3) }.should raise_error(IOError)
+ end
end
- it "updates self's lineno" do
- @io.readline
- @io.lineno.should eql(1)
+ describe "when passed [separator] and [limit]" do
+ it_behaves_like :stringio_gets_separator_and_limit, :readline
- @io.readline
- @io.lineno.should eql(2)
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- @io.readline
- @io.lineno.should eql(3)
- end
-
- it "raises an IOError if self is at the end" do
- @io.pos = 40
- -> { @io.readline }.should raise_error(IOError)
- end
-end
-
-describe "StringIO#readline when in write-only mode" do
- it "raises an IOError" do
- io = StringIO.new(+"xyz", "w")
- -> { io.readline }.should raise_error(IOError)
-
- io = StringIO.new("xyz")
- io.close_read
- -> { io.readline }.should raise_error(IOError)
+ @io.pos = 36
+ -> { @io.readline(">", 3) }.should raise_error(IOError)
+ end
end
-end
-describe "StringIO#readline when passed [chomp]" do
- it "returns the data read without a trailing newline character" do
- io = StringIO.new("this>is>an>example\n")
- io.readline(chomp: true).should == "this>is>an>example"
- end
-end
+ describe "when passed no argument" do
+ it_behaves_like :stringio_gets_no_argument, :readline
-describe "StringIO#readline when passed [limit]" do
- before :each do
- @io = StringIO.new("this>is>an>example")
- end
+ it "raises an IOError if self is at the end" do
+ @io = StringIO.new("this>is>an>example")
- it "returns the data read until the limit is met" do
- io = StringIO.new("this>is>an>example\n")
- io.readline(3).should == "thi"
+ @io.pos = 36
+ -> { @io.readline }.should raise_error(IOError)
+ end
end
- it "returns a blank string when passed a limit of 0" do
- @io.readline(0).should == ""
+ describe "when passed [chomp]" do
+ it_behaves_like :stringio_gets_chomp, :readline
end
- it "ignores it when the limit is negative" do
- seen = []
- @io.readline(-4).should == "this>is>an>example"
+ describe "when in write-only mode" do
+ it_behaves_like :stringio_gets_write_only, :readline
end
end
diff --git a/spec/ruby/library/stringio/readpartial_spec.rb b/spec/ruby/library/stringio/readpartial_spec.rb
index f25cef4014..dadefb7837 100644
--- a/spec/ruby/library/stringio/readpartial_spec.rb
+++ b/spec/ruby/library/stringio/readpartial_spec.rb
@@ -10,13 +10,7 @@ describe "StringIO#readpartial" do
@string.close unless @string.closed?
end
- it "raises IOError on closed stream" do
- @string.close
- -> { @string.readpartial(10) }.should raise_error(IOError)
- end
-
it "reads at most the specified number of bytes" do
-
# buffered read
@string.read(1).should == 'S'
# return only specified number, not the whole buffer
@@ -30,6 +24,14 @@ describe "StringIO#readpartial" do
@string.readpartial(3).should == ", l"
end
+ it "reads after ungetc with multibyte characters in the buffer" do
+ @string = StringIO.new(+"∂φ/∂x = gaîté")
+ c = @string.getc
+ @string.ungetc(c)
+ @string.readpartial(3).should == "\xE2\x88\x82".b
+ @string.readpartial(3).should == "\xCF\x86/".b
+ end
+
it "reads after ungetc without data in the buffer" do
@string = StringIO.new
@string.write("f").should == 1
@@ -67,14 +69,34 @@ describe "StringIO#readpartial" do
it "raises IOError if the stream is closed" do
@string.close
- -> { @string.readpartial(1) }.should raise_error(IOError)
+ -> { @string.readpartial(1) }.should raise_error(IOError, "not opened for reading")
end
it "raises ArgumentError if the negative argument is provided" do
- -> { @string.readpartial(-1) }.should raise_error(ArgumentError)
+ -> { @string.readpartial(-1) }.should raise_error(ArgumentError, "negative length -1 given")
end
it "immediately returns an empty string if the length argument is 0" do
@string.readpartial(0).should == ""
end
+
+ it "raises IOError if the stream is closed and the length argument is 0" do
+ @string.close
+ -> { @string.readpartial(0) }.should raise_error(IOError, "not opened for reading")
+ end
+
+ it "clears and returns the given buffer if the length argument is 0" do
+ buffer = +"existing content"
+ @string.readpartial(0, buffer).should == buffer
+ buffer.should == ""
+ end
+
+ version_is StringIO::VERSION, "3.1.2" do # ruby_version_is "3.4"
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @string.readpartial(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+ end
end
diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb
index e0dd3f9b8f..626b41a4d3 100644
--- a/spec/ruby/library/stringio/shared/each.rb
+++ b/spec/ruby/library/stringio/shared/each.rb
@@ -36,22 +36,11 @@ describe :stringio_each_separator, shared: true do
seen.should == ["2 1 2 1 2"]
end
- version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do
- it "yields each paragraph with two separation characters when passed an empty String as separator" do
- seen = []
- io = StringIO.new("para1\n\npara2\n\n\npara3")
- io.send(@method, "") {|s| seen << s}
- seen.should == ["para1\n\n", "para2\n\n", "para3"]
- end
- end
-
- version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do
- it "yields each paragraph with all separation characters when passed an empty String as separator" do
- seen = []
- io = StringIO.new("para1\n\npara2\n\n\npara3")
- io.send(@method, "") {|s| seen << s}
- seen.should == ["para1\n\n", "para2\n\n\n", "para3"]
- end
+ it "yields each paragraph with all separation characters when passed an empty String as separator" do
+ seen = []
+ io = StringIO.new("para1\n\npara2\n\n\npara3")
+ io.send(@method, "") {|s| seen << s}
+ seen.should == ["para1\n\n", "para2\n\n\n", "para3"]
end
end
@@ -161,3 +150,60 @@ describe :stringio_each_limit, shared: true do
seen.should == ["a b ", "c d ", "e\n", "1 2 ", "3 4 ", "5"]
end
end
+
+describe :stringio_each_separator_and_limit, shared: true do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is consumed or the separator is met" do
+ @io.send(@method, '>', 8) { |s| break s }.should == "this>"
+ @io.send(@method, '>', 2) { |s| break s }.should == "is"
+ @io.send(@method, '>', 10) { |s| break s }.should == ">"
+ @io.send(@method, '>', 6) { |s| break s }.should == "an>"
+ @io.send(@method, '>', 5) { |s| break s }.should == "examp"
+ end
+
+ it "truncates the multi-character separator at the end to meet the limit" do
+ @io.send(@method, "is>an", 7) { |s| break s }.should == "this>is"
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @io.send(@method, '>', 8) { |s| s }
+ $_.should == "test"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should eql(1)
+
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should eql(2)
+
+ @io.send(@method, '>', 3) { |s| break s }
+ @io.lineno.should eql(3)
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do # TODO
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return('>')
+
+ seen = []
+ @io.send(@method, obj, 5) { |s| seen << s }
+ seen.should == ["this>", "is>", "an>", "examp", "le"]
+ end
+
+ it "does not raise TypeError if passed separator is nil" do
+ @io.send(@method, nil, 5) { |s| break s }.should == "this>"
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do # TODO
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(5)
+
+ seen = []
+ @io.send(@method, '>', obj) { |s| seen << s }
+ seen.should == ["this>", "is>", "an>", "examp", "le"]
+ end
+end
diff --git a/spec/ruby/library/stringio/shared/gets.rb b/spec/ruby/library/stringio/shared/gets.rb
new file mode 100644
index 0000000000..8396b161f1
--- /dev/null
+++ b/spec/ruby/library/stringio/shared/gets.rb
@@ -0,0 +1,249 @@
+describe :stringio_gets_separator, shared: true do
+ describe "when passed [separator]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read till the next occurrence of the passed separator" do
+ @io.send(@method, ">").should == "this>"
+ @io.send(@method, ">").should == "is>"
+ @io.send(@method, ">").should == "an>"
+ @io.send(@method, ">").should == "example"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, ">")
+ $_.should == "this>"
+ @io.send(@method, ">")
+ $_.should == "is>"
+ @io.send(@method, ">")
+ $_.should == "an>"
+ @io.send(@method, ">")
+ $_.should == "example"
+ end
+
+ it "accepts string as separator" do
+ @io.send(@method, "is>")
+ $_.should == "this>"
+ @io.send(@method, "an>")
+ $_.should == "is>an>"
+ @io.send(@method, "example")
+ $_.should == "example"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, ">")
+ @io.lineno.should eql(1)
+
+ @io.send(@method, ">")
+ @io.lineno.should eql(2)
+
+ @io.send(@method, ">")
+ @io.lineno.should eql(3)
+ end
+
+ it "returns the next paragraph when the passed separator is an empty String" do
+ io = StringIO.new("this is\n\nan example")
+ io.send(@method, "").should == "this is\n\n"
+ io.send(@method, "").should == "an example"
+ end
+
+ it "returns the remaining content starting at the current position when passed nil" do
+ io = StringIO.new("this is\n\nan example")
+ io.pos = 5
+ io.send(@method, nil).should == "is\n\nan example"
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return(">")
+ @io.send(@method, obj).should == "this>"
+ end
+ end
+end
+
+describe :stringio_gets_limit, shared: true do
+ describe "when passed [limit]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is met" do
+ @io.send(@method, 4).should == "this"
+ @io.send(@method, 3).should == ">is"
+ @io.send(@method, 5).should == ">an>e"
+ @io.send(@method, 6).should == "xample"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, 4)
+ $_.should == "this"
+ @io.send(@method, 3)
+ $_.should == ">is"
+ @io.send(@method, 5)
+ $_.should == ">an>e"
+ @io.send(@method, 6)
+ $_.should == "xample"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, 3)
+ @io.lineno.should eql(1)
+
+ @io.send(@method, 3)
+ @io.lineno.should eql(2)
+
+ @io.send(@method, 3)
+ @io.lineno.should eql(3)
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(4)
+ @io.send(@method, obj).should == "this"
+ end
+
+ it "returns a blank string when passed a limit of 0" do
+ @io.send(@method, 0).should == ""
+ end
+
+ it "ignores it when passed a negative limit" do
+ @io.send(@method, -4).should == "this>is>an>example"
+ end
+ end
+end
+
+describe :stringio_gets_separator_and_limit, shared: true do
+ describe "when passed [separator] and [limit]" do
+ before :each do
+ @io = StringIO.new("this>is>an>example")
+ end
+
+ it "returns the data read until the limit is consumed or the separator is met" do
+ @io.send(@method, '>', 8).should == "this>"
+ @io.send(@method, '>', 2).should == "is"
+ @io.send(@method, '>', 10).should == ">"
+ @io.send(@method, '>', 6).should == "an>"
+ @io.send(@method, '>', 5).should == "examp"
+ end
+
+ it "truncates the multi-character separator at the end to meet the limit" do
+ @io.send(@method, "is>an", 7).should == "this>is"
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method, '>', 8)
+ $_.should == "this>"
+ @io.send(@method, '>', 2)
+ $_.should == "is"
+ @io.send(@method, '>', 10)
+ $_.should == ">"
+ @io.send(@method, '>', 6)
+ $_.should == "an>"
+ @io.send(@method, '>', 5)
+ $_.should == "examp"
+ end
+
+ it "updates self's lineno by one" do
+ @io.send(@method, '>', 3)
+ @io.lineno.should eql(1)
+
+ @io.send(@method, '>', 3)
+ @io.lineno.should eql(2)
+
+ @io.send(@method, '>', 3)
+ @io.lineno.should eql(3)
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock('to_str')
+ obj.should_receive(:to_str).and_return('>')
+ @io.send(@method, obj, 5).should == "this>"
+ end
+
+ it "does not raise TypeError if passed separator is nil" do
+ @io.send(@method, nil, 5).should == "this>"
+ end
+
+ it "tries to convert the passed limit to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(5)
+ @io.send(@method, '>', obj).should == "this>"
+ end
+ end
+end
+
+describe :stringio_gets_no_argument, shared: true do
+ describe "when passed no argument" do
+ before :each do
+ @io = StringIO.new("this is\nan example\nfor StringIO#gets")
+ end
+
+ it "returns the data read till the next occurrence of $/ or till eof" do
+ @io.send(@method).should == "this is\n"
+
+ begin
+ old_sep = $/
+ suppress_warning {$/ = " "}
+ @io.send(@method).should == "an "
+ @io.send(@method).should == "example\nfor "
+ @io.send(@method).should == "StringIO#gets"
+ ensure
+ suppress_warning {$/ = old_sep}
+ end
+ end
+
+ it "sets $_ to the read content" do
+ @io.send(@method)
+ $_.should == "this is\n"
+ @io.send(@method)
+ $_.should == "an example\n"
+ @io.send(@method)
+ $_.should == "for StringIO#gets"
+ end
+
+ it "updates self's position" do
+ @io.send(@method)
+ @io.pos.should eql(8)
+
+ @io.send(@method)
+ @io.pos.should eql(19)
+
+ @io.send(@method)
+ @io.pos.should eql(36)
+ end
+
+ it "updates self's lineno" do
+ @io.send(@method)
+ @io.lineno.should eql(1)
+
+ @io.send(@method)
+ @io.lineno.should eql(2)
+
+ @io.send(@method)
+ @io.lineno.should eql(3)
+ end
+ end
+end
+
+describe :stringio_gets_chomp, shared: true do
+ describe "when passed [chomp]" do
+ it "returns the data read without a trailing newline character" do
+ io = StringIO.new("this>is>an>example\n")
+ io.send(@method, chomp: true).should == "this>is>an>example"
+ end
+ end
+end
+
+describe :stringio_gets_write_only, shared: true do
+ describe "when in write-only mode" do
+ it "raises an IOError" do
+ io = StringIO.new(+"xyz", "w")
+ -> { io.send(@method) }.should raise_error(IOError)
+
+ io = StringIO.new("xyz")
+ io.close_read
+ -> { io.send(@method) }.should raise_error(IOError)
+ end
+ end
+end
diff --git a/spec/ruby/library/stringscanner/check_spec.rb b/spec/ruby/library/stringscanner/check_spec.rb
index 235f2f22e9..5e855e154a 100644
--- a/spec/ruby/library/stringscanner/check_spec.rb
+++ b/spec/ruby/library/stringscanner/check_spec.rb
@@ -39,7 +39,6 @@ describe "StringScanner#check" do
context "when #check was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.check("This")
@@ -47,7 +46,6 @@ describe "StringScanner#check" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "raises IndexError when matching succeeded" do
@s.check("This")
@@ -68,7 +66,6 @@ describe "StringScanner#check" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
@@ -80,7 +77,6 @@ describe "StringScanner#check" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
diff --git a/spec/ruby/library/stringscanner/check_until_spec.rb b/spec/ruby/library/stringscanner/check_until_spec.rb
index 701a703ebe..582da66b37 100644
--- a/spec/ruby/library/stringscanner/check_until_spec.rb
+++ b/spec/ruby/library/stringscanner/check_until_spec.rb
@@ -35,7 +35,6 @@ describe "StringScanner#check_until" do
end
# https://github.com/ruby/strscan/issues/131
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1"
it "sets the last match result if given a String" do
@s.check_until("a")
@@ -45,7 +44,6 @@ describe "StringScanner#check_until" do
@s.post_match.should == " test"
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "sets the last match result if given a String" do
@@ -76,7 +74,6 @@ describe "StringScanner#check_until" do
version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
context "when #check_until was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.check_until("This")
@@ -84,7 +81,6 @@ describe "StringScanner#check_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
@s.check_until("This")
@@ -105,7 +101,6 @@ describe "StringScanner#check_until" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
@@ -117,7 +112,6 @@ describe "StringScanner#check_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
diff --git a/spec/ruby/library/stringscanner/clear_spec.rb b/spec/ruby/library/stringscanner/clear_spec.rb
deleted file mode 100644
index 7ae089704a..0000000000
--- a/spec/ruby/library/stringscanner/clear_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/terminate'
-require 'strscan'
-
-describe "StringScanner#clear" do
- it_behaves_like :strscan_terminate, :clear
-
- it "warns in verbose mode that the method is obsolete" do
- s = StringScanner.new("abc")
- -> {
- s.clear
- }.should complain(/clear.*obsolete.*terminate/, verbose: true)
-
- -> {
- s.clear
- }.should_not complain(verbose: false)
- end
-end
diff --git a/spec/ruby/library/stringscanner/empty_spec.rb b/spec/ruby/library/stringscanner/empty_spec.rb
deleted file mode 100644
index d9449bea6e..0000000000
--- a/spec/ruby/library/stringscanner/empty_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/eos'
-require 'strscan'
-
-describe "StringScanner#empty?" do
- it_behaves_like :strscan_eos, :empty?
-
- it "warns in verbose mode that the method is obsolete" do
- s = StringScanner.new("abc")
- -> {
- s.empty?
- }.should complain(/empty?.*obsolete.*eos?/, verbose: true)
-
- -> {
- s.empty?
- }.should_not complain(verbose: false)
- end
-end
diff --git a/spec/ruby/library/stringscanner/eos_spec.rb b/spec/ruby/library/stringscanner/eos_spec.rb
index b58ee1e473..03c2804e5b 100644
--- a/spec/ruby/library/stringscanner/eos_spec.rb
+++ b/spec/ruby/library/stringscanner/eos_spec.rb
@@ -1,7 +1,20 @@
require_relative '../../spec_helper'
-require_relative 'shared/eos'
require 'strscan'
describe "StringScanner#eos?" do
- it_behaves_like :strscan_eos, :eos?
+ before :each do
+ @s = StringScanner.new("This is a test")
+ end
+
+ it "returns true if the scan pointer is at the end of the string" do
+ @s.terminate
+ @s.should.eos?
+
+ s = StringScanner.new('')
+ s.should.eos?
+ end
+
+ it "returns false if the scan pointer is not at the end of the string" do
+ @s.should_not.eos?
+ end
end
diff --git a/spec/ruby/library/stringscanner/exist_spec.rb b/spec/ruby/library/stringscanner/exist_spec.rb
index 3f40c7a5a5..a408fd0b8d 100644
--- a/spec/ruby/library/stringscanner/exist_spec.rb
+++ b/spec/ruby/library/stringscanner/exist_spec.rb
@@ -64,7 +64,6 @@ describe "StringScanner#exist?" do
version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
context "when #exist? was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.exist?("This")
@@ -72,7 +71,6 @@ describe "StringScanner#exist?" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
@s.exist?("This")
@@ -93,7 +91,6 @@ describe "StringScanner#exist?" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
@@ -105,7 +102,6 @@ describe "StringScanner#exist?" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
diff --git a/spec/ruby/library/stringscanner/get_byte_spec.rb b/spec/ruby/library/stringscanner/get_byte_spec.rb
index 29e2f557de..144859abc9 100644
--- a/spec/ruby/library/stringscanner/get_byte_spec.rb
+++ b/spec/ruby/library/stringscanner/get_byte_spec.rb
@@ -1,7 +1,84 @@
+# encoding: binary
require_relative '../../spec_helper'
-require_relative 'shared/get_byte'
require 'strscan'
describe "StringScanner#get_byte" do
- it_behaves_like :strscan_get_byte, :get_byte
+ it "scans one byte and returns it" do
+ s = StringScanner.new('abc5.')
+ s.get_byte.should == 'a'
+ s.get_byte.should == 'b'
+ s.get_byte.should == 'c'
+ s.get_byte.should == '5'
+ s.get_byte.should == '.'
+ end
+
+ it "is not multi-byte character sensitive" do
+ s = StringScanner.new("\244\242")
+ s.get_byte.should == "\244"
+ s.get_byte.should == "\242"
+ end
+
+ it "returns nil at the end of the string" do
+ # empty string case
+ s = StringScanner.new('')
+ s.get_byte.should == nil
+ s.get_byte.should == nil
+
+ # non-empty string case
+ s = StringScanner.new('a')
+ s.get_byte # skip one
+ s.get_byte.should == nil
+ end
+
+ describe "#[] successive call with a capture group name" do
+ # https://github.com/ruby/strscan/issues/139
+ version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
+ it "returns nil" do
+ s = StringScanner.new("This is a test")
+ s.get_byte
+ s.should.matched?
+ s[:a].should be_nil
+ end
+ end
+ version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
+ it "raises IndexError" do
+ s = StringScanner.new("This is a test")
+ s.get_byte
+ s.should.matched?
+ -> { s[:a] }.should raise_error(IndexError)
+ end
+ end
+
+ it "returns a matching character when given Integer index" do
+ s = StringScanner.new("This is a test")
+ s.get_byte
+ s[0].should == "T"
+ end
+
+ # https://github.com/ruby/strscan/issues/135
+ version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
+ it "ignores the previous matching with Regexp" do
+ s = StringScanner.new("This is a test")
+ s.exist?(/(?<a>This)/)
+ s.should.matched?
+ s[:a].should == "This"
+
+ s.get_byte
+ s.should.matched?
+ s[:a].should be_nil
+ end
+ end
+ version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
+ it "ignores the previous matching with Regexp" do
+ s = StringScanner.new("This is a test")
+ s.exist?(/(?<a>This)/)
+ s.should.matched?
+ s[:a].should == "This"
+
+ s.get_byte
+ s.should.matched?
+ -> { s[:a] }.should raise_error(IndexError)
+ end
+ end
+ end
end
diff --git a/spec/ruby/library/stringscanner/getbyte_spec.rb b/spec/ruby/library/stringscanner/getbyte_spec.rb
deleted file mode 100644
index e0659a5829..0000000000
--- a/spec/ruby/library/stringscanner/getbyte_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/get_byte'
-require_relative 'shared/extract_range'
-require 'strscan'
-
-describe "StringScanner#getbyte" do
- it_behaves_like :strscan_get_byte, :getbyte
-
- it "warns in verbose mode that the method is obsolete" do
- s = StringScanner.new("abc")
- -> {
- s.getbyte
- }.should complain(/getbyte.*obsolete.*get_byte/, verbose: true)
-
- -> {
- s.getbyte
- }.should_not complain(verbose: false)
- end
-
- it_behaves_like :extract_range, :getbyte
-end
diff --git a/spec/ruby/library/stringscanner/getch_spec.rb b/spec/ruby/library/stringscanner/getch_spec.rb
index ac43cf449d..d369391b14 100644
--- a/spec/ruby/library/stringscanner/getch_spec.rb
+++ b/spec/ruby/library/stringscanner/getch_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../spec_helper'
require_relative 'shared/extract_range'
require 'strscan'
@@ -33,7 +33,6 @@ describe "StringScanner#getch" do
describe "#[] successive call with a capture group name" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil" do
s = StringScanner.new("This is a test")
@@ -42,7 +41,6 @@ describe "StringScanner#getch" do
s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError" do
s = StringScanner.new("This is a test")
@@ -59,7 +57,6 @@ describe "StringScanner#getch" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("This is a test")
@@ -73,7 +70,6 @@ describe "StringScanner#getch" do
s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("This is a test")
diff --git a/spec/ruby/library/stringscanner/named_captures_spec.rb b/spec/ruby/library/stringscanner/named_captures_spec.rb
index f35051b8cb..a68d66c216 100644
--- a/spec/ruby/library/stringscanner/named_captures_spec.rb
+++ b/spec/ruby/library/stringscanner/named_captures_spec.rb
@@ -1,32 +1,30 @@
require_relative '../../spec_helper'
require 'strscan'
-version_is StringScanner::Version, "3.0.5" do # ruby_version_is "3.2"
- describe "StringScanner#named_captures" do
- before do
- @s = StringScanner.new('Fri Dec 12 1975 14:39')
- end
+describe "StringScanner#named_captures" do
+ before do
+ @s = StringScanner.new('Fri Dec 12 1975 14:39')
+ end
- it "returns a hash of names and matched substrings for named capturing groups in a regular expression of the most recent matching" do
- @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/)
- @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => "12"}
- end
+ it "returns a hash of names and matched substrings for named capturing groups in a regular expression of the most recent matching" do
+ @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\d+)/)
+ @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => "12"}
+ end
- it "returns {} if there are no named capturing groups" do
- @s.exist?(/(\w+) (\w+) (\d+)/)
- @s.named_captures.should == {}
- end
+ it "returns {} if there are no named capturing groups" do
+ @s.exist?(/(\w+) (\w+) (\d+)/)
+ @s.named_captures.should == {}
+ end
- # https://github.com/ruby/strscan/issues/132
- ruby_bug "", "3.2"..."3.3" do # fixed in strscan v3.0.7
- it "returns {} if there is no any matching done" do
- @s.named_captures.should == {}
- end
+ # https://github.com/ruby/strscan/issues/132
+ ruby_bug "", ""..."3.3" do # fixed in strscan v3.0.7
+ it "returns {} if there is no any matching done" do
+ @s.named_captures.should == {}
end
+ end
- it "returns nil for an optional named capturing group if it doesn't match" do
- @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/)
- @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => nil}
- end
+ it "returns nil for an optional named capturing group if it doesn't match" do
+ @s.exist?(/(?<wday>\w+) (?<month>\w+) (?<day>\s+)?/)
+ @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => nil}
end
end
diff --git a/spec/ruby/library/stringscanner/peek_spec.rb b/spec/ruby/library/stringscanner/peek_spec.rb
index cbb5630ff9..d490abecf9 100644
--- a/spec/ruby/library/stringscanner/peek_spec.rb
+++ b/spec/ruby/library/stringscanner/peek_spec.rb
@@ -1,7 +1,42 @@
require_relative '../../spec_helper'
-require_relative 'shared/peek'
require 'strscan'
describe "StringScanner#peek" do
- it_behaves_like :strscan_peek, :peek
+ before :each do
+ @s = StringScanner.new('This is a test')
+ end
+
+ it "returns at most the specified number of bytes from the current position" do
+ @s.peek(4).should == "This"
+ @s.pos.should == 0
+ @s.pos = 5
+ @s.peek(2).should == "is"
+ @s.peek(1000).should == "is a test"
+
+ s = StringScanner.new("été")
+ s.peek(2).should == "é"
+ end
+
+ it "returns an empty string when the passed argument is zero" do
+ @s.peek(0).should == ""
+ end
+
+ it "raises a ArgumentError when the passed argument is negative" do
+ -> { @s.peek(-2) }.should raise_error(ArgumentError)
+ end
+
+ it "raises a RangeError when the passed argument is a Bignum" do
+ -> { @s.peek(bignum_value) }.should raise_error(RangeError)
+ end
+
+ it "returns an instance of String when passed a String subclass" do
+ cls = Class.new(String)
+ sub = cls.new("abc")
+
+ s = StringScanner.new(sub)
+
+ ch = s.peek(1)
+ ch.should_not be_kind_of(cls)
+ ch.should be_an_instance_of(String)
+ end
end
diff --git a/spec/ruby/library/stringscanner/peep_spec.rb b/spec/ruby/library/stringscanner/peep_spec.rb
deleted file mode 100644
index bf6d579325..0000000000
--- a/spec/ruby/library/stringscanner/peep_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/peek'
-require 'strscan'
-
-describe "StringScanner#peep" do
- it_behaves_like :strscan_peek, :peep
-
- it "warns in verbose mode that the method is obsolete" do
- s = StringScanner.new("abc")
- -> {
- s.peep(1)
- }.should complain(/peep.*obsolete.*peek/, verbose: true)
-
- -> {
- s.peep(1)
- }.should_not complain(verbose: false)
- end
-end
diff --git a/spec/ruby/library/stringscanner/rest_size_spec.rb b/spec/ruby/library/stringscanner/rest_size_spec.rb
index e62e3a8f8c..a5e971631a 100644
--- a/spec/ruby/library/stringscanner/rest_size_spec.rb
+++ b/spec/ruby/library/stringscanner/rest_size_spec.rb
@@ -1,7 +1,21 @@
require_relative '../../spec_helper'
-require_relative 'shared/rest_size'
require 'strscan'
describe "StringScanner#rest_size" do
- it_behaves_like :strscan_rest_size, :rest_size
+ before :each do
+ @s = StringScanner.new('This is a test')
+ end
+
+ it "returns the length of the rest of the string" do
+ @s.rest_size.should == 14
+ @s.scan(/This/)
+ @s.rest_size.should == 10
+ @s.terminate
+ @s.rest_size.should == 0
+ end
+
+ it "is equivalent to rest.size" do
+ @s.scan(/This/)
+ @s.rest_size.should == @s.rest.size
+ end
end
diff --git a/spec/ruby/library/stringscanner/restsize_spec.rb b/spec/ruby/library/stringscanner/restsize_spec.rb
deleted file mode 100644
index 710520afae..0000000000
--- a/spec/ruby/library/stringscanner/restsize_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require_relative '../../spec_helper'
-require_relative 'shared/rest_size'
-require 'strscan'
-
-describe "StringScanner#restsize" do
- it_behaves_like :strscan_rest_size, :restsize
-
- it "warns in verbose mode that the method is obsolete" do
- s = StringScanner.new("abc")
- -> {
- s.restsize
- }.should complain(/restsize.*obsolete.*rest_size/, verbose: true)
-
- -> {
- s.restsize
- }.should_not complain(verbose: false)
- end
-end
diff --git a/spec/ruby/library/stringscanner/scan_byte_spec.rb b/spec/ruby/library/stringscanner/scan_byte_spec.rb
index c60e22be4f..aa2decc8f7 100644
--- a/spec/ruby/library/stringscanner/scan_byte_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_byte_spec.rb
@@ -43,7 +43,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
describe "#[] successive call with a capture group name" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil" do
s = StringScanner.new("abc")
@@ -52,7 +51,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError" do
s = StringScanner.new("abc")
@@ -69,7 +67,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("abc")
@@ -83,7 +80,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
s[:a].should == nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("abc")
diff --git a/spec/ruby/library/stringscanner/scan_integer_spec.rb b/spec/ruby/library/stringscanner/scan_integer_spec.rb
index a0b3685bae..fe0d26f404 100644
--- a/spec/ruby/library/stringscanner/scan_integer_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_integer_spec.rb
@@ -25,7 +25,7 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
end
# https://github.com/ruby/strscan/issues/130
- ruby_bug "", "3.4"..."3.5" do # introduced in strscan v3.1.1
+ ruby_bug "", "3.4"..."4.0" do # introduced in strscan v3.1.1
it "sets the last match result" do
s = StringScanner.new("42abc")
s.scan_integer
@@ -68,7 +68,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
}.should raise_error(ArgumentError, "Unsupported integer base: 5, expected 10 or 16")
end
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "does not match '0x' prefix on its own" do
StringScanner.new("0x").scan_integer(base: 16).should == nil
@@ -76,7 +75,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
StringScanner.new("+0x").scan_integer(base: 16).should == nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "matches '0' in a '0x' that is followed by non-hex characters" do
@@ -96,7 +94,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
describe "#[] successive call with a capture group name" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil substring when matching succeeded" do
s = StringScanner.new("42")
@@ -105,7 +102,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
s[:a].should == nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
s = StringScanner.new("42")
@@ -131,7 +127,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "does not ignore the previous matching with Regexp" do
s = StringScanner.new("42")
@@ -145,7 +140,6 @@ version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
s[:a].should == "42"
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "ignores the previous matching with Regexp" do
s = StringScanner.new("42")
diff --git a/spec/ruby/library/stringscanner/scan_until_spec.rb b/spec/ruby/library/stringscanner/scan_until_spec.rb
index 737d83a14c..610060d6f1 100644
--- a/spec/ruby/library/stringscanner/scan_until_spec.rb
+++ b/spec/ruby/library/stringscanner/scan_until_spec.rb
@@ -41,7 +41,6 @@ describe "StringScanner#scan_until" do
end
# https://github.com/ruby/strscan/issues/131
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1"
it "sets the last match result if given a String" do
@s.scan_until("a")
@@ -51,7 +50,6 @@ describe "StringScanner#scan_until" do
@s.post_match.should == " test"
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "sets the last match result if given a String" do
@@ -82,7 +80,6 @@ describe "StringScanner#scan_until" do
version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
context "when #scan_until was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.scan_until("This")
@@ -90,7 +87,6 @@ describe "StringScanner#scan_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
@s.scan_until("This")
@@ -111,7 +107,6 @@ describe "StringScanner#scan_until" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
@@ -123,7 +118,6 @@ describe "StringScanner#scan_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
diff --git a/spec/ruby/library/stringscanner/search_full_spec.rb b/spec/ruby/library/stringscanner/search_full_spec.rb
index a089da2043..197adfda4d 100644
--- a/spec/ruby/library/stringscanner/search_full_spec.rb
+++ b/spec/ruby/library/stringscanner/search_full_spec.rb
@@ -50,7 +50,6 @@ describe "StringScanner#search_full" do
end
# https://github.com/ruby/strscan/issues/131
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1"
it "sets the last match result if given a String" do
@s.search_full("is a", false, false)
@@ -60,7 +59,6 @@ describe "StringScanner#search_full" do
@s.post_match.should == " test"
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "sets the last match result if given a String" do
@@ -91,7 +89,6 @@ describe "StringScanner#search_full" do
version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
context "when #search_full was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.search_full("This", false, false)
@@ -99,7 +96,6 @@ describe "StringScanner#search_full" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
@s.search_full("This", false, false)
diff --git a/spec/ruby/library/stringscanner/shared/eos.rb b/spec/ruby/library/stringscanner/shared/eos.rb
deleted file mode 100644
index ea04c764a2..0000000000
--- a/spec/ruby/library/stringscanner/shared/eos.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-describe :strscan_eos, shared: true do
- before :each do
- @s = StringScanner.new("This is a test")
- end
-
- it "returns true if the scan pointer is at the end of the string" do
- @s.terminate
- @s.send(@method).should be_true
-
- s = StringScanner.new('')
- s.send(@method).should be_true
- end
-
- it "returns false if the scan pointer is not at the end of the string" do
- @s.send(@method).should be_false
- end
-end
diff --git a/spec/ruby/library/stringscanner/shared/get_byte.rb b/spec/ruby/library/stringscanner/shared/get_byte.rb
deleted file mode 100644
index f1b016905f..0000000000
--- a/spec/ruby/library/stringscanner/shared/get_byte.rb
+++ /dev/null
@@ -1,87 +0,0 @@
-# -*- encoding: binary -*-
-require 'strscan'
-
-describe :strscan_get_byte, shared: true do
- it "scans one byte and returns it" do
- s = StringScanner.new('abc5.')
- s.send(@method).should == 'a'
- s.send(@method).should == 'b'
- s.send(@method).should == 'c'
- s.send(@method).should == '5'
- s.send(@method).should == '.'
- end
-
- it "is not multi-byte character sensitive" do
- s = StringScanner.new("\244\242")
- s.send(@method).should == "\244"
- s.send(@method).should == "\242"
- end
-
- it "returns nil at the end of the string" do
- # empty string case
- s = StringScanner.new('')
- s.send(@method).should == nil
- s.send(@method).should == nil
-
- # non-empty string case
- s = StringScanner.new('a')
- s.send(@method) # skip one
- s.send(@method).should == nil
- end
-
- describe "#[] successive call with a capture group name" do
- # https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
- version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
- it "returns nil" do
- s = StringScanner.new("This is a test")
- s.send(@method)
- s.should.matched?
- s[:a].should be_nil
- end
- end
- end
- version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
- it "raises IndexError" do
- s = StringScanner.new("This is a test")
- s.send(@method)
- s.should.matched?
- -> { s[:a] }.should raise_error(IndexError)
- end
- end
-
- it "returns a matching character when given Integer index" do
- s = StringScanner.new("This is a test")
- s.send(@method)
- s[0].should == "T"
- end
-
- # https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
- version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
- it "ignores the previous matching with Regexp" do
- s = StringScanner.new("This is a test")
- s.exist?(/(?<a>This)/)
- s.should.matched?
- s[:a].should == "This"
-
- s.send(@method)
- s.should.matched?
- s[:a].should be_nil
- end
- end
- end
- version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
- it "ignores the previous matching with Regexp" do
- s = StringScanner.new("This is a test")
- s.exist?(/(?<a>This)/)
- s.should.matched?
- s[:a].should == "This"
-
- s.send(@method)
- s.should.matched?
- -> { s[:a] }.should raise_error(IndexError)
- end
- end
- end
-end
diff --git a/spec/ruby/library/stringscanner/shared/peek.rb b/spec/ruby/library/stringscanner/shared/peek.rb
deleted file mode 100644
index 4c757866c1..0000000000
--- a/spec/ruby/library/stringscanner/shared/peek.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-describe :strscan_peek, shared: true do
- before :each do
- @s = StringScanner.new('This is a test')
- end
-
- it "returns at most the specified number of bytes from the current position" do
- @s.send(@method, 4).should == "This"
- @s.pos.should == 0
- @s.pos = 5
- @s.send(@method, 2).should == "is"
- @s.send(@method, 1000).should == "is a test"
-
- s = StringScanner.new("été")
- s.send(@method, 2).should == "é"
- end
-
- it "returns an empty string when the passed argument is zero" do
- @s.send(@method, 0).should == ""
- end
-
- it "raises a ArgumentError when the passed argument is negative" do
- -> { @s.send(@method, -2) }.should raise_error(ArgumentError)
- end
-
- it "raises a RangeError when the passed argument is a Bignum" do
- -> { @s.send(@method, bignum_value) }.should raise_error(RangeError)
- end
-
- it "returns an instance of String when passed a String subclass" do
- cls = Class.new(String)
- sub = cls.new("abc")
-
- s = StringScanner.new(sub)
-
- ch = s.send(@method, 1)
- ch.should_not be_kind_of(cls)
- ch.should be_an_instance_of(String)
- end
-end
diff --git a/spec/ruby/library/stringscanner/shared/pos.rb b/spec/ruby/library/stringscanner/shared/pos.rb
index 6d540881f2..eea7ead6b5 100644
--- a/spec/ruby/library/stringscanner/shared/pos.rb
+++ b/spec/ruby/library/stringscanner/shared/pos.rb
@@ -22,6 +22,13 @@ describe :strscan_pos, shared: true do
@s.terminate
@s.send(@method).should == @s.string.length
end
+
+ it "is not multi-byte character sensitive" do
+ s = StringScanner.new("abcädeföghi")
+
+ s.scan_until(/ö/)
+ s.pos.should == 10
+ end
end
describe :strscan_pos_set, shared: true do
diff --git a/spec/ruby/library/stringscanner/shared/rest_size.rb b/spec/ruby/library/stringscanner/shared/rest_size.rb
deleted file mode 100644
index 4c4f49e45c..0000000000
--- a/spec/ruby/library/stringscanner/shared/rest_size.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :strscan_rest_size, shared: true do
- before :each do
- @s = StringScanner.new('This is a test')
- end
-
- it "returns the length of the rest of the string" do
- @s.send(@method).should == 14
- @s.scan(/This/)
- @s.send(@method).should == 10
- @s.terminate
- @s.send(@method).should == 0
- end
-
- it "is equivalent to rest.size" do
- @s.scan(/This/)
- @s.send(@method).should == @s.rest.size
- end
-end
diff --git a/spec/ruby/library/stringscanner/shared/terminate.rb b/spec/ruby/library/stringscanner/shared/terminate.rb
deleted file mode 100644
index bf41d097e2..0000000000
--- a/spec/ruby/library/stringscanner/shared/terminate.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :strscan_terminate, shared: true do
- it "set the scan pointer to the end of the string and clear matching data." do
- s = StringScanner.new('This is a test')
- s.send(@method)
- s.bol?.should be_false
- s.eos?.should be_true
- end
-end
diff --git a/spec/ruby/library/stringscanner/skip_until_spec.rb b/spec/ruby/library/stringscanner/skip_until_spec.rb
index f5be4b5ceb..5d73d8f0b9 100644
--- a/spec/ruby/library/stringscanner/skip_until_spec.rb
+++ b/spec/ruby/library/stringscanner/skip_until_spec.rb
@@ -38,7 +38,6 @@ describe "StringScanner#skip_until" do
end
# https://github.com/ruby/strscan/issues/131
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.1"
it "sets the last match result if given a String" do
@s.skip_until("a")
@@ -48,7 +47,6 @@ describe "StringScanner#skip_until" do
@s.post_match.should == " test"
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "sets the last match result if given a String" do
@@ -79,7 +77,6 @@ describe "StringScanner#skip_until" do
version_is StringScanner::Version, "3.1.1" do # ruby_version_is "3.4"
context "when #skip_until was called with a String pattern" do
# https://github.com/ruby/strscan/issues/139
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "returns nil when matching succeeded" do
@s.skip_until("This")
@@ -87,7 +84,6 @@ describe "StringScanner#skip_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4.3"
it "raises IndexError when matching succeeded" do
@s.skip_until("This")
@@ -108,7 +104,6 @@ describe "StringScanner#skip_until" do
end
# https://github.com/ruby/strscan/issues/135
- ruby_version_is ""..."3.5" do # Don't run on 3.5.0dev that already contains not released fixes
version_is StringScanner::Version, "3.1.1"..."3.1.3" do # ruby_version_is "3.4.0"..."3.4.3"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
@@ -120,7 +115,6 @@ describe "StringScanner#skip_until" do
@s[:a].should be_nil
end
end
- end
version_is StringScanner::Version, "3.1.3" do # ruby_version_is "3.4"
it "ignores the previous matching with Regexp" do
@s.exist?(/(?<a>This)/)
diff --git a/spec/ruby/library/stringscanner/terminate_spec.rb b/spec/ruby/library/stringscanner/terminate_spec.rb
index 7943efe0f9..3cff5c010c 100644
--- a/spec/ruby/library/stringscanner/terminate_spec.rb
+++ b/spec/ruby/library/stringscanner/terminate_spec.rb
@@ -1,7 +1,11 @@
require_relative '../../spec_helper'
-require_relative 'shared/terminate'
require 'strscan'
describe "StringScanner#terminate" do
- it_behaves_like :strscan_terminate, :terminate
+ it "set the scan pointer to the end of the string and clear matching data." do
+ s = StringScanner.new('This is a test')
+ s.terminate
+ s.should_not.bol?
+ s.should.eos?
+ end
end
diff --git a/spec/ruby/library/stringscanner/unscan_spec.rb b/spec/ruby/library/stringscanner/unscan_spec.rb
index df0ea43367..b7b4876b8a 100644
--- a/spec/ruby/library/stringscanner/unscan_spec.rb
+++ b/spec/ruby/library/stringscanner/unscan_spec.rb
@@ -21,8 +21,8 @@ describe "StringScanner#unscan" do
@s.pos.should == pos
end
- it "raises a ScanError when the previous match had failed" do
- -> { @s.unscan }.should raise_error(ScanError)
- -> { @s.scan(/\d/); @s.unscan }.should raise_error(ScanError)
+ it "raises a StringScanner::Error when the previous match had failed" do
+ -> { @s.unscan }.should raise_error(StringScanner::Error)
+ -> { @s.scan(/\d/); @s.unscan }.should raise_error(StringScanner::Error)
end
end
diff --git a/spec/ruby/library/tempfile/callback_spec.rb b/spec/ruby/library/tempfile/callback_spec.rb
deleted file mode 100644
index c0b1518326..0000000000
--- a/spec/ruby/library/tempfile/callback_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require_relative '../../spec_helper'
-require 'tempfile'
-
-describe "Tempfile.callback" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/library/tempfile/create_spec.rb b/spec/ruby/library/tempfile/create_spec.rb
new file mode 100644
index 0000000000..74c48bf32a
--- /dev/null
+++ b/spec/ruby/library/tempfile/create_spec.rb
@@ -0,0 +1,176 @@
+require_relative '../../spec_helper'
+require 'tempfile'
+
+describe "Tempfile.create" do
+ after :each do
+ if @tempfile
+ @tempfile.close
+ File.unlink(@tempfile.path) if File.file?(@tempfile.path)
+ end
+ end
+
+ it "returns a new, open regular File instance placed in tmpdir" do
+ @tempfile = Tempfile.create
+ # Unlike Tempfile.open this returns a true File,
+ # but `.should be_an_instance_of(File)` would be true either way.
+ @tempfile.instance_of?(File).should be_true
+
+ @tempfile.should_not.closed?
+ File.file?(@tempfile.path).should be_true
+
+ @tempfile.path.should.start_with?(Dir.tmpdir)
+ @tempfile.path.should_not == "#{Dir.tmpdir}/"
+ end
+
+ it "returns file in w+ mode" do
+ @tempfile = Tempfile.create
+ @tempfile << "Test!\nMore test!"
+ @tempfile.rewind
+ @tempfile.read.should == "Test!\nMore test!"
+
+ # Not "a+" mode, which would write at the end of the file.
+ @tempfile.rewind
+ @tempfile.print "Trust"
+ @tempfile.rewind
+ @tempfile.read.should == "Trust\nMore test!"
+ end
+
+ platform_is_not :windows do
+ it "returns a private, readable and writable file" do
+ @tempfile = Tempfile.create
+ stat = @tempfile.stat
+ stat.should.readable?
+ stat.should.writable?
+ stat.should_not.executable?
+ stat.should_not.world_readable?
+ stat.should_not.world_writable?
+ end
+ end
+
+ platform_is :windows do
+ it "returns a public, readable and writable file" do
+ @tempfile = Tempfile.create
+ stat = @tempfile.stat
+ stat.should.readable?
+ stat.should.writable?
+ stat.should_not.executable?
+ stat.should.world_readable?
+ stat.should.world_writable?
+ end
+ end
+
+ context "when called with a block" do
+ it "returns the value of the block" do
+ value = Tempfile.create do |tempfile|
+ tempfile << "Test!"
+ "return"
+ end
+ value.should == "return"
+ end
+
+ it "closes and unlinks file after block execution" do
+ Tempfile.create do |tempfile|
+ @tempfile = tempfile
+ @tempfile.should_not.closed?
+ File.exist?(@tempfile.path).should be_true
+ end
+
+ @tempfile.should.closed?
+ File.exist?(@tempfile.path).should be_false
+ end
+ end
+
+ context "when called with a single positional argument" do
+ it "uses a String as a prefix for the filename" do
+ @tempfile = Tempfile.create("create_spec")
+ @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec")
+ @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec"
+ end
+
+ it "uses an array of one String as a prefix for the filename" do
+ @tempfile = Tempfile.create(["create_spec"])
+ @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec")
+ @tempfile.path.should_not == "#{Dir.tmpdir}/create_spec"
+ end
+
+ it "uses an array of two Strings as a prefix and suffix for the filename" do
+ @tempfile = Tempfile.create(["create_spec", ".temp"])
+ @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec")
+ @tempfile.path.should.end_with?(".temp")
+ end
+
+ it "ignores excessive array elements after the first two" do
+ @tempfile = Tempfile.create(["create_spec", ".temp", :".txt"])
+ @tempfile.path.should.start_with?("#{Dir.tmpdir}/create_spec")
+ @tempfile.path.should.end_with?(".temp")
+ end
+
+ it "raises ArgumentError if passed something else than a String or an array of Strings" do
+ -> { Tempfile.create(:create_spec) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec")
+ -> { Tempfile.create([:create_spec]) }.should raise_error(ArgumentError, "unexpected prefix: :create_spec")
+ -> { Tempfile.create(["create_spec", :temp]) }.should raise_error(ArgumentError, "unexpected suffix: :temp")
+ end
+ end
+
+ context "when called with a second positional argument" do
+ it "uses it as a directory for the tempfile" do
+ @tempfile = Tempfile.create("create_spec", "./")
+ @tempfile.path.should.start_with?("./create_spec")
+ end
+
+ it "raises TypeError if argument can not be converted to a String" do
+ -> { Tempfile.create("create_spec", :temp) }.should raise_error(TypeError, "no implicit conversion of Symbol into String")
+ end
+ end
+
+ context "when called with a mode option" do
+ it "ORs it with the default mode, forcing it to be readable and writable" do
+ @tempfile = Tempfile.create(mode: File::RDONLY)
+ @tempfile.puts "test"
+ @tempfile.rewind
+ @tempfile.read.should == "test\n"
+ end
+
+ it "raises NoMethodError if passed a String mode" do
+ -> { Tempfile.create(mode: "wb") }.should raise_error(NoMethodError, /undefined method ['`]|' for .+String/)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ context "when called with anonymous: true" do
+ it "returns an already unlinked File without a proper path" do
+ @tempfile = Tempfile.create(anonymous: true)
+ @tempfile.should_not.closed?
+ @tempfile.path.should == "#{Dir.tmpdir}/"
+ File.file?(@tempfile.path).should be_false
+ end
+
+ it "unlinks file before calling the block" do
+ Tempfile.create(anonymous: true) do |tempfile|
+ @tempfile = tempfile
+ @tempfile.should_not.closed?
+ @tempfile.path.should == "#{Dir.tmpdir}/"
+ File.file?(@tempfile.path).should be_false
+ end
+ @tempfile.should.closed?
+ end
+ end
+
+ context "when called with anonymous: false" do
+ it "returns a usual File with a path" do
+ @tempfile = Tempfile.create(anonymous: false)
+ @tempfile.should_not.closed?
+ @tempfile.path.should.start_with?(Dir.tmpdir)
+ File.file?(@tempfile.path).should be_true
+ end
+ end
+ end
+
+ context "when called with other options" do
+ it "passes them along to File.open" do
+ @tempfile = Tempfile.create(encoding: "IBM037:IBM037", binmode: true)
+ @tempfile.external_encoding.should == Encoding.find("IBM037")
+ @tempfile.binmode?.should be_true
+ end
+ end
+end
diff --git a/spec/ruby/library/timeout/timeout_spec.rb b/spec/ruby/library/timeout/timeout_spec.rb
index 584b38d8ec..e16bcaea6a 100644
--- a/spec/ruby/library/timeout/timeout_spec.rb
+++ b/spec/ruby/library/timeout/timeout_spec.rb
@@ -39,4 +39,12 @@ describe "Timeout.timeout" do
42
end.should == 42
end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError when provided with a negative duration" do
+ -> {
+ Timeout.timeout(-1)
+ }.should raise_error(ArgumentError, "Timeout sec must be a non-negative number")
+ end
+ end
end
diff --git a/spec/ruby/library/uri/generic/host_spec.rb b/spec/ruby/library/uri/generic/host_spec.rb
index 210124ef66..4a5a162512 100644
--- a/spec/ruby/library/uri/generic/host_spec.rb
+++ b/spec/ruby/library/uri/generic/host_spec.rb
@@ -2,11 +2,9 @@ require_relative '../../../spec_helper'
require 'uri'
describe "URI::Generic#host" do
- version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do
- # https://hackerone.com/reports/156615
- it "returns empty string when host is empty" do
- URI.parse('http:////foo.com').host.should == ''
- end
+ # https://hackerone.com/reports/156615
+ it "returns empty string when host is empty" do
+ URI.parse('http:////foo.com').host.should == ''
end
end
diff --git a/spec/ruby/library/uri/generic/to_s_spec.rb b/spec/ruby/library/uri/generic/to_s_spec.rb
index 8cebd374a1..c436ee3c03 100644
--- a/spec/ruby/library/uri/generic/to_s_spec.rb
+++ b/spec/ruby/library/uri/generic/to_s_spec.rb
@@ -2,10 +2,8 @@ require_relative '../../../spec_helper'
require 'uri'
describe "URI::Generic#to_s" do
- version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do
- # https://hackerone.com/reports/156615
- it "preserves / characters when host is empty" do
- URI('http:///foo.com').to_s.should == 'http:///foo.com'
- end
+ # https://hackerone.com/reports/156615
+ it "preserves / characters when host is empty" do
+ URI('http:///foo.com').to_s.should == 'http:///foo.com'
end
end
diff --git a/spec/ruby/library/uri/set_component_spec.rb b/spec/ruby/library/uri/set_component_spec.rb
index 642a5d6fcf..1d4165c535 100644
--- a/spec/ruby/library/uri/set_component_spec.rb
+++ b/spec/ruby/library/uri/set_component_spec.rb
@@ -6,25 +6,27 @@ describe "URI#select" do
it "conforms to the MatzRuby tests" do
uri = URI.parse('http://foo:bar@baz')
(uri.user = 'oof').should == 'oof'
- uri.to_s.should == 'http://oof:bar@baz'
- (uri.password = 'rab').should == 'rab'
- uri.to_s.should == 'http://oof:rab@baz'
- (uri.userinfo = 'foo').should == 'foo'
- uri.to_s.should == 'http://foo:rab@baz'
- (uri.userinfo = ['foo', 'bar']).should == ['foo', 'bar']
- uri.to_s.should == 'http://foo:bar@baz'
- (uri.userinfo = ['foo']).should == ['foo']
- uri.to_s.should == 'http://foo:bar@baz'
- (uri.host = 'zab').should == 'zab'
- uri.to_s.should == 'http://foo:bar@zab'
- (uri.port = 8080).should == 8080
- uri.to_s.should == 'http://foo:bar@zab:8080'
- (uri.path = '/').should == '/'
- uri.to_s.should == 'http://foo:bar@zab:8080/'
- (uri.query = 'a=1').should == 'a=1'
- uri.to_s.should == 'http://foo:bar@zab:8080/?a=1'
- (uri.fragment = 'b123').should == 'b123'
- uri.to_s.should == 'http://foo:bar@zab:8080/?a=1#b123'
+ version_is(URI::VERSION, "1.0.4") do
+ uri.to_s.should == 'http://oof@baz'
+ (uri.password = 'rab').should == 'rab'
+ uri.to_s.should == 'http://oof:rab@baz'
+ (uri.userinfo = 'foo').should == 'foo'
+ uri.to_s.should == 'http://foo@baz'
+ (uri.userinfo = ['foo', 'bar']).should == ['foo', 'bar']
+ uri.to_s.should == 'http://foo:bar@baz'
+ (uri.userinfo = ['foo']).should == ['foo']
+ uri.to_s.should == 'http://foo@baz'
+ (uri.host = 'zab').should == 'zab'
+ uri.to_s.should == 'http://zab'
+ (uri.port = 8080).should == 8080
+ uri.to_s.should == 'http://zab:8080'
+ (uri.path = '/').should == '/'
+ uri.to_s.should == 'http://zab:8080/'
+ (uri.query = 'a=1').should == 'a=1'
+ uri.to_s.should == 'http://zab:8080/?a=1'
+ (uri.fragment = 'b123').should == 'b123'
+ uri.to_s.should == 'http://zab:8080/?a=1#b123'
+ end
uri = URI.parse('http://example.com')
-> { uri.password = 'bar' }.should raise_error(URI::InvalidURIError)
diff --git a/spec/ruby/library/win32ole/fixtures/classes.rb b/spec/ruby/library/win32ole/fixtures/classes.rb
index f61cf6ba69..5a16fcca45 100644
--- a/spec/ruby/library/win32ole/fixtures/classes.rb
+++ b/spec/ruby/library/win32ole/fixtures/classes.rb
@@ -1,14 +1,25 @@
require 'win32ole'
+# win32ole deprecated constants like WIN32OLE_TYPELIB in Ruby 3.4
+# but only added the replacements like WIN32OLE::TypeLib in Ruby 3.4.
+# So we use the new-style constants in specs to avoid deprecation warnings
+# and we define the new-style constants as the old ones if they don't exist yet.
+WIN32OLE::TypeLib ||= WIN32OLE_TYPELIB
+WIN32OLE::RuntimeError ||= WIN32OLERuntimeError
+WIN32OLE::Method ||= WIN32OLE_METHOD
+WIN32OLE::Type ||= WIN32OLE_TYPE
+WIN32OLE::Event ||= WIN32OLE_EVENT
+WIN32OLE::Param ||= WIN32OLE_PARAM
+
module WIN32OLESpecs
- MSXML_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
- SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE_TYPELIB.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
+ MSXML_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('Microsoft XML') }
+ SYSTEM_MONITOR_CONTROL_AVAILABLE = WIN32OLE::TypeLib.typelibs.any? { |t| t.name.start_with?('System Monitor Control') }
def self.new_ole(name)
tries = 0
begin
WIN32OLE.new(name)
- rescue WIN32OLERuntimeError => e
+ rescue WIN32OLE::RuntimeError => e
if tries < 3
tries += 1
$stderr.puts "WIN32OLESpecs#new_ole retry (#{tries}): #{e.class}: #{e.message}"
diff --git a/spec/ruby/library/win32ole/win32ole/locale_spec.rb b/spec/ruby/library/win32ole/win32ole/locale_spec.rb
index 78ede4375a..89e84d8038 100644
--- a/spec/ruby/library/win32ole/win32ole/locale_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/locale_spec.rb
@@ -13,14 +13,14 @@ platform_is :windows do
begin
begin
WIN32OLE.locale = 1041
- rescue WIN32OLERuntimeError
+ rescue WIN32OLE::RuntimeError
STDERR.puts("\n#{__FILE__}:#{__LINE__}:#{self.class.name}.test_s_locale_set is skipped(Japanese locale is not installed)")
return
end
WIN32OLE.locale.should == 1041
WIN32OLE.locale = WIN32OLE::LOCALE_SYSTEM_DEFAULT
- -> { WIN32OLE.locale = 111 }.should raise_error WIN32OLERuntimeError
+ -> { WIN32OLE.locale = 111 }.should raise_error WIN32OLE::RuntimeError
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT
ensure
WIN32OLE.locale.should == WIN32OLE::LOCALE_SYSTEM_DEFAULT
diff --git a/spec/ruby/library/win32ole/win32ole/new_spec.rb b/spec/ruby/library/win32ole/win32ole/new_spec.rb
index 7e91c2d3ea..b2a0a5da18 100644
--- a/spec/ruby/library/win32ole/win32ole/new_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/new_spec.rb
@@ -17,8 +17,8 @@ platform_is :windows do
-> { WIN32OLESpecs.new_ole(42) }.should raise_error( TypeError )
end
- it "raises WIN32OLERuntimeError if invalid string is given" do
- -> { WIN32OLE.new('foo') }.should raise_error( WIN32OLERuntimeError )
+ it "raises WIN32OLE::RuntimeError if invalid string is given" do
+ -> { WIN32OLE.new('foo') }.should raise_error( WIN32OLE::RuntimeError )
end
end
diff --git a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb
index 2bbe8c27d4..b846685518 100644
--- a/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb
@@ -11,8 +11,8 @@ platform_is :windows do
-> { @dict.ole_func_methods(1) }.should raise_error ArgumentError
end
- it "returns an array of WIN32OLE_METHODs" do
- @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
+ it "returns an array of WIN32OLE::Methods" do
+ @dict.ole_func_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
end
it "contains a 'AddRef' method for Scripting Dictionary" do
diff --git a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb
index c1d1970214..b6e7f960bb 100644
--- a/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb
@@ -8,8 +8,8 @@ platform_is :windows do
@win32ole = WIN32OLESpecs.new_ole('Shell.Application')
end
- it "returns an array of WIN32OLE_METHOD objects" do
- @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE_METHOD}.should be_true
+ it "returns an array of WIN32OLE::Method objects" do
+ @win32ole.ole_get_methods.all? {|m| m.kind_of? WIN32OLE::Method}.should be_true
end
end
diff --git a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb
index fe161ce9f0..92c4363f78 100644
--- a/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb
@@ -11,8 +11,8 @@ platform_is :windows do
-> { @dict.ole_methods(1) }.should raise_error ArgumentError
end
- it "returns an array of WIN32OLE_METHODs" do
- @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
+ it "returns an array of WIN32OLE::Methods" do
+ @dict.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
end
it "contains a 'AddRef' method for Scripting Dictionary" do
diff --git a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb
index afcf16a051..f298f19dba 100644
--- a/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb
@@ -12,8 +12,8 @@ platform_is :windows do
-> { @dict.ole_obj_help(1) }.should raise_error ArgumentError
end
- it "returns an instance of WIN32OLE_TYPE" do
- @dict.ole_obj_help.kind_of?(WIN32OLE_TYPE).should be_true
+ it "returns an instance of WIN32OLE::Type" do
+ @dict.ole_obj_help.kind_of?(WIN32OLE::Type).should be_true
end
end
end
diff --git a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb
index c091c83c95..2b46ae47de 100644
--- a/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb
@@ -11,8 +11,8 @@ platform_is :windows do
-> { @dict.ole_put_methods(1) }.should raise_error ArgumentError
end
- it "returns an array of WIN32OLE_METHODs" do
- @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
+ it "returns an array of WIN32OLE::Methods" do
+ @dict.ole_put_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
end
it "contains a 'Key' method for Scripting Dictionary" do
diff --git a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb
index f1fd8713a4..bae424a604 100644
--- a/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb
+++ b/spec/ruby/library/win32ole/win32ole/shared/ole_method.rb
@@ -10,9 +10,9 @@ platform_is :windows do
-> { @dict.send(@method) }.should raise_error ArgumentError
end
- it "returns the WIN32OLE_METHOD 'Add' if given 'Add'" do
+ it "returns the WIN32OLE::Method 'Add' if given 'Add'" do
result = @dict.send(@method, "Add")
- result.kind_of?(WIN32OLE_METHOD).should be_true
+ result.kind_of?(WIN32OLE::Method).should be_true
result.name.should == 'Add'
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb
index 94fabb1e3b..4efd4c3e0f 100644
--- a/spec/ruby/library/win32ole/win32ole_event/new_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_event/new_spec.rb
@@ -3,7 +3,7 @@ platform_is :windows do
require_relative '../fixtures/classes'
guard -> { WIN32OLESpecs::MSXML_AVAILABLE } do
- describe "WIN32OLE_EVENT.new" do
+ describe "WIN32OLE::Event.new" do
before :all do
@xml_dom = WIN32OLESpecs.new_ole('MSXML.DOMDocument')
end
@@ -13,21 +13,21 @@ platform_is :windows do
end
it "raises TypeError given invalid argument" do
- -> { WIN32OLE_EVENT.new "A" }.should raise_error TypeError
+ -> { WIN32OLE::Event.new "A" }.should raise_error TypeError
end
it "raises RuntimeError if event does not exist" do
- -> { WIN32OLE_EVENT.new(@xml_dom, 'A') }.should raise_error RuntimeError
+ -> { WIN32OLE::Event.new(@xml_dom, 'A') }.should raise_error RuntimeError
end
it "raises RuntimeError if OLE object has no events" do
dict = WIN32OLESpecs.new_ole('Scripting.Dictionary')
- -> { WIN32OLE_EVENT.new(dict) }.should raise_error RuntimeError
+ -> { WIN32OLE::Event.new(dict) }.should raise_error RuntimeError
end
- it "creates WIN32OLE_EVENT object" do
- ev = WIN32OLE_EVENT.new(@xml_dom)
- ev.should be_kind_of WIN32OLE_EVENT
+ it "creates WIN32OLE::Event object" do
+ ev = WIN32OLE::Event.new(@xml_dom)
+ ev.should be_kind_of WIN32OLE::Event
end
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb b/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb
index 0957bdd2d4..acc7d2d6b6 100644
--- a/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb
@@ -15,7 +15,7 @@ platform_is :windows do
@event_spec_alt = "spec_alt"
end
- describe "WIN32OLE_EVENT#on_event" do
+ describe "WIN32OLE::Event#on_event" do
before :all do
@fn_xml = File.absolute_path "../fixtures/event.xml", __dir__
end
@@ -23,7 +23,7 @@ platform_is :windows do
before :each do
@xml_dom = WIN32OLESpecs.new_ole 'MSXML.DOMDocument'
@xml_dom.async = true
- @ev = WIN32OLE_EVENT.new @xml_dom
+ @ev = WIN32OLE::Event.new @xml_dom
@event_global = ''
@event_specific = ''
@event_spec_alt = ''
@@ -37,21 +37,21 @@ platform_is :windows do
it "sets global event handler properly, and the handler is invoked by event loop" do
@ev.on_event { |*args| handler_global(*args) }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
- WIN32OLE_EVENT.message_loop
+ WIN32OLE::Event.message_loop
@event_global.should =~ /onreadystatechange/
end
it "accepts a String argument and the handler is invoked by event loop" do
@ev.on_event("onreadystatechange") { |*args| @event = 'foo' }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
- WIN32OLE_EVENT.message_loop
+ WIN32OLE::Event.message_loop
@event.should =~ /foo/
end
it "accepts a Symbol argument and the handler is invoked by event loop" do
@ev.on_event(:onreadystatechange) { |*args| @event = 'bar' }
@xml_dom.loadXML "<program><name>Ruby</name><version>trunk</version></program>"
- WIN32OLE_EVENT.message_loop
+ WIN32OLE::Event.message_loop
@event.should =~ /bar/
end
@@ -60,7 +60,7 @@ platform_is :windows do
@ev.on_event("onreadystatechange") { |*args| handler_specific(*args) }
@ev.on_event("onreadystatechange") { |*args| handler_spec_alt(*args) }
@xml_dom.load @fn_xml
- WIN32OLE_EVENT.message_loop
+ WIN32OLE::Event.message_loop
@event_global.should == 'ondataavailable'
@event_global.should_not =~ /onreadystatechange/
@event_specific.should == ''
diff --git a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb
index ece71df0d4..e5f55f2d38 100644
--- a/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#dispid" do
+ describe "WIN32OLE::Method#dispid" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m = WIN32OLE_METHOD.new(ole_type, "namespace")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m = WIN32OLE::Method.new(ole_type, "namespace")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb b/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb
index 78634d2fde..bea47348ee 100644
--- a/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb
@@ -3,12 +3,12 @@ platform_is :windows do
require_relative '../fixtures/classes'
guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do
- describe "WIN32OLE_METHOD#event_interface" do
+ describe "WIN32OLE::Method#event_interface" do
before :each do
- ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor")
- @on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick")
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @namespace_method = WIN32OLE_METHOD.new(ole_type, "namespace")
+ ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor")
+ @on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @namespace_method = WIN32OLE::Method.new(ole_type, "namespace")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb
index 9b642a010c..5a94cf5ce6 100644
--- a/spec/ruby/library/win32ole/win32ole_method/event_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/event_spec.rb
@@ -3,10 +3,10 @@ platform_is :windows do
require_relative '../fixtures/classes'
guard -> { WIN32OLESpecs::SYSTEM_MONITOR_CONTROL_AVAILABLE } do
- describe "WIN32OLE_METHOD#event?" do
+ describe "WIN32OLE::Method#event?" do
before :each do
- ole_type = WIN32OLE_TYPE.new("System Monitor Control", "SystemMonitor")
- @on_dbl_click_method = WIN32OLE_METHOD.new(ole_type, "OnDblClick")
+ ole_type = WIN32OLE::Type.new("System Monitor Control", "SystemMonitor")
+ @on_dbl_click_method = WIN32OLE::Method.new(ole_type, "OnDblClick")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb
index d1c5ee3be2..83f34b9c10 100644
--- a/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb
@@ -2,12 +2,12 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#helpcontext" do
+ describe "WIN32OLE::Method#helpcontext" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- @get_file_version = WIN32OLE_METHOD.new(ole_type, "GetFileVersion")
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ @get_file_version = WIN32OLE::Method.new(ole_type, "GetFileVersion")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb
index 59dad9244c..9cf9d63d3b 100644
--- a/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#helpfile" do
+ describe "WIN32OLE::Method#helpfile" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb
index b2f24ba151..5ae4a5e090 100644
--- a/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#helpstring" do
+ describe "WIN32OLE::Method#helpstring" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb
index d7fedf0d36..06acbb58a5 100644
--- a/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#invkind" do
+ describe "WIN32OLE::Method#invkind" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb b/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb
index d5536fd17b..0e97ec3305 100644
--- a/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#invoke_kind" do
+ describe "WIN32OLE::Method#invoke_kind" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/name_spec.rb b/spec/ruby/library/win32ole/win32ole_method/name_spec.rb
index 477b820f4d..6e2e233a62 100644
--- a/spec/ruby/library/win32ole/win32ole_method/name_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/name_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#name" do
+ describe "WIN32OLE::Method#name" do
it_behaves_like :win32ole_method_name, :name
end
diff --git a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb
index 4e427421b9..46186ae566 100644
--- a/spec/ruby/library/win32ole/win32ole_method/new_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/new_spec.rb
@@ -2,31 +2,31 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD.new" do
+ describe "WIN32OLE::Method.new" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
it "raises TypeError when given non-strings" do
- -> { WIN32OLE_METHOD.new(1, 2) }.should raise_error TypeError
+ -> { WIN32OLE::Method.new(1, 2) }.should raise_error TypeError
end
it "raises ArgumentError if only 1 argument is given" do
- -> { WIN32OLE_METHOD.new("hello") }.should raise_error ArgumentError
- -> { WIN32OLE_METHOD.new(@ole_type) }.should raise_error ArgumentError
+ -> { WIN32OLE::Method.new("hello") }.should raise_error ArgumentError
+ -> { WIN32OLE::Method.new(@ole_type) }.should raise_error ArgumentError
end
- it "returns a valid WIN32OLE_METHOD object" do
- WIN32OLE_METHOD.new(@ole_type, "Open").should be_kind_of WIN32OLE_METHOD
- WIN32OLE_METHOD.new(@ole_type, "open").should be_kind_of WIN32OLE_METHOD
+ it "returns a valid WIN32OLE::Method object" do
+ WIN32OLE::Method.new(@ole_type, "Open").should be_kind_of WIN32OLE::Method
+ WIN32OLE::Method.new(@ole_type, "open").should be_kind_of WIN32OLE::Method
end
- it "raises WIN32OLERuntimeError if the method does not exist" do
- -> { WIN32OLE_METHOD.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLERuntimeError
+ it "raises WIN32OLE::RuntimeError if the method does not exist" do
+ -> { WIN32OLE::Method.new(@ole_type, "NonexistentMethod") }.should raise_error WIN32OLE::RuntimeError
end
it "raises TypeError if second argument is not a String" do
- -> { WIN32OLE_METHOD.new(@ole_type, 5) }.should raise_error TypeError
+ -> { WIN32OLE::Method.new(@ole_type, 5) }.should raise_error TypeError
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb
index b3da9a8303..3c80cb3c2a 100644
--- a/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#offset_vtbl" do
+ describe "WIN32OLE::Method#offset_vtbl" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb
index 09fb0eb5ac..0b1b4595a3 100644
--- a/spec/ruby/library/win32ole/win32ole_method/params_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/params_spec.rb
@@ -2,12 +2,12 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#params" do
+ describe "WIN32OLE::Method#params" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
@@ -19,8 +19,8 @@ platform_is :windows do
@m_file_name.params.should be_empty
end
- it "returns 4-element array of WIN32OLE_PARAM for Shell's 'BrowseForFolder' method" do
- @m_browse_for_folder.params.all? { |p| p.kind_of? WIN32OLE_PARAM }.should be_true
+ it "returns 4-element array of WIN32OLE::Param for Shell's 'BrowseForFolder' method" do
+ @m_browse_for_folder.params.all? { |p| p.kind_of? WIN32OLE::Param }.should be_true
@m_browse_for_folder.params.size == 4
end
diff --git a/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb
index 582a5951d5..c3725bfef2 100644
--- a/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#return_type_detail" do
+ describe "WIN32OLE::Method#return_type_detail" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb
index dd8add402d..9e5a1eb1df 100644
--- a/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#return_type" do
+ describe "WIN32OLE::Method#return_type" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb b/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb
index 3fca3d54ed..34fd135b8c 100644
--- a/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#return_vtype" do
+ describe "WIN32OLE::Method#return_vtype" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb
index ddaff4011b..7e2197ca5a 100644
--- a/spec/ruby/library/win32ole/win32ole_method/shared/name.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/shared/name.rb
@@ -3,8 +3,8 @@ platform_is :windows do
describe :win32ole_method_name, shared: true do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
- @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "File")
+ @m_file_name = WIN32OLE::Method.new(ole_type, "name")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb
index fe9facb53a..38cb21ccef 100644
--- a/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#size_opt_params" do
+ describe "WIN32OLE::Method#size_opt_params" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb b/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb
index 8ea6e61e7d..5d0a35a0ef 100644
--- a/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#size_params" do
+ describe "WIN32OLE::Method#size_params" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb
index 11107a77fc..cdcc4525b1 100644
--- a/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#name" do
+ describe "WIN32OLE::Method#name" do
it_behaves_like :win32ole_method_name, :to_s
end
diff --git a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb
index d1a50523fc..2f02c15c8b 100644
--- a/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_method/visible_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_METHOD#visible?" do
+ describe "WIN32OLE::Method#visible?" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ @m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb
index 44bd3d7fd3..a37b03866d 100644
--- a/spec/ruby/library/win32ole/win32ole_param/default_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/default_spec.rb
@@ -2,14 +2,14 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#default" do
+ describe "WIN32OLE::Param#default" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ m_browse_for_folder = WIN32OLE::Method.new(ole_type, "BrowseForFolder")
@params = m_browse_for_folder.params
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
@@ -17,7 +17,7 @@ platform_is :windows do
-> { @params[0].default(1) }.should raise_error ArgumentError
end
- it "returns nil for each of WIN32OLE_PARAM for Shell's 'BrowseForFolder' method" do
+ it "returns nil for each of WIN32OLE::Param for Shell's 'BrowseForFolder' method" do
@params.each do |p|
p.default.should be_nil
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb
index e9134b1df8..d7e27d7739 100644
--- a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#input?" do
+ describe "WIN32OLE::Param#input?" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/name_spec.rb b/spec/ruby/library/win32ole/win32ole_param/name_spec.rb
index 67a8955ba4..2c3474ffb3 100644
--- a/spec/ruby/library/win32ole/win32ole_param/name_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/name_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#name" do
+ describe "WIN32OLE::Param#name" do
it_behaves_like :win32ole_param_name, :name
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb
index f05455e3f1..e3379dbf3e 100644
--- a/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#ole_type_detail" do
+ describe "WIN32OLE::Param#ole_type_detail" do
before :each do
- ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile")
+ ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb
index 1467130e03..a7b6666807 100644
--- a/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#ole_type" do
+ describe "WIN32OLE::Param#ole_type" do
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type, "CopyFile")
+ ole_type = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb
index b39ee41179..50e95fc77f 100644
--- a/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/optional_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#optional?" do
+ describe "WIN32OLE::Param#optional?" do
before :each do
- ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile")
+ ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb
index dd613dd29a..fa4a09ea0c 100644
--- a/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/retval_spec.rb
@@ -2,10 +2,10 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#retval?" do
+ describe "WIN32OLE::Param#retval?" do
before :each do
- ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile")
+ ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb
index 043bc32856..56ff24ddc8 100644
--- a/spec/ruby/library/win32ole/win32ole_param/shared/name.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/shared/name.rb
@@ -3,8 +3,8 @@ platform_is :windows do
describe :win32ole_param_name, shared: true do
before :each do
- ole_type_detail = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "FileSystemObject")
- m_copyfile = WIN32OLE_METHOD.new(ole_type_detail, "CopyFile")
+ ole_type_detail = WIN32OLE::Type.new("Microsoft Scripting Runtime", "FileSystemObject")
+ m_copyfile = WIN32OLE::Method.new(ole_type_detail, "CopyFile")
@param_overwritefiles = m_copyfile.params[2]
end
diff --git a/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb
index e9153a2eb2..c59f426692 100644
--- a/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_PARAM#to_s" do
+ describe "WIN32OLE::Param#to_s" do
it_behaves_like :win32ole_param_name, :to_s
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb b/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb
index abdf8d34b9..e574a945ad 100644
--- a/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/guid_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#guid for Shell Controls" do
+ describe "WIN32OLE::Type#guid for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb
index eee23abc56..35911fec52 100644
--- a/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#helpcontext for Shell Controls" do
+ describe "WIN32OLE::Type#helpcontext for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb
index 3a0a9ead94..7bd61a1c40 100644
--- a/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#helpfile for Shell Controls" do
+ describe "WIN32OLE::Type#helpfile for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb b/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb
index 9ab0004668..940475b25e 100644
--- a/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#helpstring for Shell Controls" do
+ describe "WIN32OLE::Type#helpstring for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb b/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb
index 7d2731f778..598e5bcef8 100644
--- a/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#major_version for Shell Controls" do
+ describe "WIN32OLE::Type#major_version for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb b/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb
index 3904e78d42..59cfb94012 100644
--- a/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#minor_version for Shell Controls" do
+ describe "WIN32OLE::Type#minor_version for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/name_spec.rb b/spec/ruby/library/win32ole/win32ole_type/name_spec.rb
index d76998d7dc..4cc3426872 100644
--- a/spec/ruby/library/win32ole/win32ole_type/name_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/name_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#name" do
+ describe "WIN32OLE::Type#name" do
it_behaves_like :win32ole_type_name, :name
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb
index cc691ffa67..185a235940 100644
--- a/spec/ruby/library/win32ole/win32ole_type/new_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/new_spec.rb
@@ -2,39 +2,39 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE.new" do
+ describe "WIN32OLE::Type.new" do
it "raises ArgumentError with no argument" do
- -> { WIN32OLE_TYPE.new }.should raise_error ArgumentError
+ -> { WIN32OLE::Type.new }.should raise_error ArgumentError
end
it "raises ArgumentError with invalid string" do
- -> { WIN32OLE_TYPE.new("foo") }.should raise_error ArgumentError
+ -> { WIN32OLE::Type.new("foo") }.should raise_error ArgumentError
end
it "raises TypeError if second argument is not a String" do
- -> { WIN32OLE_TYPE.new(1,2) }.should raise_error TypeError
+ -> { WIN32OLE::Type.new(1,2) }.should raise_error TypeError
-> {
- WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation',2)
+ WIN32OLE::Type.new('Microsoft Shell Controls And Automation',2)
}.should raise_error TypeError
end
- it "raise WIN32OLERuntimeError if OLE object specified is not found" do
+ it "raise WIN32OLE::RuntimeError if OLE object specified is not found" do
-> {
- WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','foo')
- }.should raise_error WIN32OLERuntimeError
+ WIN32OLE::Type.new('Microsoft Shell Controls And Automation','foo')
+ }.should raise_error WIN32OLE::RuntimeError
-> {
- WIN32OLE_TYPE.new('Microsoft Shell Controls And Automation','Application')
- }.should raise_error WIN32OLERuntimeError
+ WIN32OLE::Type.new('Microsoft Shell Controls And Automation','Application')
+ }.should raise_error WIN32OLE::RuntimeError
end
- it "creates WIN32OLE_TYPE object from name and valid type" do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
- ole_type.should be_kind_of WIN32OLE_TYPE
+ it "creates WIN32OLE::Type object from name and valid type" do
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
+ ole_type.should be_kind_of WIN32OLE::Type
end
- it "creates WIN32OLE_TYPE object from CLSID and valid type" do
- ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
- ole_type2.should be_kind_of WIN32OLE_TYPE
+ it "creates WIN32OLE::Type object from CLSID and valid type" do
+ ole_type2 = WIN32OLE::Type.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
+ ole_type2.should be_kind_of WIN32OLE::Type
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb
index a3a1d4ac58..ed14e37a95 100644
--- a/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE.ole_classes for Shell Controls" do
+ describe "WIN32OLE::Type.ole_classes for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
@@ -12,7 +12,7 @@ platform_is :windows do
end
it "returns array of WIN32OLE_TYPEs" do
- WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation").all? {|e| e.kind_of? WIN32OLE_TYPE }.should be_true
+ WIN32OLE::Type.ole_classes("Microsoft Shell Controls And Automation").all? {|e| e.kind_of? WIN32OLE::Type }.should be_true
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb
index 3b99b97a61..0c031abaa6 100644
--- a/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#ole_methods for Shell Controls" do
+ describe "WIN32OLE::Type#ole_methods for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
@@ -12,7 +12,7 @@ platform_is :windows do
end
it "returns an Integer" do
- @ole_type.ole_methods.all? { |m| m.kind_of? WIN32OLE_METHOD }.should be_true
+ @ole_type.ole_methods.all? { |m| m.kind_of? WIN32OLE::Method }.should be_true
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb
index 24292b1c4f..49c1902f8c 100644
--- a/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#ole_type for Shell Controls" do
+ describe "WIN32OLE::Type#ole_type for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb b/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb
index 340fdb34e8..9a700426d9 100644
--- a/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/progid_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#progid for Shell Controls" do
+ describe "WIN32OLE::Type#progid for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb
index 793535b48d..b1b57960cd 100644
--- a/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/progids_spec.rb
@@ -2,13 +2,13 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE.progids" do
+ describe "WIN32OLE::Type.progids" do
it "raises ArgumentError if an argument is given" do
- -> { WIN32OLE_TYPE.progids(1) }.should raise_error ArgumentError
+ -> { WIN32OLE::Type.progids(1) }.should raise_error ArgumentError
end
it "returns an array containing 'Shell.Explorer'" do
- WIN32OLE_TYPE.progids().include?('Shell.Explorer').should be_true
+ WIN32OLE::Type.progids().include?('Shell.Explorer').should be_true
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/shared/name.rb b/spec/ruby/library/win32ole/win32ole_type/shared/name.rb
index 6f37446b23..efae7aeec1 100644
--- a/spec/ruby/library/win32ole/win32ole_type/shared/name.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/shared/name.rb
@@ -3,7 +3,7 @@ platform_is :windows do
describe :win32ole_type_name, shared: true do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
end
it "raises ArgumentError if argument is given" do
diff --git a/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb b/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb
index 3f89fe702a..3c7651cc1f 100644
--- a/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#src_type for Shell Controls" do
+ describe "WIN32OLE::Type#src_type for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb b/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb
index 9f086a5a35..03a0344fdb 100644
--- a/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb
@@ -4,7 +4,7 @@ require_relative 'shared/name'
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#to_s" do
+ describe "WIN32OLE::Type#to_s" do
it_behaves_like :win32ole_type_name, :to_s
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb
index 391d505e01..8b62f3e2eb 100644
--- a/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#typekind for Shell Controls" do
+ describe "WIN32OLE::Type#typekind for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb
index a487208caa..71d7cf00f7 100644
--- a/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE.typelibs for Shell Controls" do
+ describe "WIN32OLE::Type.typelibs for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
@@ -12,11 +12,11 @@ platform_is :windows do
end
it "raises ArgumentError if any argument is give" do
- -> { WIN32OLE_TYPE.typelibs(1) }.should raise_error ArgumentError
+ -> { WIN32OLE::Type.typelibs(1) }.should raise_error ArgumentError
end
it "returns array of type libraries" do
- WIN32OLE_TYPE.typelibs().include?("Microsoft Shell Controls And Automation").should be_true
+ WIN32OLE::Type.typelibs().include?("Microsoft Shell Controls And Automation").should be_true
end
end
diff --git a/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb b/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb
index 7f61b8af95..b1a407523c 100644
--- a/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/variables_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#variables for Shell Controls" do
+ describe "WIN32OLE::Type#variables for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb
index 99e34edcdd..05c54c8838 100644
--- a/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_type/visible_spec.rb
@@ -2,9 +2,9 @@ require_relative "../../../spec_helper"
platform_is :windows do
require 'win32ole'
- describe "WIN32OLE_TYPE#visible? for Shell Controls" do
+ describe "WIN32OLE::Type#visible? for Shell Controls" do
before :each do
- @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
+ @ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "Shell")
end
after :each do
diff --git a/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb
index 7a9c791494..89576ceedc 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb
@@ -6,7 +6,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb
index 03a9aa4c74..441011f1e7 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb
@@ -6,7 +6,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb
index 033e830fac..d02942ce0a 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/shared/name.rb
@@ -5,7 +5,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb
index b7849793c5..d26273ebed 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/value_spec.rb
@@ -6,7 +6,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb
index 7a79d32ddc..17bc47160a 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb
@@ -6,7 +6,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb
index 9d7b8238c8..c5f8164509 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb
@@ -7,7 +7,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb
index 60252e8139..ba53a81de0 100644
--- a/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb
+++ b/spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb
@@ -6,7 +6,7 @@ platform_is :windows do
# not sure how WIN32OLE_VARIABLE objects are supposed to be generated
# WIN32OLE_VARIABLE.new even seg faults in some cases
before :each do
- ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
+ ole_type = WIN32OLE::Type.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
@var = ole_type.variables[0]
end
diff --git a/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb
index 251cec44bb..375ee3c765 100644
--- a/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb
+++ b/spec/ruby/library/zlib/inflate/set_dictionary_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative '../../../spec_helper'
require 'zlib'
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb
index 9c35017e21..7e87859856 100644
--- a/spec/ruby/optional/capi/array_spec.rb
+++ b/spec/ruby/optional/capi/array_spec.rb
@@ -343,37 +343,39 @@ describe "C-API Array function" do
end
end
- describe "rb_iterate" do
- it "calls an callback function as a block passed to an method" do
- s = [1,2,3,4]
- s2 = @s.rb_iterate(s)
+ ruby_version_is ""..."4.0" do
+ describe "rb_iterate" do
+ it "calls an callback function as a block passed to an method" do
+ s = [1,2,3,4]
+ s2 = @s.rb_iterate(s)
- s2.should == s
+ s2.should == s
- # Make sure they're different objects
- s2.equal?(s).should be_false
- end
+ # Make sure they're different objects
+ s2.equal?(s).should be_false
+ end
- it "calls a function with the other function available as a block" do
- h = {a: 1, b: 2}
+ it "calls a function with the other function available as a block" do
+ h = {a: 1, b: 2}
- @s.rb_iterate_each_pair(h).sort.should == [1,2]
- end
+ @s.rb_iterate_each_pair(h).sort.should == [1,2]
+ end
- it "calls a function which can yield into the original block" do
- s2 = []
+ it "calls a function which can yield into the original block" do
+ s2 = []
- o = Object.new
- def o.each
- yield 1
- yield 2
- yield 3
- yield 4
- end
+ o = Object.new
+ def o.each
+ yield 1
+ yield 2
+ yield 3
+ yield 4
+ end
- @s.rb_iterate_then_yield(o) { |x| s2 << x }
+ @s.rb_iterate_then_yield(o) { |x| s2 << x }
- s2.should == [1,2,3,4]
+ s2.should == [1,2,3,4]
+ end
end
end
diff --git a/spec/ruby/optional/capi/binding_spec.rb b/spec/ruby/optional/capi/binding_spec.rb
index 2165705457..5d0ef2efb8 100644
--- a/spec/ruby/optional/capi/binding_spec.rb
+++ b/spec/ruby/optional/capi/binding_spec.rb
@@ -8,21 +8,9 @@ describe "CApiBindingSpecs" do
end
describe "Kernel#binding" do
- ruby_version_is '3.2' do
- it "raises when called from C" do
- foo = 14
- -> { @b.get_binding }.should raise_error(RuntimeError)
- end
- end
-
- ruby_version_is ''...'3.2' do
- it "gives the top-most Ruby binding when called from C" do
- foo = 14
- b = @b.get_binding
- b.local_variable_get(:foo).should == 14
- b.local_variable_set :foo, 12
- foo.should == 12
- end
+ it "raises when called from C" do
+ foo = 14
+ -> { @b.get_binding }.should raise_error(RuntimeError)
end
end
end
diff --git a/spec/ruby/optional/capi/digest_spec.rb b/spec/ruby/optional/capi/digest_spec.rb
new file mode 100644
index 0000000000..65c5ecebb1
--- /dev/null
+++ b/spec/ruby/optional/capi/digest_spec.rb
@@ -0,0 +1,103 @@
+require_relative 'spec_helper'
+
+begin
+ require 'fiddle'
+rescue LoadError
+ return
+end
+
+load_extension('digest')
+
+describe "C-API Digest functions" do
+ before :each do
+ @s = CApiDigestSpecs.new
+ end
+
+ describe "rb_digest_make_metadata" do
+ before :each do
+ @metadata = @s.rb_digest_make_metadata
+ end
+
+ it "should store the block length" do
+ @s.block_length(@metadata).should == 40
+ end
+
+ it "should store the digest length" do
+ @s.digest_length(@metadata).should == 20
+ end
+
+ it "should store the context size" do
+ @s.context_size(@metadata).should == 129
+ end
+ end
+
+ describe "digest plugin" do
+ before :each do
+ @s = CApiDigestSpecs.new
+ @digest = Digest::TestDigest.new
+
+ # A pointer to the CTX type defined in the extension for this spec. Digest does not make the context directly
+ # accessible as part of its API. However, to ensure we are properly loading the plugin, it's useful to have
+ # direct access to the context pointer to verify its contents.
+ @context = Fiddle::Pointer.new(@s.context(@digest))
+ end
+
+ it "should report the block length" do
+ @digest.block_length.should == 40
+ end
+
+ it "should report the digest length" do
+ @digest.digest_length.should == 20
+ end
+
+ it "should initialize the context" do
+ # Our test plugin always writes the string "Initialized\n" when its init function is called.
+ verify_context("Initialized\n")
+ end
+
+ it "should update the digest" do
+ @digest.update("hello world")
+
+ # Our test plugin always writes the string "Updated: <data>\n" when its update function is called.
+ current = "Initialized\nUpdated: hello world"
+ verify_context(current)
+
+ @digest << "blah"
+
+ current = "Initialized\nUpdated: hello worldUpdated: blah"
+ verify_context(current)
+ end
+
+ it "should finalize the digest" do
+ @digest.update("")
+
+ finish_string = @digest.instance_eval { finish }
+
+ # We expect the plugin to write out the last `@digest.digest_length` bytes, followed by the string "Finished\n".
+ #
+ finish_string.should == "d\nUpdated: Finished\n"
+ finish_string.encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "should reset the context" do
+ @digest.update("foo")
+ verify_context("Initialized\nUpdated: foo")
+
+ @digest.reset
+
+ # The context will be recreated as a result of the `reset` so we must fetch the latest context pointer.
+ @context = Fiddle::Pointer.new(@s.context(@digest))
+
+ verify_context("Initialized\n")
+ end
+
+ def verify_context(current_body)
+ # In the CTX type, the length of the current context contents is stored in the first byte.
+ byte_count = @context[0]
+ byte_count.should == current_body.bytesize
+
+ # After the size byte follows a string.
+ @context[1, byte_count].should == current_body
+ end
+ end
+end
diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb
index db693f041b..c14983c7ea 100644
--- a/spec/ruby/optional/capi/encoding_spec.rb
+++ b/spec/ruby/optional/capi/encoding_spec.rb
@@ -724,25 +724,25 @@ describe "C-API Encoding function" do
end
describe "rb_define_dummy_encoding" do
+ run = 0
+
it "defines the dummy encoding" do
- @s.rb_define_dummy_encoding("FOO")
- enc = Encoding.find("FOO")
+ @s.rb_define_dummy_encoding("FOO#{run += 1}")
+ enc = Encoding.find("FOO#{run}")
enc.should.dummy?
end
it "returns the index of the dummy encoding" do
- index = @s.rb_define_dummy_encoding("BAR")
+ index = @s.rb_define_dummy_encoding("BAR#{run += 1}")
index.should == Encoding.list.size - 1
end
- ruby_version_is "3.2" do
- it "raises EncodingError if too many encodings" do
- code = <<-RUBY
- require #{extension_path.dump}
- 1_000.times {|i| CApiEncodingSpecs.new.rb_define_dummy_encoding("R_\#{i}") }
- RUBY
- ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)')
- end
+ it "raises EncodingError if too many encodings" do
+ code = <<-RUBY
+ require #{extension_path.dump}
+ 1_000.times {|i| CApiEncodingSpecs.new.rb_define_dummy_encoding("R_\#{i}") }
+ RUBY
+ ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)')
end
end
end
diff --git a/spec/ruby/optional/capi/exception_spec.rb b/spec/ruby/optional/capi/exception_spec.rb
index 5bb60608b2..5bc8e26c62 100644
--- a/spec/ruby/optional/capi/exception_spec.rb
+++ b/spec/ruby/optional/capi/exception_spec.rb
@@ -100,6 +100,26 @@ describe "C-API Exception function" do
end
end
+ describe "rb_error_frozen_object" do
+ it "raises a FrozenError regardless of the object's frozen state" do
+ # The type of the argument we supply doesn't matter. The choice here is arbitrary and we only change the type
+ # of the argument to ensure the exception messages are set correctly.
+ -> { @s.rb_error_frozen_object(Array.new) }.should raise_error(FrozenError, "can't modify frozen Array: []")
+ -> { @s.rb_error_frozen_object(Array.new.freeze) }.should raise_error(FrozenError, "can't modify frozen Array: []")
+ end
+
+ it "properly handles recursive rb_error_frozen_object calls" do
+ klass = Class.new(Object)
+ object = klass.new
+ s = @s
+ klass.define_method :inspect do
+ s.rb_error_frozen_object(object)
+ end
+
+ -> { @s.rb_error_frozen_object(object) }.should raise_error(FrozenError, "can't modify frozen #{klass}: ...")
+ end
+ end
+
describe "rb_syserr_new" do
it "returns system error with default message when passed message is NULL" do
exception = @s.rb_syserr_new(Errno::ENOENT::Errno, nil)
diff --git a/spec/ruby/optional/capi/ext/array_spec.c b/spec/ruby/optional/capi/ext/array_spec.c
index 2347798bb4..628c4df9d7 100644
--- a/spec/ruby/optional/capi/ext/array_spec.c
+++ b/spec/ruby/optional/capi/ext/array_spec.c
@@ -196,6 +196,7 @@ static VALUE copy_ary(RB_BLOCK_CALL_FUNC_ARGLIST(el, new_ary)) {
return rb_ary_push(new_ary, el);
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE array_spec_rb_iterate(VALUE self, VALUE ary) {
VALUE new_ary = rb_ary_new();
@@ -203,6 +204,7 @@ static VALUE array_spec_rb_iterate(VALUE self, VALUE ary) {
return new_ary;
}
+#endif
static VALUE array_spec_rb_block_call(VALUE self, VALUE ary) {
VALUE new_ary = rb_ary_new();
@@ -216,6 +218,7 @@ static VALUE sub_pair(RB_BLOCK_CALL_FUNC_ARGLIST(el, holder)) {
return rb_ary_push(holder, rb_ary_entry(el, 1));
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE each_pair(VALUE obj) {
return rb_funcall(obj, rb_intern("each_pair"), 0);
}
@@ -227,6 +230,7 @@ static VALUE array_spec_rb_iterate_each_pair(VALUE self, VALUE obj) {
return new_ary;
}
+#endif
static VALUE array_spec_rb_block_call_each_pair(VALUE self, VALUE obj) {
VALUE new_ary = rb_ary_new();
@@ -241,10 +245,12 @@ static VALUE iter_yield(RB_BLOCK_CALL_FUNC_ARGLIST(el, ary)) {
return Qnil;
}
+#ifndef RUBY_VERSION_IS_4_0
static VALUE array_spec_rb_iterate_then_yield(VALUE self, VALUE obj) {
rb_iterate(rb_each, obj, iter_yield, obj);
return Qnil;
}
+#endif
static VALUE array_spec_rb_block_call_then_yield(VALUE self, VALUE obj) {
rb_block_call(obj, rb_intern("each"), 0, 0, iter_yield, obj);
@@ -308,9 +314,11 @@ void Init_array_spec(void) {
rb_define_method(cls, "rb_ary_plus", array_spec_rb_ary_plus, 2);
rb_define_method(cls, "rb_ary_unshift", array_spec_rb_ary_unshift, 2);
rb_define_method(cls, "rb_assoc_new", array_spec_rb_assoc_new, 2);
+#ifndef RUBY_VERSION_IS_4_0
rb_define_method(cls, "rb_iterate", array_spec_rb_iterate, 1);
rb_define_method(cls, "rb_iterate_each_pair", array_spec_rb_iterate_each_pair, 1);
rb_define_method(cls, "rb_iterate_then_yield", array_spec_rb_iterate_then_yield, 1);
+#endif
rb_define_method(cls, "rb_block_call", array_spec_rb_block_call, 1);
rb_define_method(cls, "rb_block_call_each_pair", array_spec_rb_block_call_each_pair, 1);
rb_define_method(cls, "rb_block_call_then_yield", array_spec_rb_block_call_then_yield, 1);
diff --git a/spec/ruby/optional/capi/ext/class_spec.c b/spec/ruby/optional/capi/ext/class_spec.c
index c13f02ecf2..8ac0e7a93f 100644
--- a/spec/ruby/optional/capi/ext/class_spec.c
+++ b/spec/ruby/optional/capi/ext/class_spec.c
@@ -65,11 +65,9 @@ static VALUE class_spec_rb_class_new_instance(VALUE self, VALUE args, VALUE klas
return rb_class_new_instance(RARRAY_LENINT(args), RARRAY_PTR(args), klass);
}
-#ifdef RUBY_VERSION_IS_3_0
static VALUE class_spec_rb_class_new_instance_kw(VALUE self, VALUE args, VALUE klass) {
return rb_class_new_instance_kw(RARRAY_LENINT(args), RARRAY_PTR(args), klass, RB_PASS_KEYWORDS);
}
-#endif
static VALUE class_spec_rb_class_real(VALUE self, VALUE object) {
if (rb_type_p(object, T_FIXNUM)) {
@@ -160,9 +158,7 @@ void Init_class_spec(void) {
rb_define_method(cls, "rb_class_private_instance_methods", class_spec_rb_class_private_instance_methods, -1);
rb_define_method(cls, "rb_class_new", class_spec_rb_class_new, 1);
rb_define_method(cls, "rb_class_new_instance", class_spec_rb_class_new_instance, 2);
-#ifdef RUBY_VERSION_IS_3_0
rb_define_method(cls, "rb_class_new_instance_kw", class_spec_rb_class_new_instance_kw, 2);
-#endif
rb_define_method(cls, "rb_class_real", class_spec_rb_class_real, 1);
rb_define_method(cls, "rb_class_get_superclass", class_spec_rb_class_get_superclass, 1);
rb_define_method(cls, "rb_class_superclass", class_spec_rb_class_superclass, 1);
diff --git a/spec/ruby/optional/capi/ext/constants_spec.c b/spec/ruby/optional/capi/ext/constants_spec.c
index 9aee8db37f..05819ea476 100644
--- a/spec/ruby/optional/capi/ext/constants_spec.c
+++ b/spec/ruby/optional/capi/ext/constants_spec.c
@@ -14,9 +14,6 @@ defconstfunc(rb_cBinding)
defconstfunc(rb_cClass)
defconstfunc(rb_cComplex)
defconstfunc(rb_mComparable)
-#ifndef RUBY_VERSION_IS_3_0
-defconstfunc(rb_cData)
-#endif
defconstfunc(rb_cDir)
defconstfunc(rb_cEncoding)
defconstfunc(rb_mEnumerable)
@@ -97,9 +94,6 @@ void Init_constants_spec(void) {
rb_define_method(cls, "rb_cClass", constants_spec_rb_cClass, 0);
rb_define_method(cls, "rb_cComplex", constants_spec_rb_cComplex, 0);
rb_define_method(cls, "rb_mComparable", constants_spec_rb_mComparable, 0);
- #ifndef RUBY_VERSION_IS_3_0
- rb_define_method(cls, "rb_cData", constants_spec_rb_cData, 0);
- #endif
rb_define_method(cls, "rb_cDir", constants_spec_rb_cDir, 0);
rb_define_method(cls, "rb_cEncoding", constants_spec_rb_cEncoding, 0);
rb_define_method(cls, "rb_mEnumerable", constants_spec_rb_mEnumerable, 0);
diff --git a/spec/ruby/optional/capi/ext/digest_spec.c b/spec/ruby/optional/capi/ext/digest_spec.c
new file mode 100644
index 0000000000..65c8defa20
--- /dev/null
+++ b/spec/ruby/optional/capi/ext/digest_spec.c
@@ -0,0 +1,168 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#include "ruby/digest.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DIGEST_LENGTH 20
+#define BLOCK_LENGTH 40
+
+const char *init_string = "Initialized\n";
+const char *update_string = "Updated: ";
+const char *finish_string = "Finished\n";
+
+#define PAYLOAD_SIZE 128
+
+typedef struct CTX {
+ uint8_t pos;
+ char payload[PAYLOAD_SIZE];
+} CTX;
+
+void* context = NULL;
+
+int digest_spec_plugin_init(void *raw_ctx) {
+ // Make the context accessible to tests. This isn't safe, but there's no way to access the context otherwise.
+ context = raw_ctx;
+
+ struct CTX *ctx = (struct CTX *)raw_ctx;
+ size_t len = strlen(init_string);
+
+ // Clear the payload since this init function will be invoked as part of the `reset` operation.
+ memset(ctx->payload, 0, PAYLOAD_SIZE);
+
+ // Write a simple value we can verify in tests.
+ // This is not what a real digest would do, but we're using a dummy digest plugin to test interactions.
+ memcpy(ctx->payload, init_string, len);
+ ctx->pos = (uint8_t) len;
+
+ return 1;
+}
+
+void digest_spec_plugin_update(void *raw_ctx, unsigned char *ptr, size_t size) {
+ struct CTX *ctx = (struct CTX *)raw_ctx;
+ size_t update_str_len = strlen(update_string);
+
+ if (ctx->pos + update_str_len + size >= PAYLOAD_SIZE) {
+ rb_raise(rb_eRuntimeError, "update size too large; reset the digest and write fewer updates");
+ }
+
+ // Write the supplied value to the payload so it can be easily verified in test.
+ // This is not what a real digest would do, but we're using a dummy digest plugin to test interactions.
+ memcpy(ctx->payload + ctx->pos, update_string, update_str_len);
+ ctx->pos += update_str_len;
+
+ memcpy(ctx->payload + ctx->pos, ptr, size);
+ ctx->pos += size;
+
+ return;
+}
+
+int digest_spec_plugin_finish(void *raw_ctx, unsigned char *ptr) {
+ struct CTX *ctx = (struct CTX *)raw_ctx;
+ size_t finish_string_len = strlen(finish_string);
+
+ // We're always going to write DIGEST_LENGTH bytes. In a real plugin, this would be the digest value. Here we
+ // write out a text string in order to make validation in tests easier.
+ //
+ // In order to delineate the output more clearly from an `Digest#update` call, we always write out the
+ // `finish_string` message. That leaves `DIGEST_LENGTH - finish_string_len` bytes to read out of the context.
+ size_t context_bytes = DIGEST_LENGTH - finish_string_len;
+
+ memcpy(ptr, ctx->payload + (ctx->pos - context_bytes), context_bytes);
+ memcpy(ptr + context_bytes, finish_string, finish_string_len);
+
+ return 1;
+}
+
+static const rb_digest_metadata_t metadata = {
+ // The RUBY_DIGEST_API_VERSION value comes from ruby/digest.h and may vary based on the Ruby being tested. Since
+ // it isn't publicly exposed in the digest gem, we ignore for these tests. Either the test hard-codes an expected
+ // value and is subject to breaking depending on the Ruby being run or we publicly expose `RUBY_DIGEST_API_VERSION`,
+ // in which case the test would pass trivially.
+ RUBY_DIGEST_API_VERSION,
+ DIGEST_LENGTH,
+ BLOCK_LENGTH,
+ sizeof(CTX),
+ (rb_digest_hash_init_func_t) digest_spec_plugin_init,
+ (rb_digest_hash_update_func_t) digest_spec_plugin_update,
+ (rb_digest_hash_finish_func_t) digest_spec_plugin_finish,
+};
+
+// The `get_metadata_ptr` function is not publicly available in the digest gem. However, we need to use
+// to extract the `rb_digest_metadata_t*` value set up by the plugin so we reproduce and adjust the
+// definition here.
+//
+// Taken and adapted from https://github.com/ruby/digest/blob/v3.2.0/ext/digest/digest.c#L558-L568
+static rb_digest_metadata_t * get_metadata_ptr(VALUE obj) {
+ rb_digest_metadata_t *algo;
+
+#ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
+ // In the digest gem there is an additional data type check performed before reading the value out.
+ // Since the type definition isn't public, we can't use it as part of a type check here so we omit it.
+ // This is safe to do because this code is intended to only load digest plugins written as part of this test suite.
+ algo = (rb_digest_metadata_t *) RTYPEDDATA_DATA(obj);
+#else
+# undef RUBY_UNTYPED_DATA_WARNING
+# define RUBY_UNTYPED_DATA_WARNING 0
+ Data_Get_Struct(obj, rb_digest_metadata_t, algo);
+#endif
+
+ return algo;
+}
+
+VALUE digest_spec_rb_digest_make_metadata(VALUE self) {
+ return rb_digest_make_metadata(&metadata);
+}
+
+VALUE digest_spec_block_length(VALUE self, VALUE meta) {
+ rb_digest_metadata_t* algo = get_metadata_ptr(meta);
+
+ return SIZET2NUM(algo->block_len);
+}
+
+VALUE digest_spec_digest_length(VALUE self, VALUE meta) {
+ rb_digest_metadata_t* algo = get_metadata_ptr(meta);
+
+ return SIZET2NUM(algo->digest_len);
+}
+
+VALUE digest_spec_context_size(VALUE self, VALUE meta) {
+ rb_digest_metadata_t* algo = get_metadata_ptr(meta);
+
+ return SIZET2NUM(algo->ctx_size);
+}
+
+#ifndef PTR2NUM
+#define PTR2NUM(x) (rb_int2inum((intptr_t)(void *)(x)))
+#endif
+
+VALUE digest_spec_context(VALUE self, VALUE digest) {
+ return PTR2NUM(context);
+}
+
+void Init_digest_spec(void) {
+ VALUE cls;
+
+ cls = rb_define_class("CApiDigestSpecs", rb_cObject);
+ rb_define_method(cls, "rb_digest_make_metadata", digest_spec_rb_digest_make_metadata, 0);
+ rb_define_method(cls, "block_length", digest_spec_block_length, 1);
+ rb_define_method(cls, "digest_length", digest_spec_digest_length, 1);
+ rb_define_method(cls, "context_size", digest_spec_context_size, 1);
+ rb_define_method(cls, "context", digest_spec_context, 1);
+
+ VALUE mDigest, cDigest_Base, cDigest;
+
+ mDigest = rb_define_module("Digest");
+ mDigest = rb_digest_namespace();
+ cDigest_Base = rb_const_get(mDigest, rb_intern_const("Base"));
+
+ cDigest = rb_define_class_under(mDigest, "TestDigest", cDigest_Base);
+ rb_iv_set(cDigest, "metadata", rb_digest_make_metadata(&metadata));
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/spec/ruby/optional/capi/ext/exception_spec.c b/spec/ruby/optional/capi/ext/exception_spec.c
index 0e8347ab0d..c3b94d7bcd 100644
--- a/spec/ruby/optional/capi/ext/exception_spec.c
+++ b/spec/ruby/optional/capi/ext/exception_spec.c
@@ -36,6 +36,13 @@ VALUE exception_spec_rb_set_errinfo(VALUE self, VALUE exc) {
return Qnil;
}
+NORETURN(VALUE exception_spec_rb_error_frozen_object(VALUE self, VALUE object));
+
+VALUE exception_spec_rb_error_frozen_object(VALUE self, VALUE object) {
+ rb_error_frozen_object(object);
+ UNREACHABLE_RETURN(Qnil);
+}
+
VALUE exception_spec_rb_syserr_new(VALUE self, VALUE num, VALUE msg) {
int n = NUM2INT(num);
char *cstr = NULL;
@@ -66,6 +73,7 @@ void Init_exception_spec(void) {
rb_define_method(cls, "rb_exc_new3", exception_spec_rb_exc_new3, 1);
rb_define_method(cls, "rb_exc_raise", exception_spec_rb_exc_raise, 1);
rb_define_method(cls, "rb_set_errinfo", exception_spec_rb_set_errinfo, 1);
+ rb_define_method(cls, "rb_error_frozen_object", exception_spec_rb_error_frozen_object, 1);
rb_define_method(cls, "rb_syserr_new", exception_spec_rb_syserr_new, 2);
rb_define_method(cls, "rb_syserr_new_str", exception_spec_rb_syserr_new_str, 2);
rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1);
diff --git a/spec/ruby/optional/capi/ext/fiber_spec.c b/spec/ruby/optional/capi/ext/fiber_spec.c
index f06a54494e..db54f7ad8c 100644
--- a/spec/ruby/optional/capi/ext/fiber_spec.c
+++ b/spec/ruby/optional/capi/ext/fiber_spec.c
@@ -44,12 +44,10 @@ VALUE fiber_spec_rb_fiber_new(VALUE self) {
return rb_fiber_new(fiber_spec_rb_fiber_new_function, Qnil);
}
-#ifdef RUBY_VERSION_IS_3_1
VALUE fiber_spec_rb_fiber_raise(int argc, VALUE *argv, VALUE self) {
VALUE fiber = argv[0];
return rb_fiber_raise(fiber, argc-1, argv+1);
}
-#endif
void Init_fiber_spec(void) {
VALUE cls = rb_define_class("CApiFiberSpecs", rb_cObject);
@@ -58,10 +56,7 @@ void Init_fiber_spec(void) {
rb_define_method(cls, "rb_fiber_resume", fiber_spec_rb_fiber_resume, 2);
rb_define_method(cls, "rb_fiber_yield", fiber_spec_rb_fiber_yield, 1);
rb_define_method(cls, "rb_fiber_new", fiber_spec_rb_fiber_new, 0);
-
-#ifdef RUBY_VERSION_IS_3_1
rb_define_method(cls, "rb_fiber_raise", fiber_spec_rb_fiber_raise, -1);
-#endif
}
#ifdef __cplusplus
diff --git a/spec/ruby/optional/capi/ext/hash_spec.c b/spec/ruby/optional/capi/ext/hash_spec.c
index 0e5b3d1c0a..653917f2c4 100644
--- a/spec/ruby/optional/capi/ext/hash_spec.c
+++ b/spec/ruby/optional/capi/ext/hash_spec.c
@@ -105,11 +105,9 @@ VALUE hash_spec_rb_hash_new(VALUE self) {
return rb_hash_new();
}
-#ifdef RUBY_VERSION_IS_3_2
VALUE hash_spec_rb_hash_new_capa(VALUE self, VALUE capacity) {
return rb_hash_new_capa(NUM2LONG(capacity));
}
-#endif
VALUE rb_ident_hash_new(void); /* internal.h, used in ripper */
@@ -169,9 +167,7 @@ void Init_hash_spec(void) {
rb_define_method(cls, "rb_hash_lookup2", hash_spec_rb_hash_lookup2, 3);
rb_define_method(cls, "rb_hash_lookup2_default_undef", hash_spec_rb_hash_lookup2_default_undef, 2);
rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0);
-#ifdef RUBY_VERSION_IS_3_2
rb_define_method(cls, "rb_hash_new_capa", hash_spec_rb_hash_new_capa, 1);
-#endif
rb_define_method(cls, "rb_ident_hash_new", hash_spec_rb_ident_hash_new, 0);
rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1);
rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2);
diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c
index cc440e6b07..f3ede15729 100644
--- a/spec/ruby/optional/capi/ext/io_spec.c
+++ b/spec/ruby/optional/capi/ext/io_spec.c
@@ -28,13 +28,7 @@ static int set_non_blocking(int fd) {
}
static int io_spec_get_fd(VALUE io) {
-#ifdef RUBY_VERSION_IS_3_1
return rb_io_descriptor(io);
-#else
- rb_io_t* fp;
- GetOpenFile(io, fp);
- return fp->fd;
-#endif
}
VALUE io_spec_GetOpenFile_fd(VALUE self, VALUE io) {
@@ -143,11 +137,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
errno = saved_errno;
}
-#ifdef RUBY_VERSION_IS_3_1
ret = rb_io_maybe_wait_readable(errno, io, Qnil);
-#else
- ret = rb_io_wait_readable(fd);
-#endif
if (RTEST(read_p)) {
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
@@ -166,22 +156,15 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
}
VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) {
-#ifdef RUBY_VERSION_IS_3_1
int ret = rb_io_maybe_wait_writable(errno, io, Qnil);
-#else
- int ret = rb_io_wait_writable(io_spec_get_fd(io));
-#endif
return ret ? Qtrue : Qfalse;
}
-#ifdef RUBY_VERSION_IS_3_1
VALUE io_spec_rb_io_maybe_wait_writable(VALUE self, VALUE error, VALUE io, VALUE timeout) {
int ret = rb_io_maybe_wait_writable(NUM2INT(error), io, timeout);
return INT2NUM(ret);
}
-#endif
-#ifdef RUBY_VERSION_IS_3_1
#ifdef SET_NON_BLOCKING_FAILS_ALWAYS
NORETURN(VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE timeout, VALUE read_p));
#endif
@@ -224,13 +207,10 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE
UNREACHABLE_RETURN(Qnil);
#endif
}
-#endif
-#ifdef RUBY_VERSION_IS_3_1
VALUE io_spec_rb_io_maybe_wait(VALUE self, VALUE error, VALUE io, VALUE events, VALUE timeout) {
return rb_io_maybe_wait(NUM2INT(error), io, events, timeout);
}
-#endif
VALUE io_spec_rb_thread_wait_fd(VALUE self, VALUE io) {
rb_thread_wait_fd(io_spec_get_fd(io));
@@ -238,7 +218,6 @@ VALUE io_spec_rb_thread_wait_fd(VALUE self, VALUE io) {
}
VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE secs, VALUE usecs) {
-#ifdef RUBY_VERSION_IS_3_0
VALUE timeout = Qnil;
if (!NIL_P(secs)) {
timeout = rb_float_new((double)FIX2INT(secs) + (0.000001 * FIX2INT(usecs)));
@@ -246,15 +225,6 @@ VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE se
VALUE result = rb_io_wait(io, events, timeout);
if (result == Qfalse) return INT2FIX(0);
else return result;
-#else
- struct timeval tv;
- if (!NIL_P(secs)) {
- tv.tv_sec = FIX2INT(secs);
- tv.tv_usec = FIX2INT(usecs);
- }
- int fd = io_spec_get_fd(io);
- return INT2FIX(rb_wait_for_single_fd(fd, FIX2INT(events), NIL_P(secs) ? NULL : &tv));
-#endif
}
VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) {
@@ -409,11 +379,9 @@ void Init_io_spec(void) {
rb_define_method(cls, "rb_io_taint_check", io_spec_rb_io_taint_check, 1);
rb_define_method(cls, "rb_io_wait_readable", io_spec_rb_io_wait_readable, 2);
rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1);
-#ifdef RUBY_VERSION_IS_3_1
rb_define_method(cls, "rb_io_maybe_wait_writable", io_spec_rb_io_maybe_wait_writable, 3);
rb_define_method(cls, "rb_io_maybe_wait_readable", io_spec_rb_io_maybe_wait_readable, 4);
rb_define_method(cls, "rb_io_maybe_wait", io_spec_rb_io_maybe_wait, 4);
-#endif
rb_define_method(cls, "rb_thread_wait_fd", io_spec_rb_thread_wait_fd, 1);
rb_define_method(cls, "rb_thread_fd_writable", io_spec_rb_thread_fd_writable, 1);
rb_define_method(cls, "rb_thread_fd_select_read", io_spec_rb_thread_fd_select_read, 1);
diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c
index abd8d20ff4..a8fed21b59 100644
--- a/spec/ruby/optional/capi/ext/kernel_spec.c
+++ b/spec/ruby/optional/capi/ext/kernel_spec.c
@@ -117,9 +117,11 @@ VALUE kernel_spec_rb_eval_string(VALUE self, VALUE str) {
return rb_eval_string(RSTRING_PTR(str));
}
+#ifndef RUBY_VERSION_IS_4_0
VALUE kernel_spec_rb_eval_cmd_kw(VALUE self, VALUE cmd, VALUE args, VALUE kw_splat) {
return rb_eval_cmd_kw(cmd, args, NUM2INT(kw_splat));
}
+#endif
VALUE kernel_spec_rb_raise(VALUE self, VALUE hash) {
rb_hash_aset(hash, ID2SYM(rb_intern("stage")), ID2SYM(rb_intern("before")));
@@ -351,7 +353,6 @@ static VALUE kernel_spec_rb_funcallv(VALUE self, VALUE obj, VALUE method, VALUE
return rb_funcallv(obj, SYM2ID(method), RARRAY_LENINT(args), RARRAY_PTR(args));
}
-#ifdef RUBY_VERSION_IS_3_0
static VALUE kernel_spec_rb_funcallv_kw(VALUE self, VALUE obj, VALUE method, VALUE args) {
return rb_funcallv_kw(obj, SYM2ID(method), RARRAY_LENINT(args), RARRAY_PTR(args), RB_PASS_KEYWORDS);
}
@@ -359,7 +360,6 @@ static VALUE kernel_spec_rb_funcallv_kw(VALUE self, VALUE obj, VALUE method, VAL
static VALUE kernel_spec_rb_keyword_given_p(int argc, VALUE *args, VALUE self) {
return rb_keyword_given_p() ? Qtrue : Qfalse;
}
-#endif
static VALUE kernel_spec_rb_funcallv_public(VALUE self, VALUE obj, VALUE method) {
return rb_funcallv_public(obj, SYM2ID(method), 0, NULL);
@@ -405,7 +405,9 @@ void Init_kernel_spec(void) {
rb_define_method(cls, "rb_category_warn_deprecated_with_integer_extra_value", kernel_spec_rb_category_warn_deprecated_with_integer_extra_value, 1);
rb_define_method(cls, "rb_ensure", kernel_spec_rb_ensure, 4);
rb_define_method(cls, "rb_eval_string", kernel_spec_rb_eval_string, 1);
+#ifndef RUBY_VERSION_IS_4_0
rb_define_method(cls, "rb_eval_cmd_kw", kernel_spec_rb_eval_cmd_kw, 3);
+#endif
rb_define_method(cls, "rb_raise", kernel_spec_rb_raise, 1);
rb_define_method(cls, "rb_throw", kernel_spec_rb_throw, 1);
rb_define_method(cls, "rb_throw_obj", kernel_spec_rb_throw_obj, 2);
@@ -436,10 +438,8 @@ void Init_kernel_spec(void) {
rb_define_method(cls, "rb_str_format", kernel_spec_rb_str_format, 3);
rb_define_method(cls, "rb_make_backtrace", kernel_spec_rb_make_backtrace, 0);
rb_define_method(cls, "rb_funcallv", kernel_spec_rb_funcallv, 3);
-#ifdef RUBY_VERSION_IS_3_0
rb_define_method(cls, "rb_funcallv_kw", kernel_spec_rb_funcallv_kw, 3);
rb_define_method(cls, "rb_keyword_given_p", kernel_spec_rb_keyword_given_p, -1);
-#endif
rb_define_method(cls, "rb_funcallv_public", kernel_spec_rb_funcallv_public, 2);
rb_define_method(cls, "rb_funcall_many_args", kernel_spec_rb_funcall_many_args, 2);
rb_define_method(cls, "rb_funcall_with_block", kernel_spec_rb_funcall_with_block, 4);
diff --git a/spec/ruby/optional/capi/ext/object_spec.c b/spec/ruby/optional/capi/ext/object_spec.c
index aa60662e1e..995bc38fcf 100644
--- a/spec/ruby/optional/capi/ext/object_spec.c
+++ b/spec/ruby/optional/capi/ext/object_spec.c
@@ -15,11 +15,6 @@ static VALUE object_spec_FL_ABLE(VALUE self, VALUE obj) {
static int object_spec_FL_TEST_flag(VALUE flag_string) {
char *flag_cstr = StringValueCStr(flag_string);
-#ifndef RUBY_VERSION_IS_3_1
- if (strcmp(flag_cstr, "FL_TAINT") == 0) {
- return FL_TAINT;
- }
-#endif
if (strcmp(flag_cstr, "FL_FREEZE") == 0) {
return FL_FREEZE;
}
@@ -30,22 +25,6 @@ static VALUE object_spec_FL_TEST(VALUE self, VALUE obj, VALUE flag) {
return INT2FIX(FL_TEST(obj, object_spec_FL_TEST_flag(flag)));
}
-#ifndef RUBY_VERSION_IS_3_1
-static VALUE object_spec_OBJ_TAINT(VALUE self, VALUE obj) {
- OBJ_TAINT(obj);
- return Qnil;
-}
-
-static VALUE object_spec_OBJ_TAINTED(VALUE self, VALUE obj) {
- return OBJ_TAINTED(obj) ? Qtrue : Qfalse;
-}
-
-static VALUE object_spec_OBJ_INFECT(VALUE self, VALUE host, VALUE source) {
- OBJ_INFECT(host, source);
- return Qnil;
-}
-#endif
-
static VALUE object_spec_rb_any_to_s(VALUE self, VALUE obj) {
return rb_any_to_s(obj);
}
@@ -154,12 +133,6 @@ static VALUE object_specs_rb_obj_method(VALUE self, VALUE obj, VALUE method) {
return rb_obj_method(obj, method);
}
-#ifndef RUBY_VERSION_IS_3_2
-static VALUE object_spec_rb_obj_taint(VALUE self, VALUE obj) {
- return rb_obj_taint(obj);
-}
-#endif
-
static VALUE so_require(VALUE self) {
rb_require("fixtures/foo");
return Qnil;
@@ -410,15 +383,20 @@ static VALUE object_spec_custom_alloc_func_p(VALUE self, VALUE klass) {
return allocator ? Qtrue : Qfalse;
}
+static VALUE object_spec_redefine_frozen(VALUE self) {
+ // The purpose of this spec is to verify that `frozen?`
+ // and `RB_OBJ_FROZEN` do not mutually recurse infinitely.
+ if (RB_OBJ_FROZEN(self)) {
+ return Qtrue;
+ }
+
+ return Qfalse;
+}
+
void Init_object_spec(void) {
VALUE cls = rb_define_class("CApiObjectSpecs", rb_cObject);
rb_define_method(cls, "FL_ABLE", object_spec_FL_ABLE, 1);
rb_define_method(cls, "FL_TEST", object_spec_FL_TEST, 2);
-#ifndef RUBY_VERSION_IS_3_1
- rb_define_method(cls, "OBJ_TAINT", object_spec_OBJ_TAINT, 1);
- rb_define_method(cls, "OBJ_TAINTED", object_spec_OBJ_TAINTED, 1);
- rb_define_method(cls, "OBJ_INFECT", object_spec_OBJ_INFECT, 2);
-#endif
rb_define_method(cls, "rb_any_to_s", object_spec_rb_any_to_s, 1);
rb_define_method(cls, "rb_attr_get", so_attr_get, 2);
rb_define_method(cls, "rb_obj_instance_variables", object_spec_rb_obj_instance_variables, 1);
@@ -443,15 +421,11 @@ void Init_object_spec(void) {
rb_define_method(cls, "rb_obj_is_kind_of", so_kind_of, 2);
rb_define_method(cls, "rb_obj_method_arity", object_specs_rb_obj_method_arity, 2);
rb_define_method(cls, "rb_obj_method", object_specs_rb_obj_method, 2);
-#ifndef RUBY_VERSION_IS_3_2
- rb_define_method(cls, "rb_obj_taint", object_spec_rb_obj_taint, 1);
-#endif
rb_define_method(cls, "rb_require", so_require, 0);
rb_define_method(cls, "rb_respond_to", so_respond_to, 2);
rb_define_method(cls, "rb_method_boundp", object_spec_rb_method_boundp, 3);
rb_define_method(cls, "rb_obj_respond_to", so_obj_respond_to, 3);
rb_define_method(cls, "rb_special_const_p", object_spec_rb_special_const_p, 1);
-
rb_define_method(cls, "rb_to_id", so_to_id, 1);
rb_define_method(cls, "RTEST", object_spec_RTEST, 1);
rb_define_method(cls, "rb_check_type", so_check_type, 2);
@@ -491,6 +465,9 @@ void Init_object_spec(void) {
rb_define_method(cls, "custom_alloc_func?", object_spec_custom_alloc_func_p, 1);
rb_define_method(cls, "not_implemented_method", rb_f_notimplement, -1);
rb_define_method(cls, "rb_ivar_foreach", object_spec_rb_ivar_foreach, 1);
+
+ cls = rb_define_class("CApiObjectRedefinitionSpecs", rb_cObject);
+ rb_define_method(cls, "frozen?", object_spec_redefine_frozen, 0);
}
#ifdef __cplusplus
diff --git a/spec/ruby/optional/capi/ext/range_spec.c b/spec/ruby/optional/capi/ext/range_spec.c
index b0cf1a8662..9faed3e5ee 100644
--- a/spec/ruby/optional/capi/ext/range_spec.c
+++ b/spec/ruby/optional/capi/ext/range_spec.c
@@ -25,9 +25,9 @@ VALUE range_spec_rb_range_values(VALUE self, VALUE range) {
return ary;
}
-VALUE range_spec_rb_range_beg_len(VALUE self, VALUE range, VALUE begpv, VALUE lenpv, VALUE lenv, VALUE errv) {
- long begp = FIX2LONG(begpv);
- long lenp = FIX2LONG(lenpv);
+VALUE range_spec_rb_range_beg_len(VALUE self, VALUE range, VALUE lenv, VALUE errv) {
+ long begp = 0;
+ long lenp = 0;
long len = FIX2LONG(lenv);
int err = FIX2INT(errv);
VALUE ary = rb_ary_new();
@@ -38,11 +38,51 @@ VALUE range_spec_rb_range_beg_len(VALUE self, VALUE range, VALUE begpv, VALUE le
return ary;
}
+VALUE range_spec_rb_arithmetic_sequence_extract(VALUE self, VALUE object) {
+ VALUE ary = rb_ary_new();
+ rb_arithmetic_sequence_components_t components;
+
+ int status = rb_arithmetic_sequence_extract(object, &components);
+
+ if (!status) {
+ rb_ary_store(ary, 0, LONG2FIX(status));
+ return ary;
+ }
+
+ rb_ary_store(ary, 0, LONG2FIX(status));
+ rb_ary_store(ary, 1, components.begin);
+ rb_ary_store(ary, 2, components.end);
+ rb_ary_store(ary, 3, components.step);
+ rb_ary_store(ary, 4, components.exclude_end ? Qtrue : Qfalse);
+ return ary;
+}
+
+VALUE range_spec_rb_arithmetic_sequence_beg_len_step(VALUE self, VALUE aseq, VALUE lenv, VALUE errv) {
+ long begp = 0;
+ long lenp = 0;
+ long stepp = 0;
+
+ long len = FIX2LONG(lenv);
+ int err = FIX2INT(errv);
+
+ VALUE success = rb_arithmetic_sequence_beg_len_step(aseq, &begp, &lenp, &stepp, len, err);
+
+ VALUE ary = rb_ary_new();
+ rb_ary_store(ary, 0, success);
+ rb_ary_store(ary, 1, LONG2FIX(begp));
+ rb_ary_store(ary, 2, LONG2FIX(lenp));
+ rb_ary_store(ary, 3, LONG2FIX(stepp));
+
+ return ary;
+}
+
void Init_range_spec(void) {
VALUE cls = rb_define_class("CApiRangeSpecs", rb_cObject);
rb_define_method(cls, "rb_range_new", range_spec_rb_range_new, -1);
rb_define_method(cls, "rb_range_values", range_spec_rb_range_values, 1);
- rb_define_method(cls, "rb_range_beg_len", range_spec_rb_range_beg_len, 5);
+ rb_define_method(cls, "rb_range_beg_len", range_spec_rb_range_beg_len, 3);
+ rb_define_method(cls, "rb_arithmetic_sequence_extract", range_spec_rb_arithmetic_sequence_extract, 1);
+ rb_define_method(cls, "rb_arithmetic_sequence_beg_len_step", range_spec_rb_arithmetic_sequence_beg_len_step, 3);
}
#ifdef __cplusplus
diff --git a/spec/ruby/optional/capi/ext/rbasic_spec.c b/spec/ruby/optional/capi/ext/rbasic_spec.c
index 26be2fed6d..5a95b92804 100644
--- a/spec/ruby/optional/capi/ext/rbasic_spec.c
+++ b/spec/ruby/optional/capi/ext/rbasic_spec.c
@@ -31,13 +31,6 @@ static const VALUE DATA_VISIBLE_BITS = FL_FREEZE | ~(FL_USER0 - 1);
#error "unsupported"
#endif
-
-#ifndef RUBY_VERSION_IS_3_1
-VALUE rbasic_spec_taint_flag(VALUE self) {
- return VALUE2NUM(RUBY_FL_TAINT);
-}
-#endif
-
VALUE rbasic_spec_freeze_flag(VALUE self) {
return VALUE2NUM(RUBY_FL_FREEZE);
}
@@ -93,9 +86,6 @@ static VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) {
void Init_rbasic_spec(void) {
VALUE cls = rb_define_class("CApiRBasicSpecs", rb_cObject);
-#ifndef RUBY_VERSION_IS_3_1
- rb_define_method(cls, "taint_flag", rbasic_spec_taint_flag, 0);
-#endif
rb_define_method(cls, "freeze_flag", rbasic_spec_freeze_flag, 0);
rb_define_method(cls, "get_flags", rbasic_spec_get_flags, 1);
rb_define_method(cls, "set_flags", rbasic_spec_set_flags, 2);
diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h
index 35fe3c765d..6c4bea5da0 100644
--- a/spec/ruby/optional/capi/ext/rubyspec.h
+++ b/spec/ruby/optional/capi/ext/rubyspec.h
@@ -35,8 +35,8 @@
(RUBY_API_VERSION_MAJOR == (major) && RUBY_API_VERSION_MINOR < (minor)))
#define RUBY_VERSION_SINCE(major,minor) (!RUBY_VERSION_BEFORE(major, minor))
-#if RUBY_VERSION_SINCE(3, 5)
-#define RUBY_VERSION_IS_3_5
+#if RUBY_VERSION_SINCE(4, 0)
+#define RUBY_VERSION_IS_4_0
#endif
#if RUBY_VERSION_SINCE(3, 4)
@@ -47,16 +47,4 @@
#define RUBY_VERSION_IS_3_3
#endif
-#if RUBY_VERSION_SINCE(3, 2)
-#define RUBY_VERSION_IS_3_2
-#endif
-
-#if RUBY_VERSION_SINCE(3, 1)
-#define RUBY_VERSION_IS_3_1
-#endif
-
-#if RUBY_VERSION_SINCE(3, 0)
-#define RUBY_VERSION_IS_3_0
-#endif
-
#endif
diff --git a/spec/ruby/optional/capi/ext/set_spec.c b/spec/ruby/optional/capi/ext/set_spec.c
new file mode 100644
index 0000000000..11a271b361
--- /dev/null
+++ b/spec/ruby/optional/capi/ext/set_spec.c
@@ -0,0 +1,65 @@
+#include "ruby.h"
+#include "rubyspec.h"
+
+#ifdef RUBY_VERSION_IS_4_0
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define RBOOL(x) ((x) ? Qtrue : Qfalse)
+
+int yield_element_and_arg(VALUE element, VALUE arg) {
+ return RTEST(rb_yield_values(2, element, arg)) ? ST_CONTINUE : ST_STOP;
+}
+
+VALUE set_spec_rb_set_foreach(VALUE self, VALUE set, VALUE arg) {
+ rb_set_foreach(set, yield_element_and_arg, arg);
+ return Qnil;
+}
+
+VALUE set_spec_rb_set_new(VALUE self) {
+ return rb_set_new();
+}
+
+VALUE set_spec_rb_set_new_capa(VALUE self, VALUE capa) {
+ return rb_set_new_capa(NUM2INT(capa));
+}
+
+VALUE set_spec_rb_set_lookup(VALUE self, VALUE set, VALUE element) {
+ return RBOOL(rb_set_lookup(set, element));
+}
+
+VALUE set_spec_rb_set_add(VALUE self, VALUE set, VALUE element) {
+ return RBOOL(rb_set_add(set, element));
+}
+
+VALUE set_spec_rb_set_clear(VALUE self, VALUE set) {
+ return rb_set_clear(set);
+}
+
+VALUE set_spec_rb_set_delete(VALUE self, VALUE set, VALUE element) {
+ return RBOOL(rb_set_delete(set, element));
+}
+
+VALUE set_spec_rb_set_size(VALUE self, VALUE set) {
+ return SIZET2NUM(rb_set_size(set));
+}
+
+void Init_set_spec(void) {
+ VALUE cls = rb_define_class("CApiSetSpecs", rb_cObject);
+
+ rb_define_method(cls, "rb_set_foreach", set_spec_rb_set_foreach, 2);
+ rb_define_method(cls, "rb_set_new", set_spec_rb_set_new, 0);
+ rb_define_method(cls, "rb_set_new_capa", set_spec_rb_set_new_capa, 1);
+ rb_define_method(cls, "rb_set_lookup", set_spec_rb_set_lookup, 2);
+ rb_define_method(cls, "rb_set_add", set_spec_rb_set_add, 2);
+ rb_define_method(cls, "rb_set_clear", set_spec_rb_set_clear, 1);
+ rb_define_method(cls, "rb_set_delete", set_spec_rb_set_delete, 2);
+ rb_define_method(cls, "rb_set_size", set_spec_rb_set_size, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c
index a140c86347..094013e049 100644
--- a/spec/ruby/optional/capi/ext/string_spec.c
+++ b/spec/ruby/optional/capi/ext/string_spec.c
@@ -252,16 +252,6 @@ VALUE string_spec_rb_str_new5(VALUE self, VALUE str, VALUE ptr, VALUE len) {
return rb_str_new5(str, RSTRING_PTR(ptr), FIX2INT(len));
}
-#ifndef RUBY_VERSION_IS_3_2
-VALUE string_spec_rb_tainted_str_new(VALUE self, VALUE str, VALUE len) {
- return rb_tainted_str_new(RSTRING_PTR(str), FIX2INT(len));
-}
-
-VALUE string_spec_rb_tainted_str_new2(VALUE self, VALUE str) {
- return rb_tainted_str_new2(RSTRING_PTR(str));
-}
-#endif
-
VALUE string_spec_rb_str_plus(VALUE self, VALUE str1, VALUE str2) {
return rb_str_plus(str1, str2);
}
@@ -450,6 +440,7 @@ static VALUE string_spec_rb_str_free(VALUE self, VALUE str) {
static VALUE string_spec_rb_sprintf1(VALUE self, VALUE str, VALUE repl) {
return rb_sprintf(RSTRING_PTR(str), RSTRING_PTR(repl));
}
+
static VALUE string_spec_rb_sprintf2(VALUE self, VALUE str, VALUE repl1, VALUE repl2) {
return rb_sprintf(RSTRING_PTR(str), RSTRING_PTR(repl1), RSTRING_PTR(repl2));
}
@@ -635,10 +626,6 @@ void Init_string_spec(void) {
rb_define_method(cls, "rb_str_new3", string_spec_rb_str_new3, 1);
rb_define_method(cls, "rb_str_new4", string_spec_rb_str_new4, 1);
rb_define_method(cls, "rb_str_new5", string_spec_rb_str_new5, 3);
-#ifndef RUBY_VERSION_IS_3_2
- rb_define_method(cls, "rb_tainted_str_new", string_spec_rb_tainted_str_new, 2);
- rb_define_method(cls, "rb_tainted_str_new2", string_spec_rb_tainted_str_new2, 1);
-#endif
rb_define_method(cls, "rb_str_plus", string_spec_rb_str_plus, 2);
rb_define_method(cls, "rb_str_times", string_spec_rb_str_times, 2);
rb_define_method(cls, "rb_str_modify_expand", string_spec_rb_str_modify_expand, 2);
diff --git a/spec/ruby/optional/capi/ext/struct_spec.c b/spec/ruby/optional/capi/ext/struct_spec.c
index 413249e828..756cfca8dd 100644
--- a/spec/ruby/optional/capi/ext/struct_spec.c
+++ b/spec/ruby/optional/capi/ext/struct_spec.c
@@ -62,6 +62,10 @@ static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) {
return rb_struct_size(st);
}
+static VALUE struct_spec_rb_struct_initialize(VALUE self, VALUE st, VALUE values) {
+ return rb_struct_initialize(st, values);
+}
+
#if defined(RUBY_VERSION_IS_3_3)
/* Only allow setting three attributes, should be sufficient for testing. */
static VALUE struct_spec_rb_data_define(VALUE self, VALUE superclass,
@@ -90,6 +94,7 @@ void Init_struct_spec(void) {
rb_define_method(cls, "rb_struct_define_under", struct_spec_rb_struct_define_under, 5);
rb_define_method(cls, "rb_struct_new", struct_spec_rb_struct_new, 4);
rb_define_method(cls, "rb_struct_size", struct_spec_rb_struct_size, 1);
+ rb_define_method(cls, "rb_struct_initialize", struct_spec_rb_struct_initialize, 2);
#if defined(RUBY_VERSION_IS_3_3)
rb_define_method(cls, "rb_data_define", struct_spec_rb_data_define, 4);
#endif
diff --git a/spec/ruby/optional/capi/ext/thread_spec.c b/spec/ruby/optional/capi/ext/thread_spec.c
index 6ee111b7b7..ac77e4e813 100644
--- a/spec/ruby/optional/capi/ext/thread_spec.c
+++ b/spec/ruby/optional/capi/ext/thread_spec.c
@@ -166,7 +166,7 @@ static VALUE thread_spec_ruby_native_thread_p_new_thread(VALUE self) {
#endif
}
-#ifdef RUBY_VERSION_IS_3_5
+#ifdef RUBY_VERSION_IS_4_0
static VALUE thread_spec_ruby_thread_has_gvl_p(VALUE self) {
return ruby_thread_has_gvl_p() ? Qtrue : Qfalse;
}
@@ -185,7 +185,7 @@ void Init_thread_spec(void) {
rb_define_method(cls, "rb_thread_create", thread_spec_rb_thread_create, 2);
rb_define_method(cls, "ruby_native_thread_p", thread_spec_ruby_native_thread_p, 0);
rb_define_method(cls, "ruby_native_thread_p_new_thread", thread_spec_ruby_native_thread_p_new_thread, 0);
-#ifdef RUBY_VERSION_IS_3_5
+#ifdef RUBY_VERSION_IS_4_0
rb_define_method(cls, "ruby_thread_has_gvl_p", thread_spec_ruby_thread_has_gvl_p, 0);
#endif
}
diff --git a/spec/ruby/optional/capi/globals_spec.rb b/spec/ruby/optional/capi/globals_spec.rb
index 48677620bc..4657293e15 100644
--- a/spec/ruby/optional/capi/globals_spec.rb
+++ b/spec/ruby/optional/capi/globals_spec.rb
@@ -41,14 +41,19 @@ describe "CApiGlobalSpecs" do
@f.sb_get_global_value.should == "XYZ"
end
+ run = 0
+
it "rb_define_readonly_variable should define a new readonly global variable" do
+ name = "ro_gvar#{run += 1}"
+ eval <<~RUBY
# Check the gvar doesn't exist and ensure rb_gv_get doesn't implicitly declare the gvar,
# otherwise the rb_define_readonly_variable call will conflict.
- suppress_warning { @f.sb_gv_get("ro_gvar") } .should == nil
+ suppress_warning { @f.sb_gv_get("#{name}") }.should == nil
- @f.rb_define_readonly_variable("ro_gvar", 15)
- $ro_gvar.should == 15
- -> { $ro_gvar = 10 }.should raise_error(NameError)
+ @f.rb_define_readonly_variable("#{name}", 15)
+ $#{name}.should == 15
+ -> { $#{name} = 10 }.should raise_error(NameError)
+ RUBY
end
it "rb_define_hooked_variable should define a C hooked global variable" do
diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb
index 08e03fcb26..3a27de3bfa 100644
--- a/spec/ruby/optional/capi/hash_spec.rb
+++ b/spec/ruby/optional/capi/hash_spec.rb
@@ -50,19 +50,17 @@ describe "C-API Hash function" do
end
end
- ruby_version_is '3.2' do
- describe "rb_hash_new_capa" do
- it "returns a new hash" do
- @s.rb_hash_new_capa(3).should == {}
- end
+ describe "rb_hash_new_capa" do
+ it "returns a new hash" do
+ @s.rb_hash_new_capa(3).should == {}
+ end
- it "creates a hash with no default proc" do
- @s.rb_hash_new_capa(3) {}.default_proc.should be_nil
- end
+ it "creates a hash with no default proc" do
+ @s.rb_hash_new_capa(3) {}.default_proc.should be_nil
+ end
- it "raises RuntimeError when negative index is provided" do
- -> { @s.rb_hash_new_capa(-1) }.should raise_error(RuntimeError, "st_table too big")
- end
+ it "raises RuntimeError when negative index is provided" do
+ -> { @s.rb_hash_new_capa(-1) }.should raise_error(RuntimeError, "st_table too big")
end
end
diff --git a/spec/ruby/optional/capi/integer_spec.rb b/spec/ruby/optional/capi/integer_spec.rb
index 089872381c..f177374569 100644
--- a/spec/ruby/optional/capi/integer_spec.rb
+++ b/spec/ruby/optional/capi/integer_spec.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require_relative 'spec_helper'
load_extension("integer")
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb
index d915a72c22..6633ee50c1 100644
--- a/spec/ruby/optional/capi/kernel_spec.rb
+++ b/spec/ruby/optional/capi/kernel_spec.rb
@@ -635,22 +635,24 @@ describe "C-API Kernel function" do
end
end
- describe "rb_eval_cmd_kw" do
- it "evaluates a string of ruby code" do
- @s.rb_eval_cmd_kw("1+1", [], 0).should == 2
- end
+ ruby_version_is ""..."4.0" do
+ describe "rb_eval_cmd_kw" do
+ it "evaluates a string of ruby code" do
+ @s.rb_eval_cmd_kw("1+1", [], 0).should == 2
+ end
- it "calls a proc with the supplied arguments" do
- @s.rb_eval_cmd_kw(-> *x { x.map { |i| i + 1 } }, [1, 3, 7], 0).should == [2, 4, 8]
- end
+ it "calls a proc with the supplied arguments" do
+ @s.rb_eval_cmd_kw(-> *x { x.map { |i| i + 1 } }, [1, 3, 7], 0).should == [2, 4, 8]
+ end
- it "calls a proc with keyword arguments if kw_splat is non zero" do
- a_proc = -> *x, **y {
- res = x.map { |i| i + 1 }
- y.each { |k, v| res << k; res << v }
- res
- }
- @s.rb_eval_cmd_kw(a_proc, [1, 3, 7, {a: 1, b: 2, c: 3}], 1).should == [2, 4, 8, :a, 1, :b, 2, :c, 3]
+ it "calls a proc with keyword arguments if kw_splat is non zero" do
+ a_proc = -> *x, **y {
+ res = x.map { |i| i + 1 }
+ y.each { |k, v| res << k; res << v }
+ res
+ }
+ @s.rb_eval_cmd_kw(a_proc, [1, 3, 7, {a: 1, b: 2, c: 3}], 1).should == [2, 4, 8, :a, 1, :b, 2, :c, 3]
+ end
end
end
diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb
index b7684e566b..af39ec0192 100644
--- a/spec/ruby/optional/capi/module_spec.rb
+++ b/spec/ruby/optional/capi/module_spec.rb
@@ -38,7 +38,7 @@ describe "CApiModule" do
CApiModuleSpecs::C.const_set(:_INVALID, 1)
}.should raise_error(NameError, /wrong constant name/)
- @m.rb_const_set(CApiModuleSpecs::C, :_INVALID, 2)
+ suppress_warning { @m.rb_const_set(CApiModuleSpecs::C, :_INVALID, 2) }
@m.rb_const_get(CApiModuleSpecs::C, :_INVALID).should == 2
# Ruby-level should still not allow access
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index 7bc7bd992a..8b4d8a9bba 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -691,6 +691,16 @@ describe "CApiObject" do
end
end
+ describe "redefining frozen? works" do
+ it "allows an object to override frozen?" do
+ obj = CApiObjectRedefinitionSpecs.new
+
+ obj.frozen?.should == false
+ obj.freeze
+ obj.frozen?.should == true
+ end
+ end
+
describe "rb_obj_taint" do
end
@@ -888,7 +898,7 @@ describe "CApiObject" do
end
end
- # The `generic_iv_tbl` table and `*_generic_ivar` functions are for mutable
+ # The `generic_fields_tbl` table and `*_generic_ivar` functions are for mutable
# objects which do not store ivars directly in MRI such as RString, because
# there is no member iv_index_tbl (ivar table) such as in RObject and RClass.
diff --git a/spec/ruby/optional/capi/range_spec.rb b/spec/ruby/optional/capi/range_spec.rb
index 7a52dc7ff8..80c052e79a 100644
--- a/spec/ruby/optional/capi/range_spec.rb
+++ b/spec/ruby/optional/capi/range_spec.rb
@@ -69,7 +69,7 @@ describe "C-API Range function" do
describe "rb_range_beg_len" do
it "returns correct begin, length and result" do
r = 2..5
- begp, lenp, result = @s.rb_range_beg_len(r, 0, 0, 10, 0)
+ begp, lenp, result = @s.rb_range_beg_len(r, 10, 0)
result.should be_true
begp.should == 2
lenp.should == 4
@@ -77,19 +77,155 @@ describe "C-API Range function" do
it "returns nil when not in range" do
r = 2..5
- begp, lenp, result = @s.rb_range_beg_len(r, 0, 0, 1, 0)
+ begp, lenp, result = @s.rb_range_beg_len(r, 1, 0)
result.should be_nil
end
it "raises a RangeError when not in range and err is 1" do
r = -5..-1
- -> { @s.rb_range_beg_len(r, 0, 0, 1, 1) }.should raise_error(RangeError)
+ -> { @s.rb_range_beg_len(r, 1, 1) }.should raise_error(RangeError)
end
it "returns nil when not in range and err is 0" do
r = -5..-1
- begp, lenp, result = @s.rb_range_beg_len(r, 0, 0, 1, 0)
+ begp, lenp, result = @s.rb_range_beg_len(r, 1, 0)
result.should be_nil
end
end
+
+ describe "rb_arithmetic_sequence_extract" do
+ it "returns begin, end, step, exclude end of an instance of an Enumerator::ArithmeticSequence" do
+ enum = (10..20).step(5)
+ enum.should.kind_of?(Enumerator::ArithmeticSequence)
+
+ @s.rb_arithmetic_sequence_extract(enum).should == [1, 10, 20, 5, false]
+ end
+
+ it "returns begin, end, step, exclude end of an instance of a Range" do
+ range = (10..20)
+ @s.rb_arithmetic_sequence_extract(range).should == [1, 10, 20, 1, false]
+ end
+
+ it "returns begin, end, step, exclude end of a non-Range object with Range properties" do
+ object = Object.new
+ def object.begin
+ 10
+ end
+ def object.end
+ 20
+ end
+ def object.exclude_end?
+ false
+ end
+
+ @s.rb_arithmetic_sequence_extract(object).should == [1, 10, 20, 1, false]
+ end
+
+ it "returns failed status if given object is not Enumerator::ArithmeticSequence or Range or Range-like object" do
+ object = Object.new
+ @s.rb_arithmetic_sequence_extract(object).should == [0]
+ end
+ end
+
+ describe "rb_arithmetic_sequence_beg_len_step" do
+ it "returns correct begin, length, step and result" do
+ as = (2..5).step(5)
+ error_code = 0
+
+ success, beg, len, step = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+
+ beg.should == 2
+ len.should == 4
+ step.should == 5
+ end
+
+ it "takes into account excluded end boundary" do
+ as = (2...5).step(1)
+ error_code = 0
+
+ success, _, len, _ = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+ len.should == 3
+ end
+
+ it "adds length to negative begin boundary" do
+ as = (-2..5).step(1)
+ error_code = 0
+
+ success, beg, len, _ = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+
+ beg.should == 4
+ len.should == 2
+ end
+
+ it "adds length to negative end boundary" do
+ as = (2..-1).step(1)
+ error_code = 0
+
+ success, beg, len, _ = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+
+ beg.should == 2
+ len.should == 4
+ end
+
+ it "truncates arithmetic sequence length if end boundary greater than specified length value" do
+ as = (2..10).step(1)
+ error_code = 0
+
+ success, _, len, _ = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+ len.should == 4
+ end
+
+ it "returns inverted begin and end boundaries when step is negative" do
+ as = (2..5).step(-2)
+ error_code = 0
+
+ success, beg, len, step = @s.rb_arithmetic_sequence_beg_len_step(as, 6, error_code)
+ success.should be_true
+
+ beg.should == 5
+ len.should == 0
+ step.should == -2
+ end
+
+ it "returns nil when not in range and error code = 0" do
+ as = (2..5).step(1)
+ error_code = 0
+
+ success, = @s.rb_arithmetic_sequence_beg_len_step(as, 1, error_code)
+ success.should be_nil
+ end
+
+ it "returns nil when not in range, negative boundaries and error code = 0" do
+ as = (-5..-1).step(1)
+ error_code = 0
+
+ success, = @s.rb_arithmetic_sequence_beg_len_step(as, 1, 0)
+ success.should be_nil
+ end
+
+ it "returns begin, length and step and doesn't raise a RangeError when not in range and error code = 1" do
+ as = (2..5).step(1)
+ error_code = 1
+
+ success, beg, len, step = @s.rb_arithmetic_sequence_beg_len_step(as, 1, error_code)
+ success.should be_true
+
+ beg.should == 2
+ len.should == 4
+ step.should == 1
+ end
+
+ it "returns nil and doesn't raise a RangeError when not in range, negative boundaries and error code = 1" do
+ as = (-5..-1).step(1)
+ error_code = 1
+
+ success, = @s.rb_arithmetic_sequence_beg_len_step(as, 1, error_code)
+ success.should be_nil
+ end
+ end
end
diff --git a/spec/ruby/optional/capi/regexp_spec.rb b/spec/ruby/optional/capi/regexp_spec.rb
index 4b130ff66a..49ac79f5c4 100644
--- a/spec/ruby/optional/capi/regexp_spec.rb
+++ b/spec/ruby/optional/capi/regexp_spec.rb
@@ -110,7 +110,7 @@ describe "C-API Regexp function" do
end
end
- describe "rb_memicmp" do
+ describe "rb_memcicmp" do
it "returns 0 for identical strings" do
@p.rb_memcicmp('Hello', 'Hello').should == 0
end
diff --git a/spec/ruby/optional/capi/set_spec.rb b/spec/ruby/optional/capi/set_spec.rb
new file mode 100644
index 0000000000..3e35be0505
--- /dev/null
+++ b/spec/ruby/optional/capi/set_spec.rb
@@ -0,0 +1,96 @@
+require_relative 'spec_helper'
+
+ruby_version_is "4.0" do
+ load_extension("set")
+
+ describe "C-API Set function" do
+ before :each do
+ @s = CApiSetSpecs.new
+ end
+
+ describe "rb_set_foreach" do
+ it "calls function with each element and arg" do
+ a = []
+ @s.rb_set_foreach(Set[1, 2], 3) {|*args| a.concat(args) }
+ a.should == [1, 3, 2, 3]
+ end
+
+ it "respects function return value" do
+ a = []
+ @s.rb_set_foreach(Set[1, 2], 3) do |*args|
+ a.concat(args)
+ false
+ end
+ a.should == [1, 3]
+ end
+ end
+
+ describe "rb_set_new" do
+ it "returns a new set" do
+ @s.rb_set_new.should == Set[]
+ end
+ end
+
+ describe "rb_set_new_capa" do
+ it "returns a new set" do
+ @s.rb_set_new_capa(3).should == Set[]
+ end
+ end
+
+ describe "rb_set_lookup" do
+ it "returns whether the element is in the set" do
+ set = Set[1]
+ @s.rb_set_lookup(set, 1).should == true
+ @s.rb_set_lookup(set, 2).should == false
+ end
+ end
+
+ describe "rb_set_add" do
+ it "adds element to set" do
+ set = Set[]
+ @s.rb_set_add(set, 1).should == true
+ set.should == Set[1]
+ @s.rb_set_add(set, 2).should == true
+ set.should == Set[1, 2]
+ end
+
+ it "returns false if element is already in set" do
+ set = Set[1]
+ @s.rb_set_add(set, 1).should == false
+ set.should == Set[1]
+ end
+ end
+
+ describe "rb_set_clear" do
+ it "empties and returns self" do
+ set = Set[1]
+ @s.rb_set_clear(set).should equal(set)
+ set.should == Set[]
+ end
+ end
+
+ describe "rb_set_delete" do
+ it "removes element from set" do
+ set = Set[1, 2]
+ @s.rb_set_delete(set, 1).should == true
+ set.should == Set[2]
+ @s.rb_set_delete(set, 2).should == true
+ set.should == Set[]
+ end
+
+ it "returns false if element is not already in set" do
+ set = Set[2]
+ @s.rb_set_delete(set, 1).should == false
+ set.should == Set[2]
+ end
+ end
+
+ describe "rb_set_size" do
+ it "returns number of elements in set" do
+ @s.rb_set_size(Set[]).should == 0
+ @s.rb_set_size(Set[1]).should == 1
+ @s.rb_set_size(Set[1,2]).should == 2
+ end
+ end
+ end
+end
diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb
index 9d80a93e1d..e3485d4b7b 100644
--- a/spec/ruby/optional/capi/shared/rbasic.rb
+++ b/spec/ruby/optional/capi/shared/rbasic.rb
@@ -1,7 +1,6 @@
describe :rbasic, shared: true do
before :all do
specs = CApiRBasicSpecs.new
- @taint = ruby_version_is(''...'3.1') ? specs.taint_flag : 0
@freeze = specs.freeze_flag
end
diff --git a/spec/ruby/optional/capi/spec_helper.rb b/spec/ruby/optional/capi/spec_helper.rb
index 2691aa1332..e7abf46e6c 100644
--- a/spec/ruby/optional/capi/spec_helper.rb
+++ b/spec/ruby/optional/capi/spec_helper.rb
@@ -74,12 +74,19 @@ def compile_extension(name)
init_mkmf unless required
create_makefile(ext, tmpdir)
else
+ # Workaround for digest C-API specs to find the ruby/digest.h header
+ # when run in the CRuby repository via make test-spec
+ if MSpecScript.instance_variable_defined?(:@testing_ruby)
+ ruby_repository_extra_include_dir = "-I#{RbConfig::CONFIG.fetch("prefix")}/#{RbConfig::CONFIG.fetch("EXTOUT")}/include"
+ end
+
File.write("extconf.rb", <<-RUBY)
require 'mkmf'
$ruby = ENV.values_at('RUBY_EXE', 'RUBY_FLAGS').join(' ')
# MRI magic to consider building non-bundled extensions
$extout = nil
append_cflags '-Wno-declaration-after-statement'
+ #{"append_cflags #{ruby_repository_extra_include_dir.inspect}" if ruby_repository_extra_include_dir}
create_makefile(#{ext.inspect})
RUBY
output = ruby_exe("extconf.rb")
@@ -115,13 +122,9 @@ def setup_make
opts = {}
if /(?:\A|\s)--jobserver-(?:auth|fds)=(\d+),(\d+)/ =~ make_flags
- begin
- r = IO.for_fd($1.to_i(10), "rb", autoclose: false)
- w = IO.for_fd($2.to_i(10), "wb", autoclose: false)
- rescue Errno::EBADF
- else
- opts[r] = r
- opts[w] = w
+ [$1, $2].each do |fd|
+ fd = fd.to_i(10)
+ opts[fd] = fd
end
end
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 18eaeda8e0..72f20ee6a5 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -191,11 +191,19 @@ describe "C-API String function" do
end
it "returns a new String object filled with \\0 bytes" do
- s = @s.rb_str_tmp_new(4)
- s.encoding.should == Encoding::BINARY
- s.bytesize.should == 4
- s.size.should == 4
- s.should == "\x00\x00\x00\x00"
+ lens = [4]
+
+ ruby_version_is "4.0" do
+ lens << 100
+ end
+
+ lens.each do |len|
+ s = @s.rb_str_tmp_new(len)
+ s.encoding.should == Encoding::BINARY
+ s.bytesize.should == len
+ s.size.should == len
+ s.should == "\x00" * len
+ end
end
end
@@ -1040,11 +1048,19 @@ describe "C-API String function" do
@s.rb_sprintf3(true.class).should == s
end
- ruby_bug "#19167", ""..."3.2" do
- it "formats a TrueClass VALUE as 'true' if sign specified in format" do
- s = 'Result: TrueClass.'
- @s.rb_sprintf4(true.class).should == s
- end
+ it "formats a TrueClass VALUE as 'true' if sign specified in format" do
+ s = 'Result: TrueClass.'
+ @s.rb_sprintf4(true.class).should == s
+ end
+
+ it "formats nil using to_s if sign not specified in format" do
+ s = 'Result: .'
+ @s.rb_sprintf3(nil).should == s
+ end
+
+ it "formats nil using inspect if sign specified in format" do
+ s = 'Result: nil.'
+ @s.rb_sprintf4(nil).should == s
end
it "truncates a string to a supplied precision if that is shorter than the string" do
@@ -1203,28 +1219,50 @@ describe "C-API String function" do
describe "rb_str_locktmp" do
it "raises an error when trying to lock an already locked string" do
- str = "test"
+ str = +"test"
@s.rb_str_locktmp(str).should == str
-> { @s.rb_str_locktmp(str) }.should raise_error(RuntimeError, 'temporal locking already locked string')
end
it "locks a string so that modifications would raise an error" do
- str = "test"
+ str = +"test"
@s.rb_str_locktmp(str).should == str
-> { str.upcase! }.should raise_error(RuntimeError, 'can\'t modify string; temporarily locked')
end
+
+ ruby_version_is "4.0" do
+ it "raises FrozenError if string is frozen" do
+ str = -"rb_str_locktmp"
+ -> { @s.rb_str_locktmp(str) }.should raise_error(FrozenError)
+
+ str = +"rb_str_locktmp"
+ str.freeze
+ -> { @s.rb_str_locktmp(str) }.should raise_error(FrozenError)
+ end
+ end
end
describe "rb_str_unlocktmp" do
it "unlocks a locked string" do
- str = "test"
+ str = +"test"
@s.rb_str_locktmp(str)
@s.rb_str_unlocktmp(str).should == str
str.upcase!.should == "TEST"
end
it "raises an error when trying to unlock an already unlocked string" do
- -> { @s.rb_str_unlocktmp("test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string')
+ -> { @s.rb_str_unlocktmp(+"test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string')
+ end
+
+ ruby_version_is "4.0" do
+ it "raises FrozenError if string is frozen" do
+ str = -"rb_str_locktmp"
+ -> { @s.rb_str_unlocktmp(str) }.should raise_error(FrozenError)
+
+ str = +"rb_str_locktmp"
+ str.freeze
+ -> { @s.rb_str_unlocktmp(str) }.should raise_error(FrozenError)
+ end
end
end
diff --git a/spec/ruby/optional/capi/struct_spec.rb b/spec/ruby/optional/capi/struct_spec.rb
index 474c397956..cc8d7f932e 100644
--- a/spec/ruby/optional/capi/struct_spec.rb
+++ b/spec/ruby/optional/capi/struct_spec.rb
@@ -208,20 +208,48 @@ describe "C-API Struct function" do
@s.rb_struct_size(@struct).should == 3
end
end
+
+ describe "rb_struct_initialize" do
+ it "sets all members" do
+ @s.rb_struct_initialize(@struct, [1, 2, 3]).should == nil
+ @struct.a.should == 1
+ @struct.b.should == 2
+ @struct.c.should == 3
+ end
+
+ it "does not freeze the Struct instance" do
+ @s.rb_struct_initialize(@struct, [1, 2, 3]).should == nil
+ @struct.should_not.frozen?
+ @s.rb_struct_initialize(@struct, [4, 5, 6]).should == nil
+ @struct.a.should == 4
+ @struct.b.should == 5
+ @struct.c.should == 6
+ end
+
+ it "raises ArgumentError if too many values" do
+ -> { @s.rb_struct_initialize(@struct, [1, 2, 3, 4]) }.should raise_error(ArgumentError, "struct size differs")
+ end
+
+ it "treats missing values as nil" do
+ @s.rb_struct_initialize(@struct, [1, 2]).should == nil
+ @struct.a.should == 1
+ @struct.b.should == 2
+ @struct.c.should == nil
+ end
+ end
end
ruby_version_is "3.3" do
describe "C-API Data function" do
- before :each do
+ before :all do
@s = CApiStructSpecs.new
+ @klass = @s.rb_data_define(nil, "a", "b", "c")
end
describe "rb_data_define" do
it "returns a subclass of Data class when passed nil as the first argument" do
- klass = @s.rb_data_define(nil, "a", "b", "c")
-
- klass.should.is_a? Class
- klass.superclass.should == Data
+ @klass.should.is_a? Class
+ @klass.superclass.should == Data
end
it "returns a subclass of a class when passed as the first argument" do
@@ -233,8 +261,7 @@ ruby_version_is "3.3" do
end
it "creates readers for the members" do
- klass = @s.rb_data_define(nil, "a", "b", "c")
- obj = klass.new(1, 2, 3)
+ obj = @klass.new(1, 2, 3)
obj.a.should == 1
obj.b.should == 2
@@ -242,8 +269,7 @@ ruby_version_is "3.3" do
end
it "returns the member names as Symbols" do
- klass = @s.rb_data_define(nil, "a", "b", "c")
- obj = klass.new(0, 0, 0)
+ obj = @klass.new(0, 0, 0)
obj.members.should == [:a, :b, :c]
end
@@ -256,5 +282,35 @@ ruby_version_is "3.3" do
-> { @s.rb_data_define([], "a", "b", "c") }.should raise_error(TypeError, "wrong argument type Array (expected Class)")
end
end
+
+ describe "rb_struct_initialize" do
+ it "sets all members for a Data instance" do
+ data = @klass.allocate
+ @s.rb_struct_initialize(data, [1, 2, 3]).should == nil
+ data.a.should == 1
+ data.b.should == 2
+ data.c.should == 3
+ end
+
+ it "freezes the Data instance" do
+ data = @klass.allocate
+ @s.rb_struct_initialize(data, [1, 2, 3]).should == nil
+ data.should.frozen?
+ -> { @s.rb_struct_initialize(data, [1, 2, 3]) }.should raise_error(FrozenError)
+ end
+
+ it "raises ArgumentError if too many values" do
+ data = @klass.allocate
+ -> { @s.rb_struct_initialize(data, [1, 2, 3, 4]) }.should raise_error(ArgumentError, "struct size differs")
+ end
+
+ it "treats missing values as nil" do
+ data = @klass.allocate
+ @s.rb_struct_initialize(data, [1, 2]).should == nil
+ data.a.should == 1
+ data.b.should == 2
+ data.c.should == nil
+ end
+ end
end
end
diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb
index cd9ae8ff19..117726f0e2 100644
--- a/spec/ruby/optional/capi/thread_spec.rb
+++ b/spec/ruby/optional/capi/thread_spec.rb
@@ -185,7 +185,7 @@ describe "C-API Thread function" do
end
end
- ruby_version_is "3.5" do
+ ruby_version_is "4.0" do
describe "ruby_thread_has_gvl_p" do
it "returns true if the current thread has the GVL" do
@t.ruby_thread_has_gvl_p.should be_true
diff --git a/spec/ruby/optional/thread_safety/fixtures/classes.rb b/spec/ruby/optional/thread_safety/fixtures/classes.rb
new file mode 100644
index 0000000000..4f0ad030e5
--- /dev/null
+++ b/spec/ruby/optional/thread_safety/fixtures/classes.rb
@@ -0,0 +1,39 @@
+module ThreadSafetySpecs
+ # Returns the number of processors, rounded up so it's always a multiple of 2
+ def self.processors
+ require 'etc'
+ n = Etc.nprocessors
+ raise "expected at least 1 processor" if n < 1
+ n += 1 if n.odd? # ensure it's a multiple of 2
+ n
+ end
+
+ class Counter
+ def initialize
+ @value = 0
+ @mutex = Mutex.new
+ end
+
+ def get
+ @mutex.synchronize { @value }
+ end
+
+ def increment
+ @mutex.synchronize do
+ @value += 1
+ end
+ end
+ end
+
+ class Barrier
+ def initialize(parties)
+ @parties = parties
+ @counter = Counter.new
+ end
+
+ def wait
+ @counter.increment
+ Thread.pass until @counter.get == @parties
+ end
+ end
+end
diff --git a/spec/ruby/optional/thread_safety/hash_spec.rb b/spec/ruby/optional/thread_safety/hash_spec.rb
new file mode 100644
index 0000000000..53127fc973
--- /dev/null
+++ b/spec/ruby/optional/thread_safety/hash_spec.rb
@@ -0,0 +1,210 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Hash thread safety" do
+ it "supports concurrent #[]=" do
+ n_threads = ThreadSafetySpecs.processors
+
+ n = 1_000
+ operations = n * n_threads
+
+ h = {}
+ barrier = ThreadSafetySpecs::Barrier.new(n_threads + 1)
+
+ threads = n_threads.times.map { |t|
+ Thread.new {
+ barrier.wait
+ base = t * n
+ n.times do |j|
+ h[base+j] = t
+ end
+ }
+ }
+
+ barrier.wait
+ threads.each(&:join)
+
+ h.size.should == operations
+ h.each_pair { |key, value|
+ (key / n).should == value
+ }
+ end
+
+ # can't add a new key into hash during iteration (RuntimeError) on CRuby.
+ # Yet it's good to test this for implementations that support it.
+ guard_not -> { PlatformGuard.standard? } do
+ it "supports concurrent #[]= and #delete and iteration" do
+ n_threads = ThreadSafetySpecs.processors
+
+ n = 1_000
+ operations = n * n_threads / 2
+
+ h = {}
+ barrier1 = ThreadSafetySpecs::Barrier.new(n_threads + 2)
+ barrier2 = ThreadSafetySpecs::Barrier.new(n_threads + 1)
+
+ threads = n_threads.times.map { |t|
+ Thread.new {
+ barrier1.wait
+ base = t * n
+ n.times do |j|
+ h[base+j] = t
+ end
+
+ barrier2.wait
+ n.times do |j|
+ # delete only even keys
+ h.delete(base+j).should == t if (base+j).even?
+ end
+ }
+ }
+
+ read = true
+ reader = Thread.new {
+ barrier1.wait
+ while read
+ h.each_pair { |k,v|
+ k.should.is_a?(Integer)
+ v.should.is_a?(Integer)
+ (k / n).should == v
+ }
+ end
+ }
+
+ barrier1.wait
+ barrier2.wait
+ threads.each(&:join)
+ read = false
+ reader.join
+
+ # odd keys are left
+ h.size.should == operations
+ h.each_pair { |key, value|
+ key.should.odd?
+ (key / n).should == value
+ }
+ end
+ end
+
+ it "supports concurrent #[]= and #[]" do
+ n_threads = ThreadSafetySpecs.processors
+
+ n = 1_000
+ operations = n * n_threads / 2
+
+ h = {}
+ barrier = ThreadSafetySpecs::Barrier.new(n_threads + 1)
+
+ threads = n_threads.times.map { |t|
+ Thread.new {
+ barrier.wait
+ base = (t / 2) * n
+
+ if t.even?
+ n.times do |j|
+ k = base + j
+ h[k] = k
+ end
+ else
+ n.times do |j|
+ k = base + j
+ Thread.pass until v = h[k]
+ v.should == k
+ end
+ end
+ }
+ }
+
+ barrier.wait
+ threads.each(&:join)
+
+ h.size.should == operations
+ h.each_pair { |key, value|
+ key.should == value
+ }
+ end
+
+ it "supports concurrent #[]= and #[] with change to #compare_by_identity in the middle" do
+ n_threads = ThreadSafetySpecs.processors
+
+ n = 1_000
+ operations = n * n_threads / 2
+
+ h = {}
+ barrier = ThreadSafetySpecs::Barrier.new(n_threads + 1)
+
+ threads = n_threads.times.map { |t|
+ Thread.new {
+ barrier.wait
+ base = (t / 2) * n
+
+ if t.even?
+ n.times do |j|
+ k = base + j
+ h[k] = k
+ end
+ else
+ n.times do |j|
+ k = base + j
+ Thread.pass until v = h[k]
+ v.should == k
+ end
+ end
+ }
+ }
+
+ changer = Thread.new {
+ Thread.pass until h.size >= operations / 2
+ h.should_not.compare_by_identity?
+ h.compare_by_identity
+ h.should.compare_by_identity?
+ }
+
+ barrier.wait
+ threads.each(&:join)
+ changer.join
+
+ h.size.should == operations
+ h.each_pair { |key, value|
+ key.should == value
+ }
+ end
+
+ it "supports repeated concurrent #[]= and #delete and always returns a #size >= 0" do
+ n_threads = ThreadSafetySpecs.processors
+
+ n = 1_000
+ operations = n * n_threads / 2
+
+ h = {}
+ barrier = ThreadSafetySpecs::Barrier.new(n_threads + 1)
+ deleted = ThreadSafetySpecs::Counter.new
+
+ threads = n_threads.times.map { |t|
+ Thread.new {
+ barrier.wait
+ key = t / 2
+
+ if t.even?
+ n.times {
+ Thread.pass until h.delete(key)
+ h.size.should >= 0
+ deleted.increment
+ }
+ else
+ n.times {
+ h[key] = key
+ Thread.pass while h.key?(key)
+ }
+ end
+ }
+ }
+
+ barrier.wait
+ threads.each(&:join)
+
+ deleted.get.should == operations
+ h.size.should == 0
+ h.should.empty?
+ end
+end
diff --git a/spec/ruby/security/cve_2020_10663_spec.rb b/spec/ruby/security/cve_2020_10663_spec.rb
index 80e860348b..c44a13a0dd 100644
--- a/spec/ruby/security/cve_2020_10663_spec.rb
+++ b/spec/ruby/security/cve_2020_10663_spec.rb
@@ -1,6 +1,6 @@
require_relative '../spec_helper'
-ruby_version_is ""..."3.5" do
+ruby_version_is ""..."4.0" do
require 'json'
module JSONSpecs
diff --git a/spec/ruby/security/cve_2024_49761_spec.rb b/spec/ruby/security/cve_2024_49761_spec.rb
index 54ede39032..c66b438eef 100644
--- a/spec/ruby/security/cve_2024_49761_spec.rb
+++ b/spec/ruby/security/cve_2024_49761_spec.rb
@@ -1,9 +1,7 @@
require_relative '../spec_helper'
-ruby_version_is "3.2" do
- describe "CVE-2024-49761 is resisted by" do
- it "the Regexp implementation handling that regular expression in linear time" do
- Regexp.linear_time?(/&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/).should == true
- end
+describe "CVE-2024-49761 is resisted by" do
+ it "the Regexp implementation handling that regular expression in linear time" do
+ Regexp.linear_time?(/&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/).should == true
end
end
diff --git a/spec/ruby/shared/file/socket.rb b/spec/ruby/shared/file/socket.rb
index 55a1cfd284..ef6c482d1c 100644
--- a/spec/ruby/shared/file/socket.rb
+++ b/spec/ruby/shared/file/socket.rb
@@ -1,3 +1,33 @@
describe :file_socket, shared: true do
- it "accepts an object that has a #to_path method"
+ it "returns false if the file is not a socket" do
+ filename = tmp("i_exist")
+ touch(filename)
+
+ @object.send(@method, filename).should == false
+
+ rm_r filename
+ end
+
+ it "returns true if the file is a socket" do
+ require 'socket'
+
+ # We need a really short name here.
+ # On Linux the path length is limited to 107, see unix(7).
+ name = tmp("s")
+ server = UNIXServer.new(name)
+
+ @object.send(@method, name).should == true
+
+ server.close
+ rm_r name
+ end
+
+ it "accepts an object that has a #to_path method" do
+ obj = Object.new
+ def obj.to_path
+ __FILE__
+ end
+
+ @object.send(@method, obj).should == false
+ end
end
diff --git a/spec/ruby/shared/io/putc.rb b/spec/ruby/shared/io/putc.rb
index e6012c0098..cdf18ac9fd 100644
--- a/spec/ruby/shared/io/putc.rb
+++ b/spec/ruby/shared/io/putc.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :io_putc, shared: true do
after :each do
@io.close if @io && !@io.closed?
diff --git a/spec/ruby/shared/kernel/raise.rb b/spec/ruby/shared/kernel/raise.rb
index 1917a4c923..2be06ea797 100644
--- a/spec/ruby/shared/kernel/raise.rb
+++ b/spec/ruby/shared/kernel/raise.rb
@@ -49,21 +49,6 @@ describe :kernel_raise, shared: true do
end
end
- it "does not allow message and extra keyword arguments" do
- data_error = Class.new(StandardError) do
- attr_reader :data
- def initialize(data)
- @data = data
- end
- end
-
- -> { @object.raise(data_error, {a: 1}, b: 2) }.should raise_error(StandardError) do |e|
- [TypeError, ArgumentError].should.include?(e.class)
- end
-
- -> { @object.raise(data_error, {a: 1}, [], b: 2) }.should raise_error(ArgumentError)
- end
-
it "raises RuntimeError if no exception class is given" do
-> { @object.raise }.should raise_error(RuntimeError, "")
end
@@ -74,7 +59,7 @@ describe :kernel_raise, shared: true do
end
it "raises a RuntimeError if string given" do
- -> { @object.raise("a bad thing") }.should raise_error(RuntimeError)
+ -> { @object.raise("a bad thing") }.should raise_error(RuntimeError, "a bad thing")
end
it "passes no arguments to the constructor when given only an exception class" do
@@ -86,59 +71,57 @@ describe :kernel_raise, shared: true do
end
it "raises a TypeError when passed a non-Exception object" do
- -> { @object.raise(Object.new) }.should raise_error(TypeError)
+ -> { @object.raise(Object.new) }.should raise_error(TypeError, "exception class/object expected")
+ -> { @object.raise(Object.new, "message") }.should raise_error(TypeError, "exception class/object expected")
+ -> { @object.raise(Object.new, "message", []) }.should raise_error(TypeError, "exception class/object expected")
end
it "raises a TypeError when passed true" do
- -> { @object.raise(true) }.should raise_error(TypeError)
+ -> { @object.raise(true) }.should raise_error(TypeError, "exception class/object expected")
end
it "raises a TypeError when passed false" do
- -> { @object.raise(false) }.should raise_error(TypeError)
+ -> { @object.raise(false) }.should raise_error(TypeError, "exception class/object expected")
end
it "raises a TypeError when passed nil" do
- -> { @object.raise(nil) }.should raise_error(TypeError)
+ -> { @object.raise(nil) }.should raise_error(TypeError, "exception class/object expected")
+ end
+
+ it "raises a TypeError when passed a message and an extra argument" do
+ -> { @object.raise("message", {cause: RuntimeError.new()}) }.should raise_error(TypeError, "exception class/object expected")
+ end
+
+ it "raises TypeError when passed a non-Exception object but it responds to #exception method that doesn't return an instance of Exception class" do
+ e = Object.new
+ def e.exception
+ Array
+ end
+
+ -> {
+ @object.raise e
+ }.should raise_error(TypeError, "exception object expected")
end
it "re-raises a previously rescued exception without overwriting the backtrace" do
- # This spec is written using #backtrace and matching the line number
- # from the string, as backtrace_locations is a more advanced
- # method that is not always supported by implementations.
- #
- initial_raise_line = nil
- raise_again_line = nil
- raised_again = nil
-
- if defined?(FiberSpecs::NewFiberToRaise) and @object == FiberSpecs::NewFiberToRaise
- fiber = Fiber.new do
- begin
- initial_raise_line = __LINE__; Fiber.yield
- rescue => raised
- begin
- raise_again_line = __LINE__; Fiber.yield raised
- rescue => raised_again
- raised_again
- end
- end
- end
- fiber.resume
- raised = fiber.raise 'raised'
- raised_again = fiber.raise raised
- else
- begin
- initial_raise_line = __LINE__; @object.raise 'raised'
- rescue => raised
- begin
- raise_again_line = __LINE__; @object.raise raised
- rescue => raised_again
- raised_again
- end
- end
+ exception = nil
+
+ begin
+ raise "raised"
+ rescue => exception
+ # Ignore.
end
- raised_again.backtrace.first.should include("#{__FILE__}:#{initial_raise_line}:")
- raised_again.backtrace.first.should_not include("#{__FILE__}:#{raise_again_line}:")
+ backtrace = exception.backtrace
+
+ begin
+ raised_exception = @object.raise(exception)
+ rescue => raised_exception
+ # Ignore.
+ end
+
+ raised_exception.backtrace.should == backtrace
+ raised_exception.should == exception
end
it "allows Exception, message, and backtrace parameters" do
@@ -157,4 +140,259 @@ describe :kernel_raise, shared: true do
}
end
end
+
+ ruby_version_is "4.0" do
+ it "allows cause keyword argument" do
+ cause = StandardError.new("original error")
+ result = nil
+
+ -> do
+ @object.raise("new error", cause: cause)
+ end.should raise_error(RuntimeError, "new error") do |error|
+ error.cause.should == cause
+ end
+ end
+
+ it "raises an ArgumentError when only cause is given" do
+ cause = StandardError.new("cause")
+ -> do
+ @object.raise(cause: cause)
+ end.should raise_error(ArgumentError, "only cause is given with no arguments")
+ end
+
+ it "raises an ArgumentError when only cause is given and is nil" do
+ -> do
+ @object.raise(cause: nil)
+ end.should raise_error(ArgumentError, "only cause is given with no arguments")
+ end
+
+ it "raises a TypeError when given cause is not an instance of Exception" do
+ cause = Object.new
+ -> do
+ @object.raise("message", cause: cause)
+ end.should raise_error(TypeError, "exception object expected")
+ end
+
+ it "doesn't set given cause when it equals the raised exception" do
+ cause = StandardError.new("cause")
+ result = nil
+
+ -> do
+ @object.raise(cause, cause: cause)
+ end.should raise_error(StandardError, "cause") do |error|
+ error.should == cause
+ error.cause.should == nil
+ end
+ end
+
+ it "accepts cause equal an exception" do
+ error = RuntimeError.new("message")
+ result = nil
+
+ -> do
+ @object.raise(error, cause: error)
+ end.should raise_error(RuntimeError, "message") do |e|
+ e.cause.should == nil
+ end
+ end
+
+ it "rejects circular causes" do
+ -> {
+ begin
+ raise "Error 1"
+ rescue => error1
+ begin
+ raise "Error 2"
+ rescue => error2
+ begin
+ raise "Error 3"
+ rescue => error3
+ @object.raise(error1, cause: error3)
+ end
+ end
+ end
+ }.should raise_error(ArgumentError, "circular causes")
+ end
+
+ it "supports exception class with message and cause" do
+ cause = StandardError.new("cause message")
+ result = nil
+
+ -> do
+ @object.raise(ArgumentError, "argument error message", cause: cause)
+ end.should raise_error(ArgumentError, "argument error message") do |error|
+ error.should be_kind_of(ArgumentError)
+ error.message.should == "argument error message"
+ error.cause.should == cause
+ end
+ end
+
+ it "supports exception class with message, backtrace and cause" do
+ cause = StandardError.new("cause message")
+ backtrace = ["line1", "line2"]
+ result = nil
+
+ -> do
+ @object.raise(ArgumentError, "argument error message", backtrace, cause: cause)
+ end.should raise_error(ArgumentError, "argument error message") do |error|
+ error.should be_kind_of(ArgumentError)
+ error.message.should == "argument error message"
+ error.cause.should == cause
+ error.backtrace.should == backtrace
+ end
+ end
+
+ it "supports automatic cause chaining" do
+ -> do
+ begin
+ raise "first error"
+ rescue
+ # No explicit cause - should chain automatically:
+ @object.raise("second error")
+ end
+ end.should raise_error(RuntimeError, "second error") do |error|
+ error.cause.should be_kind_of(RuntimeError)
+ error.cause.message.should == "first error"
+ end
+ end
+
+ it "supports cause: nil to prevent automatic cause chaining" do
+ -> do
+ begin
+ raise "first error"
+ rescue
+ # Explicit nil prevents chaining:
+ @object.raise("second error", cause: nil)
+ end
+ end.should raise_error(RuntimeError, "second error") do |error|
+ error.cause.should == nil
+ end
+ end
+ end
+end
+
+describe :kernel_raise_across_contexts, shared: true do
+ ruby_version_is "4.0" do
+ describe "with cause keyword argument" do
+ it "uses the cause from the calling context" do
+ original_cause = nil
+ result = nil
+
+ # We have no cause ($!) and we don't specify one explicitly either:
+ @object.raise("second error") do |&block|
+ begin
+ begin
+ raise "first error"
+ rescue => original_cause
+ # We have a cause here ($!) but we should ignore it:
+ block.call
+ end
+ rescue => result
+ # Ignore.
+ end
+ end
+
+ result.should be_kind_of(RuntimeError)
+ result.message.should == "second error"
+ result.cause.should == nil
+ end
+
+ it "accepts a cause keyword argument that overrides the last exception" do
+ original_cause = nil
+ override_cause = StandardError.new("override cause")
+ result = nil
+
+ begin
+ raise "outer error"
+ rescue
+ # We have an existing cause, but we want to override it:
+ @object.raise("second error", cause: override_cause) do |&block|
+ begin
+ begin
+ raise "first error"
+ rescue => original_cause
+ # We also have an existing cause here:
+ block.call
+ end
+ rescue => result
+ # Ignore.
+ end
+ end
+ end
+
+ result.should be_kind_of(RuntimeError)
+ result.message.should == "second error"
+ result.cause.should == override_cause
+ end
+
+ it "supports automatic cause chaining from calling context" do
+ result = nil
+
+ @object.raise("new error") do |&block|
+ begin
+ begin
+ raise "original error"
+ rescue
+ block.call # Let the context yield/sleep
+ end
+ rescue => result
+ # Ignore.
+ end
+ end
+
+ result.should be_kind_of(RuntimeError)
+ result.message.should == "new error"
+ # Calling context has no current exception:
+ result.cause.should == nil
+ end
+
+ it "supports explicit cause: nil to prevent cause chaining" do
+ result = nil
+
+ begin
+ raise "calling context error"
+ rescue
+ @object.raise("new error", cause: nil) do |&block|
+ begin
+ begin
+ raise "target context error"
+ rescue
+ block.call # Let the context yield/sleep
+ end
+ rescue => result
+ # Ignore.
+ end
+ end
+
+ result.should be_kind_of(RuntimeError)
+ result.message.should == "new error"
+ result.cause.should == nil
+ end
+ end
+
+ it "raises TypeError when cause is not an Exception" do
+ -> {
+ @object.raise("error", cause: "not an exception") do |&block|
+ begin
+ block.call # Let the context yield/sleep
+ rescue
+ # Ignore - we expect the TypeError to be raised in the calling context
+ end
+ end
+ }.should raise_error(TypeError, "exception object expected")
+ end
+
+ it "raises ArgumentError when only cause is given with no arguments" do
+ -> {
+ @object.raise(cause: StandardError.new("cause")) do |&block|
+ begin
+ block.call # Let the context yield/sleep
+ rescue
+ # Ignore - we expect the ArgumentError to be raised in the calling context
+ end
+ end
+ }.should raise_error(ArgumentError, "only cause is given with no arguments")
+ end
+ end
+ end
end
diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb
index 0abba5301e..a154da6274 100644
--- a/spec/ruby/shared/queue/deque.rb
+++ b/spec/ruby/shared/queue/deque.rb
@@ -65,66 +65,64 @@ describe :queue_deq, shared: true do
end
describe "with a timeout" do
- ruby_version_is "3.2" do
- it "returns an item if one is available in time" do
- q = @object.call
-
- t = Thread.new {
- q.send(@method, timeout: TIME_TOLERANCE).should == 1
- }
- Thread.pass until t.status == "sleep" && q.num_waiting == 1
- q << 1
- t.join
- end
-
- it "returns nil if no item is available in time" do
- q = @object.call
-
- Thread.new {
- q.send(@method, timeout: 0.001).should == nil
- }.join
- end
-
- it "does nothing if the timeout is nil" do
- q = @object.call
- t = Thread.new {
- q.send(@method, timeout: nil).should == 1
- }
- Thread.pass until t.status == "sleep" && q.num_waiting == 1
- q << 1
- t.join
- end
-
- it "immediately returns nil if no item is available and the timeout is 0" do
- q = @object.call
- q << 1
- q.send(@method, timeout: 0).should == 1
- q.send(@method, timeout: 0).should == nil
- end
-
- it "raise TypeError if timeout is not a valid numeric" do
- q = @object.call
- -> {
- q.send(@method, timeout: "1")
- }.should raise_error(TypeError, "no implicit conversion to float from string")
-
- -> {
- q.send(@method, timeout: false)
- }.should raise_error(TypeError, "no implicit conversion to float from false")
- end
-
- it "raise ArgumentError if non_block = true is passed too" do
- q = @object.call
- -> {
- q.send(@method, true, timeout: 1)
- }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
- end
-
- it "returns nil for a closed empty queue" do
- q = @object.call
- q.close
- q.send(@method, timeout: 0).should == nil
- end
+ it "returns an item if one is available in time" do
+ q = @object.call
+
+ t = Thread.new {
+ q.send(@method, timeout: TIME_TOLERANCE).should == 1
+ }
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
+ q << 1
+ t.join
+ end
+
+ it "returns nil if no item is available in time" do
+ q = @object.call
+
+ Thread.new {
+ q.send(@method, timeout: 0.001).should == nil
+ }.join
+ end
+
+ it "does nothing if the timeout is nil" do
+ q = @object.call
+ t = Thread.new {
+ q.send(@method, timeout: nil).should == 1
+ }
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
+ q << 1
+ t.join
+ end
+
+ it "immediately returns nil if no item is available and the timeout is 0" do
+ q = @object.call
+ q << 1
+ q.send(@method, timeout: 0).should == 1
+ q.send(@method, timeout: 0).should == nil
+ end
+
+ it "raise TypeError if timeout is not a valid numeric" do
+ q = @object.call
+ -> {
+ q.send(@method, timeout: "1")
+ }.should raise_error(TypeError, "no implicit conversion to float from string")
+
+ -> {
+ q.send(@method, timeout: false)
+ }.should raise_error(TypeError, "no implicit conversion to float from false")
+ end
+
+ it "raise ArgumentError if non_block = true is passed too" do
+ q = @object.call
+ -> {
+ q.send(@method, true, timeout: 1)
+ }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
+ end
+
+ it "returns nil for a closed empty queue" do
+ q = @object.call
+ q.close
+ q.send(@method, timeout: 0).should == nil
end
end
diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb
index 2f25517675..6804af3fb3 100644
--- a/spec/ruby/shared/sizedqueue/enque.rb
+++ b/spec/ruby/shared/sizedqueue/enque.rb
@@ -49,83 +49,81 @@ describe :sizedqueue_enq, shared: true do
end
describe "with a timeout" do
- ruby_version_is "3.2" do
- it "returns self if the item was pushed in time" do
- q = @object.call(1)
- q << 1
-
- t = Thread.new {
- q.send(@method, 2, timeout: TIME_TOLERANCE).should == q
- }
- Thread.pass until t.status == "sleep" && q.num_waiting == 1
- q.pop
- t.join
- end
-
- it "does nothing if the timeout is nil" do
- q = @object.call(1)
- q << 1
- t = Thread.new {
- q.send(@method, 2, timeout: nil).should == q
- }
- t.join(0.2).should == nil
- q.pop
- t.join
- end
-
- it "returns nil if no space is available and timeout is 0" do
- q = @object.call(1)
- q.send(@method, 1, timeout: 0).should == q
- q.send(@method, 2, timeout: 0).should == nil
- end
-
- it "returns nil if no space is available in time" do
- q = @object.call(1)
- q << 1
- Thread.new {
- q.send(@method, 2, timeout: 0.001).should == nil
- }.join
- end
-
- it "raise TypeError if timeout is not a valid numeric" do
- q = @object.call(1)
- -> {
- q.send(@method, 2, timeout: "1")
- }.should raise_error(TypeError, "no implicit conversion to float from string")
-
- -> {
- q.send(@method, 2, timeout: false)
- }.should raise_error(TypeError, "no implicit conversion to float from false")
- end
-
- it "raise ArgumentError if non_block = true is passed too" do
- q = @object.call(1)
- -> {
- q.send(@method, 2, true, timeout: 1)
- }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
- end
-
- it "raise ClosedQueueError when closed before enqueued" do
- q = @object.call(1)
- q.close
- -> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed")
- end
-
- it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do
- q = @object.call(1)
- q << 1
-
- t = Thread.new {
- -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed")
- }
-
- Thread.pass until q.num_waiting == 1
-
- q.close
-
- t.join
- q.pop.should == 1
- end
+ it "returns self if the item was pushed in time" do
+ q = @object.call(1)
+ q << 1
+
+ t = Thread.new {
+ q.send(@method, 2, timeout: TIME_TOLERANCE).should == q
+ }
+ Thread.pass until t.status == "sleep" && q.num_waiting == 1
+ q.pop
+ t.join
+ end
+
+ it "does nothing if the timeout is nil" do
+ q = @object.call(1)
+ q << 1
+ t = Thread.new {
+ q.send(@method, 2, timeout: nil).should == q
+ }
+ t.join(0.2).should == nil
+ q.pop
+ t.join
+ end
+
+ it "returns nil if no space is available and timeout is 0" do
+ q = @object.call(1)
+ q.send(@method, 1, timeout: 0).should == q
+ q.send(@method, 2, timeout: 0).should == nil
+ end
+
+ it "returns nil if no space is available in time" do
+ q = @object.call(1)
+ q << 1
+ Thread.new {
+ q.send(@method, 2, timeout: 0.001).should == nil
+ }.join
+ end
+
+ it "raise TypeError if timeout is not a valid numeric" do
+ q = @object.call(1)
+ -> {
+ q.send(@method, 2, timeout: "1")
+ }.should raise_error(TypeError, "no implicit conversion to float from string")
+
+ -> {
+ q.send(@method, 2, timeout: false)
+ }.should raise_error(TypeError, "no implicit conversion to float from false")
+ end
+
+ it "raise ArgumentError if non_block = true is passed too" do
+ q = @object.call(1)
+ -> {
+ q.send(@method, 2, true, timeout: 1)
+ }.should raise_error(ArgumentError, "can't set a timeout if non_block is enabled")
+ end
+
+ it "raise ClosedQueueError when closed before enqueued" do
+ q = @object.call(1)
+ q.close
+ -> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed")
+ end
+
+ it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do
+ q = @object.call(1)
+ q << 1
+
+ t = Thread.new {
+ -> { q.send(@method, 1, timeout: TIME_TOLERANCE) }.should raise_error(ClosedQueueError, "queue closed")
+ }
+
+ Thread.pass until q.num_waiting == 1
+
+ q.close
+
+ t.join
+ q.pop.should == 1
end
end
end