From cbd7925d720683cf6949a8fd821505f096fc7882 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 12 May 2025 15:22:52 +0300 Subject: [PATCH 1/5] Update to ruby/spec@f8c065e --- spec/ruby/.rubocop.yml | 2 +- spec/ruby/README.md | 5 +- spec/ruby/command_line/dash_0_spec.rb | 13 + spec/ruby/core/array/pack/a_spec.rb | 4 +- spec/ruby/core/array/pack/shared/basic.rb | 11 +- spec/ruby/core/array/pack/z_spec.rb | 2 +- spec/ruby/core/array/shared/slice.rb | 184 +++--- spec/ruby/core/class/attached_object_spec.rb | 40 +- .../core/class/fixtures/callback_order.rb | 31 - spec/ruby/core/class/inherited_spec.rb | 24 +- spec/ruby/core/complex/polar_spec.rb | 24 +- spec/ruby/core/data/constants_spec.rb | 20 +- spec/ruby/core/data/deconstruct_keys_spec.rb | 202 +++---- spec/ruby/core/data/deconstruct_spec.rb | 8 +- spec/ruby/core/data/define_spec.rb | 48 +- spec/ruby/core/data/eql_spec.rb | 92 ++- spec/ruby/core/data/equal_value_spec.rb | 92 ++- spec/ruby/core/data/fixtures/classes.rb | 2 +- spec/ruby/core/data/hash_spec.rb | 36 +- spec/ruby/core/data/initialize_spec.rb | 94 ++- spec/ruby/core/data/inspect_spec.rb | 6 +- spec/ruby/core/data/members_spec.rb | 26 +- spec/ruby/core/data/to_h_spec.rb | 94 ++- spec/ruby/core/data/to_s_spec.rb | 6 +- spec/ruby/core/data/with_spec.rb | 46 +- spec/ruby/core/dir/chdir_spec.rb | 2 +- spec/ruby/core/dir/close_spec.rb | 6 +- spec/ruby/core/dir/exist_spec.rb | 8 +- spec/ruby/core/dir/fchdir_spec.rb | 4 +- spec/ruby/core/dir/fixtures/common.rb | 10 +- spec/ruby/core/dir/for_fd_spec.rb | 4 +- spec/ruby/core/dir/home_spec.rb | 46 +- spec/ruby/core/dir/shared/delete.rb | 18 +- spec/ruby/core/encoding/replicate_spec.rb | 2 +- spec/ruby/core/enumerable/filter_spec.rb | 2 +- spec/ruby/core/enumerable/fixtures/classes.rb | 5 +- spec/ruby/core/enumerable/shared/inject.rb | 8 +- spec/ruby/core/enumerable/to_set_spec.rb | 38 +- .../ruby/core/enumerator/product/each_spec.rb | 108 ++-- .../product/initialize_copy_spec.rb | 74 ++- .../enumerator/product/initialize_spec.rb | 44 +- .../core/enumerator/product/inspect_spec.rb | 28 +- .../core/enumerator/product/rewind_spec.rb | 90 ++- .../ruby/core/enumerator/product/size_spec.rb | 102 ++-- spec/ruby/core/enumerator/product_spec.rb | 138 +++-- spec/ruby/core/env/clone_spec.rb | 10 +- spec/ruby/core/env/shared/update.rb | 10 +- .../core/exception/detailed_message_spec.rb | 70 ++- spec/ruby/core/exception/full_message_spec.rb | 70 ++- spec/ruby/core/exception/syntax_error_spec.rb | 36 +- spec/ruby/core/fiber/blocking_spec.rb | 20 +- spec/ruby/core/fiber/storage_spec.rb | 268 ++++----- spec/ruby/core/file/empty_spec.rb | 6 - spec/ruby/core/file/exist_spec.rb | 8 +- spec/ruby/core/file/flock_spec.rb | 32 - spec/ruby/core/file/lchmod_spec.rb | 2 +- spec/ruby/core/file/setuid_spec.rb | 4 - spec/ruby/core/file/stat/rdev_major_spec.rb | 13 +- spec/ruby/core/file/stat/rdev_minor_spec.rb | 13 +- spec/ruby/core/file/zero_spec.rb | 6 - spec/ruby/core/filetest/exist_spec.rb | 8 +- spec/ruby/core/filetest/zero_spec.rb | 6 - spec/ruby/core/hash/shared/to_s.rb | 6 + spec/ruby/core/hash/shift_spec.rb | 41 +- spec/ruby/core/integer/ceildiv_spec.rb | 26 +- spec/ruby/core/integer/constants_spec.rb | 36 +- spec/ruby/core/integer/left_shift_spec.rb | 6 +- spec/ruby/core/integer/right_shift_spec.rb | 6 +- spec/ruby/core/io/path_spec.rb | 14 +- spec/ruby/core/io/shared/each.rb | 18 +- spec/ruby/core/io/sysread_spec.rb | 6 +- spec/ruby/core/kernel/match_spec.rb | 27 +- spec/ruby/core/kernel/not_match_spec.rb | 14 +- spec/ruby/core/kernel/open_spec.rb | 2 +- spec/ruby/core/kernel/require_spec.rb | 3 + spec/ruby/core/kernel/shared/sprintf.rb | 30 +- spec/ruby/core/kernel/taint_spec.rb | 23 +- spec/ruby/core/kernel/tainted_spec.rb | 25 +- spec/ruby/core/kernel/trust_spec.rb | 24 +- spec/ruby/core/kernel/untaint_spec.rb | 24 +- spec/ruby/core/kernel/untrust_spec.rb | 23 +- spec/ruby/core/kernel/untrusted_spec.rb | 24 +- spec/ruby/core/main/using_spec.rb | 10 +- spec/ruby/core/marshal/dump_spec.rb | 38 +- .../core/marshal/fixtures/marshal_data.rb | 22 +- spec/ruby/core/marshal/shared/load.rb | 40 +- spec/ruby/core/matchdata/byteoffset_spec.rb | 132 ++-- .../core/matchdata/deconstruct_keys_spec.rb | 86 ++- spec/ruby/core/matchdata/deconstruct_spec.rb | 4 +- spec/ruby/core/method/owner_spec.rb | 6 +- spec/ruby/core/method/parameters_spec.rb | 26 +- spec/ruby/core/method/private_spec.rb | 25 +- spec/ruby/core/method/protected_spec.rb | 25 +- spec/ruby/core/method/public_spec.rb | 25 +- spec/ruby/core/method/unbind_spec.rb | 12 +- spec/ruby/core/module/autoload_spec.rb | 48 +- spec/ruby/core/module/const_added_spec.rb | 291 +++++---- spec/ruby/core/module/include_spec.rb | 28 +- spec/ruby/core/module/instance_method_spec.rb | 5 - spec/ruby/core/module/name_spec.rb | 52 +- spec/ruby/core/module/prepend_spec.rb | 28 +- spec/ruby/core/module/refine_spec.rb | 26 - spec/ruby/core/module/refinements_spec.rb | 56 +- spec/ruby/core/module/ruby2_keywords_spec.rb | 154 ++--- .../module/undefined_instance_methods_spec.rb | 32 +- .../ruby/core/module/used_refinements_spec.rb | 110 ++-- spec/ruby/core/proc/parameters_spec.rb | 56 +- spec/ruby/core/proc/shared/dup.rb | 8 +- spec/ruby/core/process/_fork_spec.rb | 2 + spec/ruby/core/process/fixtures/clocks.rb | 2 +- spec/ruby/core/process/setrlimit_spec.rb | 28 +- spec/ruby/core/queue/deq_spec.rb | 4 +- spec/ruby/core/queue/pop_spec.rb | 4 +- spec/ruby/core/queue/shift_spec.rb | 4 +- spec/ruby/core/random/default_spec.rb | 32 +- spec/ruby/core/range/case_compare_spec.rb | 2 +- spec/ruby/core/range/last_spec.rb | 6 +- spec/ruby/core/range/size_spec.rb | 11 +- spec/ruby/core/rational/exponent_spec.rb | 8 +- .../core/refinement/append_features_spec.rb | 24 +- .../core/refinement/extend_object_spec.rb | 28 +- spec/ruby/core/refinement/include_spec.rb | 26 +- .../core/refinement/prepend_features_spec.rb | 24 +- spec/ruby/core/refinement/prepend_spec.rb | 26 +- .../core/refinement/refined_class_spec.rb | 2 +- spec/ruby/core/regexp/linear_time_spec.rb | 40 +- spec/ruby/core/regexp/shared/new.rb | 167 ++--- spec/ruby/core/regexp/timeout_spec.rb | 48 +- spec/ruby/{library => core}/set/add_spec.rb | 1 - .../ruby/{library => core}/set/append_spec.rb | 1 - .../set/case_compare_spec.rb | 1 - .../set/case_equality_spec.rb | 1 - .../{library => core}/set/classify_spec.rb | 1 - spec/ruby/{library => core}/set/clear_spec.rb | 1 - .../{library => core}/set/collect_spec.rb | 1 - .../set/compare_by_identity_spec.rb | 22 +- .../{library => core}/set/comparison_spec.rb | 1 - .../{library => core}/set/constructor_spec.rb | 1 - .../{library => core}/set/delete_if_spec.rb | 1 - .../ruby/{library => core}/set/delete_spec.rb | 1 - .../{library => core}/set/difference_spec.rb | 1 - .../{library => core}/set/disjoint_spec.rb | 1 - .../ruby/{library => core}/set/divide_spec.rb | 19 +- spec/ruby/{library => core}/set/each_spec.rb | 1 - spec/ruby/{library => core}/set/empty_spec.rb | 1 - .../set/enumerable/to_set_spec.rb | 1 - spec/ruby/{library => core}/set/eql_spec.rb | 1 - .../{library => core}/set/equal_value_spec.rb | 9 +- .../{library => core}/set/exclusion_spec.rb | 1 - .../ruby/{library => core}/set/filter_spec.rb | 0 .../set/fixtures/set_like.rb | 1 - spec/ruby/core/set/flatten_merge_spec.rb | 24 + .../{library => core}/set/flatten_spec.rb | 17 +- spec/ruby/{library => core}/set/hash_spec.rb | 9 +- .../{library => core}/set/include_spec.rb | 1 - .../set/initialize_clone_spec.rb | 1 - .../{library => core}/set/initialize_spec.rb | 1 - .../{library => core}/set/inspect_spec.rb | 1 - .../{library => core}/set/intersect_spec.rb | 1 - .../set/intersection_spec.rb | 1 - spec/ruby/{library => core}/set/join_spec.rb | 11 +- .../{library => core}/set/keep_if_spec.rb | 1 - .../ruby/{library => core}/set/length_spec.rb | 1 - spec/ruby/{library => core}/set/map_spec.rb | 1 - .../ruby/{library => core}/set/member_spec.rb | 1 - spec/ruby/{library => core}/set/merge_spec.rb | 1 - spec/ruby/{library => core}/set/minus_spec.rb | 1 - spec/ruby/{library => core}/set/plus_spec.rb | 1 - .../set/pretty_print_cycle_spec.rb | 1 - .../set/proper_subset_spec.rb | 9 +- .../set/proper_superset_spec.rb | 9 +- .../ruby/{library => core}/set/reject_spec.rb | 1 - .../{library => core}/set/replace_spec.rb | 1 - .../ruby/{library => core}/set/select_spec.rb | 0 spec/ruby/core/set/set_spec.rb | 10 + spec/ruby/{library => core}/set/shared/add.rb | 0 .../{library => core}/set/shared/collect.rb | 0 .../set/shared/difference.rb | 0 .../{library => core}/set/shared/include.rb | 0 .../{library => core}/set/shared/inspect.rb | 0 .../set/shared/intersection.rb | 0 .../{library => core}/set/shared/length.rb | 0 .../{library => core}/set/shared/select.rb | 1 - .../{library => core}/set/shared/union.rb | 0 spec/ruby/{library => core}/set/size_spec.rb | 1 - .../set/sortedset/sortedset_spec.rb | 1 - .../ruby/{library => core}/set/subset_spec.rb | 9 +- .../{library => core}/set/subtract_spec.rb | 1 - .../{library => core}/set/superset_spec.rb | 9 +- spec/ruby/{library => core}/set/to_a_spec.rb | 1 - spec/ruby/{library => core}/set/to_s_spec.rb | 1 - spec/ruby/{library => core}/set/union_spec.rb | 1 - spec/ruby/core/sizedqueue/append_spec.rb | 4 +- spec/ruby/core/sizedqueue/deq_spec.rb | 4 +- spec/ruby/core/sizedqueue/enq_spec.rb | 4 +- spec/ruby/core/sizedqueue/pop_spec.rb | 4 +- spec/ruby/core/sizedqueue/push_spec.rb | 4 +- spec/ruby/core/sizedqueue/shift_spec.rb | 4 +- spec/ruby/core/string/byteindex_spec.rb | 470 +++++++-------- spec/ruby/core/string/byterindex_spec.rb | 568 +++++++++--------- spec/ruby/core/string/bytesplice_spec.rb | 204 +++---- spec/ruby/core/string/dedup_spec.rb | 4 +- spec/ruby/core/string/modulo_spec.rb | 12 +- spec/ruby/core/string/rstrip_spec.rb | 28 +- spec/ruby/core/string/to_c_spec.rb | 20 +- spec/ruby/core/string/to_f_spec.rb | 16 +- spec/ruby/core/string/unpack_spec.rb | 2 +- spec/ruby/core/struct/constants_spec.rb | 16 +- .../ruby/core/struct/deconstruct_keys_spec.rb | 2 +- spec/ruby/core/struct/initialize_spec.rb | 20 +- spec/ruby/core/struct/new_spec.rb | 32 +- spec/ruby/core/symbol/to_proc_spec.rb | 44 +- .../core/thread/each_caller_location_spec.rb | 70 ++- spec/ruby/core/time/deconstruct_keys_spec.rb | 80 ++- spec/ruby/core/time/minus_spec.rb | 2 +- spec/ruby/core/time/new_spec.rb | 398 ++++++------ spec/ruby/core/time/now_spec.rb | 142 +++-- spec/ruby/core/tracepoint/enable_spec.rb | 55 +- .../core/unboundmethod/equal_value_spec.rb | 39 +- spec/ruby/core/unboundmethod/owner_spec.rb | 6 +- spec/ruby/core/unboundmethod/private_spec.rb | 25 +- .../ruby/core/unboundmethod/protected_spec.rb | 25 +- spec/ruby/core/unboundmethod/public_spec.rb | 25 +- spec/ruby/core/unboundmethod/shared/to_s.rb | 15 +- spec/ruby/language/assignments_spec.rb | 75 +-- spec/ruby/language/block_spec.rb | 80 +-- spec/ruby/language/constants_spec.rb | 34 +- spec/ruby/language/delegation_spec.rb | 68 +-- .../fixtures/class_with_class_variable.rb | 2 +- spec/ruby/language/keyword_arguments_spec.rb | 62 +- spec/ruby/language/module_spec.rb | 19 +- spec/ruby/language/predefined_spec.rb | 75 ++- .../language/regexp/character_classes_spec.rb | 4 +- spec/ruby/language/variables_spec.rb | 19 +- spec/ruby/library/bigdecimal/round_spec.rb | 12 +- spec/ruby/library/cgi/cookie/domain_spec.rb | 33 +- spec/ruby/library/cgi/cookie/expires_spec.rb | 33 +- .../library/cgi/cookie/initialize_spec.rb | 235 ++++---- spec/ruby/library/cgi/cookie/name_spec.rb | 33 +- spec/ruby/library/cgi/cookie/parse_spec.rb | 41 +- spec/ruby/library/cgi/cookie/path_spec.rb | 33 +- spec/ruby/library/cgi/cookie/secure_spec.rb | 99 +-- spec/ruby/library/cgi/cookie/to_s_spec.rb | 51 +- spec/ruby/library/cgi/cookie/value_spec.rb | 121 ++-- spec/ruby/library/cgi/escapeElement_spec.rb | 6 +- spec/ruby/library/cgi/escapeHTML_spec.rb | 6 +- .../library/cgi/escapeURIComponent_spec.rb | 88 +-- spec/ruby/library/cgi/escape_spec.rb | 6 +- spec/ruby/library/cgi/htmlextension/a_spec.rb | 73 +-- .../library/cgi/htmlextension/base_spec.rb | 47 +- .../cgi/htmlextension/blockquote_spec.rb | 47 +- .../ruby/library/cgi/htmlextension/br_spec.rb | 31 +- .../library/cgi/htmlextension/caption_spec.rb | 47 +- .../cgi/htmlextension/checkbox_group_spec.rb | 121 ++-- .../cgi/htmlextension/checkbox_spec.rb | 113 ++-- .../library/cgi/htmlextension/doctype_spec.rb | 41 +- .../cgi/htmlextension/file_field_spec.rb | 105 ++-- .../library/cgi/htmlextension/form_spec.rb | 85 +-- .../library/cgi/htmlextension/frame_spec.rb | 21 +- .../cgi/htmlextension/frameset_spec.rb | 21 +- .../library/cgi/htmlextension/hidden_spec.rb | 87 +-- .../library/cgi/htmlextension/html_spec.rb | 99 +-- .../cgi/htmlextension/image_button_spec.rb | 101 ++-- .../library/cgi/htmlextension/img_spec.rb | 123 ++-- .../cgi/htmlextension/multipart_form_spec.rb | 93 +-- .../cgi/htmlextension/password_field_spec.rb | 123 ++-- .../cgi/htmlextension/popup_menu_spec.rb | 13 +- .../cgi/htmlextension/radio_button_spec.rb | 113 ++-- .../cgi/htmlextension/radio_group_spec.rb | 123 ++-- .../library/cgi/htmlextension/reset_spec.rb | 83 +-- .../cgi/htmlextension/scrolling_list_spec.rb | 13 +- .../library/cgi/htmlextension/submit_spec.rb | 83 +-- .../cgi/htmlextension/text_field_spec.rb | 123 ++-- .../cgi/htmlextension/textarea_spec.rb | 107 ++-- spec/ruby/library/cgi/http_header_spec.rb | 11 +- spec/ruby/library/cgi/initialize_spec.rb | 209 +++---- spec/ruby/library/cgi/out_spec.rb | 97 +-- spec/ruby/library/cgi/parse_spec.rb | 37 +- spec/ruby/library/cgi/pretty_spec.rb | 19 +- spec/ruby/library/cgi/print_spec.rb | 39 +- .../cgi/queryextension/accept_charset_spec.rb | 33 +- .../queryextension/accept_encoding_spec.rb | 33 +- .../queryextension/accept_language_spec.rb | 33 +- .../library/cgi/queryextension/accept_spec.rb | 33 +- .../cgi/queryextension/auth_type_spec.rb | 33 +- .../cgi/queryextension/cache_control_spec.rb | 33 +- .../cgi/queryextension/content_length_spec.rb | 39 +- .../cgi/queryextension/content_type_spec.rb | 33 +- .../cgi/queryextension/cookies_spec.rb | 15 +- .../queryextension/element_reference_spec.rb | 41 +- .../library/cgi/queryextension/from_spec.rb | 33 +- .../queryextension/gateway_interface_spec.rb | 33 +- .../cgi/queryextension/has_key_spec.rb | 11 +- .../library/cgi/queryextension/host_spec.rb | 33 +- .../cgi/queryextension/include_spec.rb | 11 +- .../library/cgi/queryextension/key_spec.rb | 11 +- .../library/cgi/queryextension/keys_spec.rb | 29 +- .../cgi/queryextension/multipart_spec.rb | 47 +- .../cgi/queryextension/negotiate_spec.rb | 33 +- .../library/cgi/queryextension/params_spec.rb | 55 +- .../cgi/queryextension/path_info_spec.rb | 33 +- .../queryextension/path_translated_spec.rb | 33 +- .../library/cgi/queryextension/pragma_spec.rb | 33 +- .../cgi/queryextension/query_string_spec.rb | 33 +- .../cgi/queryextension/raw_cookie2_spec.rb | 33 +- .../cgi/queryextension/raw_cookie_spec.rb | 33 +- .../cgi/queryextension/referer_spec.rb | 33 +- .../cgi/queryextension/remote_addr_spec.rb | 33 +- .../cgi/queryextension/remote_host_spec.rb | 33 +- .../cgi/queryextension/remote_ident_spec.rb | 33 +- .../cgi/queryextension/remote_user_spec.rb | 33 +- .../cgi/queryextension/request_method_spec.rb | 33 +- .../cgi/queryextension/script_name_spec.rb | 33 +- .../cgi/queryextension/server_name_spec.rb | 33 +- .../cgi/queryextension/server_port_spec.rb | 39 +- .../queryextension/server_protocol_spec.rb | 33 +- .../queryextension/server_software_spec.rb | 33 +- .../cgi/queryextension/user_agent_spec.rb | 33 +- spec/ruby/library/cgi/rfc1123_date_spec.rb | 15 +- spec/ruby/library/cgi/unescapeElement_spec.rb | 6 +- spec/ruby/library/cgi/unescapeHTML_spec.rb | 6 +- spec/ruby/library/cgi/unescape_spec.rb | 6 +- spec/ruby/library/coverage/result_spec.rb | 112 ++-- spec/ruby/library/coverage/start_spec.rb | 114 ++-- spec/ruby/library/coverage/supported_spec.rb | 42 +- .../library/date/deconstruct_keys_spec.rb | 74 ++- .../library/datetime/deconstruct_keys_spec.rb | 78 ++- .../library/datetime/time/to_datetime_spec.rb | 20 +- spec/ruby/library/datetime/to_time_spec.rb | 20 +- .../library/io-wait/wait_readable_spec.rb | 4 - spec/ruby/library/io-wait/wait_spec.rb | 61 +- .../library/io-wait/wait_writable_spec.rb | 4 - .../trace_object_allocations_spec.rb | 32 +- spec/ruby/library/openssl/kdf/scrypt_spec.rb | 3 +- .../rbconfig/unicode_emoji_version_spec.rb | 12 +- .../library/rbconfig/unicode_version_spec.rb | 12 +- spec/ruby/library/set/flatten_merge_spec.rb | 23 - spec/ruby/library/set/set_spec.rb | 12 - .../socket/addrinfo/getaddrinfo_spec.rb | 16 +- .../socket/addrinfo/initialize_spec.rb | 6 +- .../socket/addrinfo/marshal_dump_spec.rb | 6 +- spec/ruby/library/socket/addrinfo/udp_spec.rb | 6 +- .../socket/ancillarydata/initialize_spec.rb | 2 +- .../socket/ancillarydata/unix_rights_spec.rb | 2 +- .../library/socket/basicsocket/recv_spec.rb | 36 +- .../library/socket/basicsocket/send_spec.rb | 2 +- .../socket/constants/constants_spec.rb | 2 +- .../library/socket/shared/pack_sockaddr.rb | 31 +- .../socket/socket/connect_nonblock_spec.rb | 58 +- .../library/socket/socket/getaddrinfo_spec.rb | 2 +- .../socket/socket/gethostbyaddr_spec.rb | 7 +- .../library/socket/socket/getifaddrs_spec.rb | 2 +- .../library/socket/tcpsocket/shared/new.rb | 27 +- spec/ruby/library/stringio/fileno_spec.rb | 3 +- spec/ruby/library/stringio/shared/each.rb | 21 +- .../stringscanner/named_captures_spec.rb | 42 +- spec/ruby/library/stringscanner/shared/pos.rb | 7 + spec/ruby/library/syslog/constants_spec.rb | 2 +- spec/ruby/library/syslog/log_spec.rb | 2 +- spec/ruby/library/syslog/shared/log.rb | 2 +- spec/ruby/library/uri/generic/host_spec.rb | 8 +- spec/ruby/library/uri/generic/to_s_spec.rb | 8 +- spec/ruby/optional/capi/binding_spec.rb | 18 +- spec/ruby/optional/capi/class_spec.rb | 11 - spec/ruby/optional/capi/digest_spec.rb | 2 +- spec/ruby/optional/capi/encoding_spec.rb | 14 +- spec/ruby/optional/capi/ext/class_spec.c | 4 - spec/ruby/optional/capi/ext/constants_spec.c | 6 - spec/ruby/optional/capi/ext/digest_spec.c | 2 +- spec/ruby/optional/capi/ext/fiber_spec.c | 5 - spec/ruby/optional/capi/ext/hash_spec.c | 4 - spec/ruby/optional/capi/ext/io_spec.c | 32 - spec/ruby/optional/capi/ext/kernel_spec.c | 4 - spec/ruby/optional/capi/ext/object_spec.c | 36 -- spec/ruby/optional/capi/ext/rbasic_spec.c | 10 - spec/ruby/optional/capi/ext/rubyspec.h | 16 +- spec/ruby/optional/capi/ext/string_spec.c | 14 - spec/ruby/optional/capi/ext/thread_spec.c | 10 +- spec/ruby/optional/capi/fixtures/class.rb | 10 - spec/ruby/optional/capi/hash_spec.rb | 20 +- spec/ruby/optional/capi/kernel_spec.rb | 6 +- spec/ruby/optional/capi/object_spec.rb | 2 +- spec/ruby/optional/capi/shared/rbasic.rb | 1 - spec/ruby/optional/capi/string_spec.rb | 8 +- spec/ruby/optional/capi/thread_spec.rb | 8 + spec/ruby/security/cve_2020_10663_spec.rb | 71 +-- spec/ruby/security/cve_2024_49761_spec.rb | 8 +- spec/ruby/shared/file/sticky.rb | 2 +- spec/ruby/shared/queue/deque.rb | 118 ++-- spec/ruby/shared/sizedqueue/enque.rb | 152 +++-- 390 files changed, 6278 insertions(+), 7362 deletions(-) create mode 100755 spec/ruby/command_line/dash_0_spec.rb delete mode 100644 spec/ruby/core/class/fixtures/callback_order.rb rename spec/ruby/{library => core}/set/add_spec.rb (97%) rename spec/ruby/{library => core}/set/append_spec.rb (89%) rename spec/ruby/{library => core}/set/case_compare_spec.rb (94%) rename spec/ruby/{library => core}/set/case_equality_spec.rb (90%) rename spec/ruby/{library => core}/set/classify_spec.rb (98%) rename spec/ruby/{library => core}/set/clear_spec.rb (95%) rename spec/ruby/{library => core}/set/collect_spec.rb (91%) rename spec/ruby/{library => core}/set/compare_by_identity_spec.rb (88%) rename spec/ruby/{library => core}/set/comparison_spec.rb (98%) rename spec/ruby/{library => core}/set/constructor_spec.rb (95%) rename spec/ruby/{library => core}/set/delete_if_spec.rb (98%) rename spec/ruby/{library => core}/set/delete_spec.rb (98%) rename spec/ruby/{library => core}/set/difference_spec.rb (91%) rename spec/ruby/{library => core}/set/disjoint_spec.rb (98%) rename spec/ruby/{library => core}/set/divide_spec.rb (82%) rename spec/ruby/{library => core}/set/each_spec.rb (97%) rename spec/ruby/{library => core}/set/empty_spec.rb (93%) rename spec/ruby/{library => core}/set/enumerable/to_set_spec.rb (95%) rename spec/ruby/{library => core}/set/eql_spec.rb (96%) rename spec/ruby/{library => core}/set/equal_value_spec.rb (77%) rename spec/ruby/{library => core}/set/exclusion_spec.rb (97%) rename spec/ruby/{library => core}/set/filter_spec.rb (100%) rename spec/ruby/{library => core}/set/fixtures/set_like.rb (97%) create mode 100644 spec/ruby/core/set/flatten_merge_spec.rb rename spec/ruby/{library => core}/set/flatten_spec.rb (76%) rename spec/ruby/{library => core}/set/hash_spec.rb (64%) rename spec/ruby/{library => core}/set/include_spec.rb (91%) rename spec/ruby/{library => core}/set/initialize_clone_spec.rb (96%) rename spec/ruby/{library => core}/set/initialize_spec.rb (99%) rename spec/ruby/{library => core}/set/inspect_spec.rb (91%) rename spec/ruby/{library => core}/set/intersect_spec.rb (98%) rename spec/ruby/{library => core}/set/intersection_spec.rb (94%) rename spec/ruby/{library => core}/set/join_spec.rb (73%) rename spec/ruby/{library => core}/set/keep_if_spec.rb (98%) rename spec/ruby/{library => core}/set/length_spec.rb (90%) rename spec/ruby/{library => core}/set/map_spec.rb (91%) rename spec/ruby/{library => core}/set/member_spec.rb (91%) rename spec/ruby/{library => core}/set/merge_spec.rb (98%) rename spec/ruby/{library => core}/set/minus_spec.rb (90%) rename spec/ruby/{library => core}/set/plus_spec.rb (90%) rename spec/ruby/{library => core}/set/pretty_print_cycle_spec.rb (95%) rename spec/ruby/{library => core}/set/proper_subset_spec.rb (83%) rename spec/ruby/{library => core}/set/proper_superset_spec.rb (82%) rename spec/ruby/{library => core}/set/reject_spec.rb (98%) rename spec/ruby/{library => core}/set/replace_spec.rb (96%) rename spec/ruby/{library => core}/set/select_spec.rb (100%) create mode 100644 spec/ruby/core/set/set_spec.rb rename spec/ruby/{library => core}/set/shared/add.rb (100%) rename spec/ruby/{library => core}/set/shared/collect.rb (100%) rename spec/ruby/{library => core}/set/shared/difference.rb (100%) rename spec/ruby/{library => core}/set/shared/include.rb (100%) rename spec/ruby/{library => core}/set/shared/inspect.rb (100%) rename spec/ruby/{library => core}/set/shared/intersection.rb (100%) rename spec/ruby/{library => core}/set/shared/length.rb (100%) rename spec/ruby/{library => core}/set/shared/select.rb (98%) rename spec/ruby/{library => core}/set/shared/union.rb (100%) rename spec/ruby/{library => core}/set/size_spec.rb (90%) rename spec/ruby/{library => core}/set/sortedset/sortedset_spec.rb (96%) rename spec/ruby/{library => core}/set/subset_spec.rb (82%) rename spec/ruby/{library => core}/set/subtract_spec.rb (96%) rename spec/ruby/{library => core}/set/superset_spec.rb (82%) rename spec/ruby/{library => core}/set/to_a_spec.rb (92%) rename spec/ruby/{library => core}/set/to_s_spec.rb (94%) rename spec/ruby/{library => core}/set/union_spec.rb (93%) delete mode 100644 spec/ruby/library/set/flatten_merge_spec.rb delete mode 100644 spec/ruby/library/set/set_spec.rb diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml index a385b5e79c6f..68cce312808b 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 diff --git a/spec/ruby/README.md b/spec/ruby/README.md index ee1015c24c4c..56d6c3c5426a 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -30,8 +30,8 @@ ruby/spec is known to be tested in these implementations for every commit: * [Opal](https://github.com/opal/opal/tree/master/spec) * [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor) -ruby/spec describes the behavior of Ruby 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 new file mode 100755 index 000000000000..73c5e29004eb --- /dev/null +++ b/spec/ruby/command_line/dash_0_spec.rb @@ -0,0 +1,13 @@ +require_relative '../spec_helper' + +describe "The -0 command line option" do + it "sets $/ and $-0" do + ruby_exe("puts $/, $-0", options: "-072").should == ":\n:\n" + end + + ruby_version_is "3.5" do + it "sets $/ and $-0 as a frozen string" do + ruby_exe("puts $/.frozen?, $-0.frozen?", options: "-072").should == "true\ntrue\n" + end + end +end diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb index f4a40502c27d..75b8d63b1e60 100644 --- a/spec/ruby/core/array/pack/a_spec.rb +++ b/spec/ruby/core/array/pack/a_spec.rb @@ -27,7 +27,7 @@ ["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 @@ ["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/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb index 4b28de7ed040..ebd9f75d9dc6 100644 --- a/spec/ruby/core/array/pack/shared/basic.rb +++ b/spec/ruby/core/array/pack/shared/basic.rb @@ -32,16 +32,7 @@ [@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 + ruby_version_is ""..."3.3" do # https://bugs.ruby-lang.org/issues/19150 # NOTE: it's just a plan of the Ruby core team it "warns that a directive is unknown" do diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb index 5ad3afd69e1d..0757d16e31fe 100644 --- a/spec/ruby/core/array/pack/z_spec.rb +++ b/spec/ruby/core/array/pack/z_spec.rb @@ -26,7 +26,7 @@ ["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 d2866970a55f..b80261d32fd6 100644 --- a/spec/ruby/core/array/shared/slice.rb +++ b/spec/ruby/core/array/shared/slice.rb @@ -754,99 +754,97 @@ def to.to_int() -2 end 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/class/attached_object_spec.rb b/spec/ruby/core/class/attached_object_spec.rb index f1c0f63a444c..8f8a0734c6e7 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/fixtures/callback_order.rb b/spec/ruby/core/class/fixtures/callback_order.rb deleted file mode 100644 index b7b52ab778c3..000000000000 --- a/spec/ruby/core/class/fixtures/callback_order.rb +++ /dev/null @@ -1,31 +0,0 @@ -module CoreClassSpecs - module Callbacks - class Base - def self.inherited(subclass) - subclass.const_set(:INHERITED_NAME, subclass.name) - ORDER << [ - :inherited, - subclass, - eval("defined?(#{subclass.name})"), - Object.const_source_location(subclass.name) ? :location : :unknown_location, - ] - super - end - end - - ORDER = [] - - def self.const_added(const_name) - ORDER << [ - :const_added, - const_name, - eval("defined?(#{const_name})"), - const_source_location(const_name) ? :location : :unknown_location, - ] - super - end - - class Child < Base - end - end -end diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb index 15d0c3ddb942..2a8d1ff813aa 100644 --- a/spec/ruby/core/class/inherited_spec.rb +++ b/spec/ruby/core/class/inherited_spec.rb @@ -1,6 +1,5 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -require_relative 'fixtures/callback_order' describe "Class.inherited" do @@ -99,16 +98,21 @@ class << top; protected :inherited; end -> { Class.new(top) }.should_not raise_error end - it "is invoked after the class is named when using class definition syntax" do - CoreClassSpecs::Callbacks::Child::INHERITED_NAME.should == "CoreClassSpecs::Callbacks::Child" - end + it "if the subclass is assigned to a constant, it is all set" do + ScratchPad.record [] - ruby_version_is "3.5" do # https://bugs.ruby-lang.org/issues/21143 - it "is invoked before `const_added`" do - CoreClassSpecs::Callbacks::ORDER.should == [ - [:inherited, CoreClassSpecs::Callbacks::Child, "constant", :location], - [:const_added, :Child, "constant", :location], - ] + 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#::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/complex/polar_spec.rb b/spec/ruby/core/complex/polar_spec.rb index 3bb3751bc637..56335584efe0 100644 --- a/spec/ruby/core/complex/polar_spec.rb +++ b/spec/ruby/core/complex/polar_spec.rb @@ -11,20 +11,18 @@ ->{ 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 2eb43d501e6d..ad0b1ddea7a1 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 07af87771d8d..5cae4cbd68ca 100644 --- a/spec/ruby/core/data/deconstruct_keys_spec.rb +++ b/spec/ruby/core/data/deconstruct_keys_spec.rb @@ -1,107 +1,105 @@ 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" 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 end diff --git a/spec/ruby/core/data/deconstruct_spec.rb b/spec/ruby/core/data/deconstruct_spec.rb index f0995e8fedf3..4ca0b870396a 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 2aa2c50d4c68..c0b4671e395b 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 906e46316cf7..6958d5de4a98 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 f90a7d7a62c4..d9a0dcff3ecb 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 f0a526517d95..5db263fa208d 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 diff --git a/spec/ruby/core/data/hash_spec.rb b/spec/ruby/core/data/hash_spec.rb index 324a2abca4e9..c23f08a71d61 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 2c36bd3ac484..37a6c8f2dd87 100644 --- a/spec/ruby/core/data/initialize_spec.rb +++ b/spec/ruby/core/data/initialize_spec.rb @@ -1,65 +1,63 @@ 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 + data.amount.should == 42 + data.unit.should == "km" + end - it "accepts String keyword arguments" do - data = DataSpecs::Measure.new("amount" => 42, "unit" => "km") + 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" + 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") - } - 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") + } + 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 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 "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 end diff --git a/spec/ruby/core/data/inspect_spec.rb b/spec/ruby/core/data/inspect_spec.rb index 3d337fac6817..38642910a045 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 1776b0b9c17d..457a90a0d650 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/to_h_spec.rb b/spec/ruby/core/data/to_h_spec.rb index 41d6960c97a3..64816b72510a 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 0b9099f03564..2b4a670e8e30 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 97e34c951f74..9cd2d5733526 100644 --- a/spec/ruby/core/data/with_spec.rb +++ b/spec/ruby/core/data/with_spec.rb @@ -1,35 +1,33 @@ 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") + 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 + data.amount.should == 4 + data.unit.should == "m" + end - it "raises ArgumentError if no keyword arguments are given" do - data = DataSpecs::Measure.new(amount: 42, unit: "km") + it "raises ArgumentError if no keyword arguments are given" do + data = DataSpecs::Measure.new(amount: 42, unit: "km") - -> { - data.with(4, "m") - }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)") - end + -> { + data.with(4, "m") + }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)") end end diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb index 1da9307599e2..015386a9026c 100644 --- a/spec/ruby/core/dir/chdir_spec.rb +++ b/spec/ruby/core/dir/chdir_spec.rb @@ -177,7 +177,7 @@ def to_str; DirSpecs.mock_dir; end 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 5fbf5fcaf29e..f7cce318b8b1 100644 --- a/spec/ruby/core/dir/close_spec.rb +++ b/spec/ruby/core/dir/close_spec.rb @@ -14,7 +14,7 @@ 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 @@ 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 @@ 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 9023de533fd3..0b8e521894d5 100644 --- a/spec/ruby/core/dir/exist_spec.rb +++ b/spec/ruby/core/dir/exist_spec.rb @@ -14,10 +14,8 @@ 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 d9dec13aab03..52600a95f2b8 100644 --- a/spec/ruby/core/dir/fchdir_spec.rb +++ b/spec/ruby/core/dir/fchdir_spec.rb @@ -2,7 +2,7 @@ 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 @@ 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 087f46b331e2..848656c9b9a1 100644 --- a/spec/ruby/core/dir/fixtures/common.rb +++ b/spec/ruby/core/dir/fixtures/common.rb @@ -192,13 +192,7 @@ def self.expected_paths ] 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 3afcc7e94901..ba467f2f86d9 100644 --- a/spec/ruby/core/dir/for_fd_spec.rb +++ b/spec/ruby/core/dir/for_fd_spec.rb @@ -3,7 +3,7 @@ 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 @@ 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 3cf745ab468c..966ac38af3ec 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -33,40 +33,32 @@ 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 describe "when called with the current user name" do - platform_is :solaris do - it "returns the named user's home directory from the user database" do - Dir.home(ENV['USER']).should == `getent passwd #{ENV['USER']}|cut -d: -f6`.chomp - end - end - - platform_is_not :windows, :solaris, :android, :wasi do + platform_is_not :windows, :android, :wasi do it "returns the named user's home directory, from the user database" do Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp end diff --git a/spec/ruby/core/dir/shared/delete.rb b/spec/ruby/core/dir/shared/delete.rb index 49e88360e84a..a81b0597593d 100644 --- a/spec/ruby/core/dir/shared/delete.rb +++ b/spec/ruby/core/dir/shared/delete.rb @@ -17,20 +17,10 @@ Dir.send(@method, p) end - platform_is_not :solaris do - it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do - -> do - Dir.send @method, DirSpecs.mock_rmdir("nonempty") - end.should raise_error(Errno::ENOTEMPTY) - end - end - - platform_is :solaris do - it "raises an Errno::EEXIST when trying to remove a nonempty directory" do - -> do - Dir.send @method, DirSpecs.mock_rmdir("nonempty") - end.should raise_error(Errno::EEXIST) - end + it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do + -> do + Dir.send @method, DirSpecs.mock_rmdir("nonempty") + end.should raise_error(Errno::ENOTEMPTY) end it "raises an Errno::ENOENT when trying to remove a non-existing directory" do diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb index e22673db7d32..8d6f843fdf66 100644 --- a/spec/ruby/core/encoding/replicate_spec.rb +++ b/spec/ruby/core/encoding/replicate_spec.rb @@ -67,7 +67,7 @@ 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 c9ee23c54105..1c3a7e9ff59c 100644 --- a/spec/ruby/core/enumerable/filter_spec.rb +++ b/spec/ruby/core/enumerable/filter_spec.rb @@ -3,5 +3,5 @@ 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 2701c6999c43..e30b57d29423 100644 --- a/spec/ruby/core/enumerable/fixtures/classes.rb +++ b/spec/ruby/core/enumerable/fixtures/classes.rb @@ -343,9 +343,6 @@ def ===(*args) 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 92f220efa4cc..aae9e06c974f 100644 --- a/spec/ruby/core/enumerable/shared/inject.rb +++ b/spec/ruby/core/enumerable/shared/inject.rb @@ -135,10 +135,8 @@ def name.to_str; "-"; end 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 c21a2772c478..966baae1d92d 100644 --- a/spec/ruby/core/enumerable/to_set_spec.rb +++ b/spec/ruby/core/enumerable/to_set_spec.rb @@ -1,29 +1,27 @@ 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 - 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 + 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 - 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 + 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 == "#" - end + output.chomp.should == "#" end end diff --git a/spec/ruby/core/enumerator/product/each_spec.rb b/spec/ruby/core/enumerator/product/each_spec.rb index cabeb9d93a2c..88f115a7124b 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 46e8421322a5..b1b9f3ca9b91 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 4b6056424043..ed2a8a2a1350 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 1ea8e9c49b6f..e0d7441f2677 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 == "#" - end +describe "Enumerator::Product#inspect" do + it "returns a String including enumerators" do + enum = Enumerator::Product.new([1, 2], [:a, :b]) + enum.inspect.should == "#" + 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 == "#]]>" - end + enum << enum_recursive + enum_recursive.inspect.should == "#]]>" + end - it "returns a not initialized representation if #initialized is not called yet" do - Enumerator::Product.allocate.inspect.should == "#" - end + it "returns a not initialized representation if #initialized is not called yet" do + Enumerator::Product.allocate.inspect.should == "#" end end diff --git a/spec/ruby/core/enumerator/product/rewind_spec.rb b/spec/ruby/core/enumerator/product/rewind_spec.rb index e8ee7302397c..2beffaf5c170 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 46958b1a2295..96632d6eeecb 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 0acca6690eb0..83c7cb8e0e86 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 991e4e6774b8..01a29c6ab48a 100644 --- a/spec/ruby/core/env/clone_spec.rb +++ b/spec/ruby/core/env/clone_spec.rb @@ -13,11 +13,9 @@ }.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/shared/update.rb b/spec/ruby/core/env/shared/update.rb index 7d4799955bdd..e1b1c9c290e2 100644 --- a/spec/ruby/core/env/shared/update.rb +++ b/spec/ruby/core/env/shared/update.rb @@ -15,12 +15,10 @@ 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 8178278b2bcc..9df164a1cf39 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 '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(**) - "#{message}" - end - exception.full_message(highlight: false).should.include? "new error" + it "is called by #full_message to allow message customization" do + exception = Exception.new("new error") + def exception.detailed_message(**) + "#{message}" end + exception.full_message(highlight: false).should.include? "new error" + 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#\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#\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/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb index d752083db2fa..b07c6d482911 100644 --- a/spec/ruby/core/exception/full_message_spec.rb +++ b/spec/ruby/core/exception/full_message_spec.rb @@ -165,52 +165,50 @@ 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/ - 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.lines.first.should =~ /DETAILED MESSAGE/ + end - e.full_message(foo: "bar") - options_passed.should == { foo: "bar", highlight: Exception.to_tty? } + 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 "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.full_message(foo: "bar") + options_passed.should == { foo: "bar", highlight: Exception.to_tty? } + end - e = RuntimeError.new("new error") - e.define_singleton_method(:detailed_message) { |**| message } + 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.full_message.lines.first.should =~ /DETAILED MESSAGE/ - end + e = RuntimeError.new("new error") + e.define_singleton_method(:detailed_message) { |**| message } - 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.lines.first.should =~ /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 + 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 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 "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 end diff --git a/spec/ruby/core/exception/syntax_error_spec.rb b/spec/ruby/core/exception/syntax_error_spec.rb index 6cc8522de388..4c713a35077d 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 ed3c05751632..d5caf81fbe14 100644 --- a/spec/ruby/core/fiber/blocking_spec.rb +++ b/spec/ruby/core/fiber/blocking_spec.rb @@ -57,19 +57,17 @@ 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/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb index 03e9e3b822f9..3d39f32009b5 100644 --- a/spec/ruby/core/fiber/storage_spec.rb +++ b/spec/ruby/core/fiber/storage_spec.rb @@ -1,183 +1,179 @@ 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 +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 + 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 "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} + 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 non-hash storage" do - -> { Fiber.new(storage: 42) {} }.should raise_error(TypeError) - 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 frozen hash as storage" do - -> { Fiber.new(storage: {life: 43}.freeze) {} }.should raise_error(FrozenError) - 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 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 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 "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 +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 - 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} +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 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} + 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 non-hash" do - -> { Fiber.current.storage = 42 }.should raise_error(TypeError) - 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 frozen hash" do - -> { Fiber.current.storage = {life: 43}.freeze }.should raise_error(FrozenError) - 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 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 hash with non-symbol keys" do + -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should raise_error(TypeError) end +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 +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 key is not present in the storage of the current fiber" do - Fiber.new(storage: {life: 42}) { Fiber[:death] }.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 + + 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 current fiber has no storage" do - Fiber.new { Fiber[:life] }.resume.should be_nil + 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 "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 - - 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_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 - 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 - 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 "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 + + 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 + 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/empty_spec.rb b/spec/ruby/core/file/empty_spec.rb index 77f132303e53..e8c99416767d 100644 --- a/spec/ruby/core/file/empty_spec.rb +++ b/spec/ruby/core/file/empty_spec.rb @@ -4,10 +4,4 @@ describe "File.empty?" do it_behaves_like :file_zero, :empty?, File it_behaves_like :file_zero_missing, :empty?, File - - platform_is :solaris do - it "returns false for /dev/null" do - File.empty?('/dev/null').should == true - end - end end diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb index 2633376880b9..b5600e5b0781 100644 --- a/spec/ruby/core/file/exist_spec.rb +++ b/spec/ruby/core/file/exist_spec.rb @@ -5,10 +5,8 @@ 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/flock_spec.rb b/spec/ruby/core/file/flock_spec.rb index 070d830bc470..23ddf89ed8f3 100644 --- a/spec/ruby/core/file/flock_spec.rb +++ b/spec/ruby/core/file/flock_spec.rb @@ -72,35 +72,3 @@ end end end - -platform_is :solaris do - describe "File#flock on Solaris" do - before :each do - @name = tmp("flock_test") - touch(@name) - - @read_file = File.open @name, "r" - @write_file = File.open @name, "w" - end - - after :each do - @read_file.flock File::LOCK_UN - @read_file.close - @write_file.flock File::LOCK_UN - @write_file.close - rm_r @name - end - - it "fails with EBADF acquiring exclusive lock on read-only File" do - -> do - @read_file.flock File::LOCK_EX - end.should raise_error(Errno::EBADF) - end - - it "fails with EBADF acquiring shared lock on read-only File" do - -> do - @write_file.flock File::LOCK_SH - end.should raise_error(Errno::EBADF) - end - end -end diff --git a/spec/ruby/core/file/lchmod_spec.rb b/spec/ruby/core/file/lchmod_spec.rb index 7420b95e4a36..3c44374983c4 100644 --- a/spec/ruby/core/file/lchmod_spec.rb +++ b/spec/ruby/core/file/lchmod_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "File.lchmod" do - platform_is_not :linux, :windows, :openbsd, :solaris, :aix do + platform_is_not :linux, :windows, :openbsd, :aix do before :each do @fname = tmp('file_chmod_test') @lname = @fname + '.lnk' diff --git a/spec/ruby/core/file/setuid_spec.rb b/spec/ruby/core/file/setuid_spec.rb index 281ef01ab9ec..9e5e86df6133 100644 --- a/spec/ruby/core/file/setuid_spec.rb +++ b/spec/ruby/core/file/setuid_spec.rb @@ -26,10 +26,6 @@ platform_is_not :windows do it "returns true when the gid bit is set" do - platform_is :solaris do - # Solaris requires execute bit before setting suid - system "chmod u+x #{@name}" - end system "chmod u+s #{@name}" File.setuid?(@name).should == true diff --git a/spec/ruby/core/file/stat/rdev_major_spec.rb b/spec/ruby/core/file/stat/rdev_major_spec.rb index f8a8d1b10727..e08d19c03ad9 100644 --- a/spec/ruby/core/file/stat/rdev_major_spec.rb +++ b/spec/ruby/core/file/stat/rdev_major_spec.rb @@ -2,19 +2,12 @@ describe "File::Stat#rdev_major" do before :each do - platform_is :solaris do - @name = "/dev/zfs" - end - platform_is_not :solaris do - @name = tmp("file.txt") - touch(@name) - end + @name = tmp("file.txt") + touch(@name) end after :each do - platform_is_not :solaris do - rm_r @name - end + rm_r @name end platform_is_not :windows do diff --git a/spec/ruby/core/file/stat/rdev_minor_spec.rb b/spec/ruby/core/file/stat/rdev_minor_spec.rb index dc30c1f56cda..ace5b8a7320e 100644 --- a/spec/ruby/core/file/stat/rdev_minor_spec.rb +++ b/spec/ruby/core/file/stat/rdev_minor_spec.rb @@ -2,19 +2,12 @@ describe "File::Stat#rdev_minor" do before :each do - platform_is :solaris do - @name = "/dev/zfs" - end - platform_is_not :solaris do - @name = tmp("file.txt") - touch(@name) - end + @name = tmp("file.txt") + touch(@name) end after :each do - platform_is_not :solaris do - rm_r @name - end + rm_r @name end platform_is_not :windows do diff --git a/spec/ruby/core/file/zero_spec.rb b/spec/ruby/core/file/zero_spec.rb index 63dd85ee46a9..01c7505ef226 100644 --- a/spec/ruby/core/file/zero_spec.rb +++ b/spec/ruby/core/file/zero_spec.rb @@ -4,10 +4,4 @@ describe "File.zero?" do it_behaves_like :file_zero, :zero?, File it_behaves_like :file_zero_missing, :zero?, File - - platform_is :solaris do - it "returns false for /dev/null" do - File.zero?('/dev/null').should == true - end - end end diff --git a/spec/ruby/core/filetest/exist_spec.rb b/spec/ruby/core/filetest/exist_spec.rb index a95d3f91a18d..612ffa9fcbec 100644 --- a/spec/ruby/core/filetest/exist_spec.rb +++ b/spec/ruby/core/filetest/exist_spec.rb @@ -5,10 +5,8 @@ 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/zero_spec.rb b/spec/ruby/core/filetest/zero_spec.rb index dd6a164ec96c..92cab67f1b4f 100644 --- a/spec/ruby/core/filetest/zero_spec.rb +++ b/spec/ruby/core/filetest/zero_spec.rb @@ -4,10 +4,4 @@ describe "FileTest.zero?" do it_behaves_like :file_zero, :zero?, FileTest it_behaves_like :file_zero_missing, :zero?, FileTest - - platform_is :solaris do - it "returns false for /dev/null" do - File.zero?('/dev/null').should == true - end - end end diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb index 5f0a8f97fdb5..e116b8878b96 100644 --- a/spec/ruby/core/hash/shared/to_s.rb +++ b/spec/ruby/core/hash/shared/to_s.rb @@ -84,4 +84,10 @@ 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 ea36488a04df..3f31b9864cd4 100644 --- a/spec/ruby/core/hash/shift_spec.rb +++ b/spec/ruby/core/hash/shift_spec.rb @@ -30,45 +30,22 @@ 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/integer/ceildiv_spec.rb b/spec/ruby/core/integer/ceildiv_spec.rb index 18d07c66d0a8..c6e22a457dd2 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 2077ad451ed1..937806c72f9e 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/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb index 0781371d9399..86c2b18ae298 100644 --- a/spec/ruby/core/integer/left_shift_spec.rb +++ b/spec/ruby/core/integer/left_shift_spec.rb @@ -181,10 +181,8 @@ (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/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb index e91613d8d143..c902674e2f3e 100644 --- a/spec/ruby/core/integer/right_shift_spec.rb +++ b/spec/ruby/core/integer/right_shift_spec.rb @@ -203,10 +203,8 @@ (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/io/path_spec.rb b/spec/ruby/core/io/path_spec.rb index 8145c32f39fa..798adb216327 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/shared/each.rb b/spec/ruby/core/io/shared/each.rb index aca622834f34..0747f31b8a84 100644 --- a/spec/ruby/core/io/shared/each.rb +++ b/spec/ruby/core/io/shared/each.rb @@ -202,20 +202,10 @@ 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/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb index 8851214283ca..d56a27b3af3e 100644 --- a/spec/ruby/core/io/sysread_spec.rb +++ b/spec/ruby/core/io/sysread_spec.rb @@ -131,9 +131,7 @@ @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/kernel/match_spec.rb b/spec/ruby/core/kernel/match_spec.rb index aa25006163ff..cd6330fe91c1 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 f8dd82fad865..082e56fed7df 100644 --- a/spec/ruby/core/kernel/not_match_spec.rb +++ b/spec/ruby/core/kernel/not_match_spec.rb @@ -14,18 +14,8 @@ def !~(obj) (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 bb42c31f31e4..6d00af395d9d 100644 --- a/spec/ruby/core/kernel/open_spec.rb +++ b/spec/ruby/core/kernel/open_spec.rb @@ -106,7 +106,7 @@ 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/require_spec.rb b/spec/ruby/core/kernel/require_spec.rb index e78e7176ec5a..945f68aba9ec 100644 --- a/spec/ruby/core/kernel/require_spec.rb +++ b/spec/ruby/core/kernel/require_spec.rb @@ -17,6 +17,9 @@ end provided = %w[complex enumerator fiber rational thread ruby2_keywords] + ruby_version_is "3.5" do + provided << "set" + end it "#{provided.join(', ')} are already required" do out = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems --disable-did-you-mean') diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb index 13dc6e97f0f0..26bd189593ce 100644 --- a/spec/ruby/core/kernel/shared/sprintf.rb +++ b/spec/ruby/core/kernel/shared/sprintf.rb @@ -22,6 +22,7 @@ def obj.to_i; 10; end @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 @@ def obj.to_i; 10; end 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 @@ def obj.to_i; 10; end @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 diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index 0c16b1dbbffa..9a2efbaea074 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -2,26 +2,7 @@ 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 fcae433069cc..837eb1dafbf8 100644 --- a/spec/ruby/core/kernel/tainted_spec.rb +++ b/spec/ruby/core/kernel/tainted_spec.rb @@ -2,28 +2,7 @@ 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 db6f17e0fb06..ef3fa9a3e154 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -2,27 +2,7 @@ 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 26b2aabbe914..47e8544bd400 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -2,27 +2,7 @@ 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 5310cd8eb4ef..8787ab3fc9c0 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -2,26 +2,7 @@ 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 ea36d6c98c4c..29261be9c450 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -2,27 +2,7 @@ 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/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb index 8a23970c4bf2..5b9a75159544 100644 --- a/spec/ruby/core/main/using_spec.rb +++ b/spec/ruby/core/main/using_spec.rb @@ -142,11 +142,9 @@ def bar; 'quux'; end 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 c2a2b7799978..efc2293d9a1b 100644 --- a/spec/ruby/core/marshal/dump_spec.rb +++ b/spec/ruby/core/marshal/dump_spec.rb @@ -361,30 +361,28 @@ def _dump(level) 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 diff --git a/spec/ruby/core/marshal/fixtures/marshal_data.rb b/spec/ruby/core/marshal/fixtures/marshal_data.rb index 3ba85aa6eb39..124eb9ecd624 100644 --- a/spec/ruby/core/marshal/fixtures/marshal_data.rb +++ b/spec/ruby/core/marshal/fixtures/marshal_data.rb @@ -532,18 +532,16 @@ class ObjectWithoutFreeze < Object "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 - - MeasureExtended = Class.new(Measure) - MeasureExtended.extend(Enumerable) - - class MeasureWithOverriddenName < Measure - def self.name - "Foo" - end + module DataSpec + Measure = Data.define(:amount, :unit) + Empty = Data.define + + MeasureExtended = Class.new(Measure) + MeasureExtended.extend(Enumerable) + + 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 f73fa67e9a8d..6d79f7c3ef72 100644 --- a/spec/ruby/core/marshal/shared/load.rb +++ b/spec/ruby/core/marshal/shared/load.rb @@ -139,7 +139,7 @@ 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 @@ def io.binmode; raise "binmode"; end 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/byteoffset_spec.rb b/spec/ruby/core/matchdata/byteoffset_spec.rb index b27267fd0ece..fb8f5fb67d4e 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 = /(?foo)(?bar)/.match("foobar") + it "accepts String as a reference to a named capture" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "accepts Symbol as a reference to a named capture" do + m = /(?foo)(?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 = /(?q..)?/.match("foobarbaz") + it "returns [nil, nil] if a capturing group is optional and doesn't match" do + m = /(?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 = /(?foo)(?bar)/.match("foobar") + it "converts argument into integer if is not String nor Symbol" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "raises IndexError if there is no group with the provided name" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "raises IndexError if index is out of bounds" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "raises TypeError if can't convert argument into Integer" do + m = /(?foo)(?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 5b68f886c7cb..bf22bc33ff7a 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 = /(?foo)(?bar)/.match("foobar") + it "returns whole hash for nil as an argument" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "returns only specified keys" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "it raises error when argument is neither nil nor array" do + m = /(?foo)(?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 = /(?foo)(?bar)/.match("foobar") + it "returns {} when passed []" do + m = /(?foo)(?bar)/.match("foobar") - m.deconstruct_keys([]).should == {} - end + m.deconstruct_keys([]).should == {} + end - it "does not accept non-Symbol keys" do - m = /(?foo)(?bar)/.match("foobar") + it "does not accept non-Symbol keys" do + m = /(?foo)(?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 = /(?foo)(?bar)(?baz)/.match("foobarbaz") + it "process keys till the first non-existing one" do + m = /(?foo)(?bar)(?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 = /(?foo)(?bar)/.match("foobar") - m.deconstruct_keys([:f, :b, :c]).should == {} - end + it "returns {} when passed more keys than named captured groups" do + m = /(?foo)(?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 6af55113b68a..c55095665df9 100644 --- a/spec/ruby/core/matchdata/deconstruct_spec.rb +++ b/spec/ruby/core/matchdata/deconstruct_spec.rb @@ -2,7 +2,5 @@ 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/method/owner_spec.rb b/spec/ruby/core/method/owner_spec.rb index 05422f169782..1cdc4edfa799 100644 --- a/spec/ruby/core/method/owner_spec.rb +++ b/spec/ruby/core/method/owner_spec.rb @@ -24,9 +24,7 @@ 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 0178a61de684..f1c2523cf0c8 100644 --- a/spec/ruby/core/method/parameters_spec.rb +++ b/spec/ruby/core/method/parameters_spec.rb @@ -233,28 +233,14 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end 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 9b67a7724309..e708542b2e9a 100644 --- a/spec/ruby/core/method/private_spec.rb +++ b/spec/ruby/core/method/private_spec.rb @@ -2,27 +2,8 @@ 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 28c60c7536fa..f9e422ae3d22 100644 --- a/spec/ruby/core/method/protected_spec.rb +++ b/spec/ruby/core/method/protected_spec.rb @@ -2,27 +2,8 @@ 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 4844f4b90b31..4cb23f4cf191 100644 --- a/spec/ruby/core/method/public_spec.rb +++ b/spec/ruby/core/method/public_spec.rb @@ -2,27 +2,8 @@ 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/unbind_spec.rb b/spec/ruby/core/method/unbind_spec.rb index bdedd513cea2..0b630e4d883e 100644 --- a/spec/ruby/core/method/unbind_spec.rb +++ b/spec/ruby/core/method/unbind_spec.rb @@ -27,16 +27,8 @@ @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/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index 3cdc48f9bad1..bba911e75279 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -603,32 +603,30 @@ class LexicalScope 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 diff --git a/spec/ruby/core/module/const_added_spec.rb b/spec/ruby/core/module/const_added_spec.rb index 4b10dd596375..739be3ead844 100644 --- a/spec/ruby/core/module/const_added_spec.rb +++ b/spec/ruby/core/module/const_added_spec.rb @@ -3,201 +3,234 @@ 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 - ScratchPad.recorded.should == [:SubModule] + it "is called when a new constant is assigned on self through const_set" do + ScratchPad.record [] + + 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 + end + + ScratchPad.recorded.should == [:A, :B] + end - ScratchPad.recorded.should == [:A, :B] + 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 end - it "is called when an autoload is defined" do - ScratchPad.record [] + mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) + class SubClass + end - mod = Module.new do - def self.const_added(name) - ScratchPad << name - end + class SubClass end + RUBY - mod.autoload :Autoload, "foo" - ScratchPad.recorded.should == [:Autoload] - end + ScratchPad.recorded.should == [:SubClass] + end + + it "is called when a new class is defined under a named module (assigned to a constant)" do + ScratchPad.record [] - it "is called with a precise caller location with the line of definition" do - ScratchPad.record [] + ModuleSpecs::ConstAddedSpecs::NamedModuleB = Module.new do + def self.const_added(name) + ScratchPad << name + end - mod = Module.new do + class self::A def self.const_added(name) - location = caller_locations(1, 1)[0] - ScratchPad << location.lineno + ScratchPad << name + end + + class self::B end end + end - line = __LINE__ - mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) - TEST = 1 + ScratchPad.recorded.should == [:A, :B] + end - module SubModule - end + it "is called when an autoload is defined" do + ScratchPad.record [] - class SubClass - end - RUBY + mod = Module.new do + def self.const_added(name) + ScratchPad << name + end + end - mod.const_set(:CONST_SET, 1) + 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 == [line + 2, line + 4, line + 7, line + 11] + mod = Module.new do + def self.const_added(name) + location = caller_locations(1, 1)[0] + ScratchPad << location.lineno + end end - it "is called when the constant is already assigned a value" do - ScratchPad.record [] + line = __LINE__ + mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) + TEST = 1 - mod = Module.new do - def self.const_added(name) - ScratchPad.record const_get(name) - end + module SubModule end - mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) - TEST = 123 - RUBY + class SubClass + end + RUBY - ScratchPad.recorded.should == 123 - end + mod.const_set(:CONST_SET, 1) - it "records re-definition of existing constants" do - ScratchPad.record [] + ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11] + end - mod = Module.new do - def self.const_added(name) - ScratchPad << const_get(name) - end + it "is called when the constant is already assigned a value" do + ScratchPad.record [] + + 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 - -> { - mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1) - TEST = 123 - TEST = 456 - RUBY - }.should complain(/warning: already initialized constant .+::TEST/) + it "records re-definition of existing constants" do + ScratchPad.record [] - ScratchPad.recorded.should == [123, 456] + 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/include_spec.rb b/spec/ruby/core/module/include_spec.rb index a1bfd3a6f546..210918b2e7ac 100644 --- a/spec/ruby/core/module/include_spec.rb +++ b/spec/ruby/core/module/include_spec.rb @@ -51,32 +51,16 @@ class ModuleSpecs::SubclassSpec::AClass 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 8d006e647e21..182cdf5c5438 100644 --- a/spec/ruby/core/module/instance_method_spec.rb +++ b/spec/ruby/core/module/instance_method_spec.rb @@ -48,11 +48,6 @@ @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 b5c1f771f8d6..fd28ee0a33a7 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -153,45 +153,43 @@ module ModuleSpecs::Anonymous 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?(/#::A$/) - ScratchPad.recorded.should.one?(/#::A::B$/) end + + ScratchPad.recorded.should.one?(/#::A$/) + ScratchPad.recorded.should.one?(/#::A::B$/) 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 9508fbf1822b..71e82c513ea1 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -455,32 +455,16 @@ class ModuleSpecs::SubclassSpec::AClass 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 7a5d607c4f81..d219b9882502 100644 --- a/spec/ruby/core/module/refine_spec.rb +++ b/spec/ruby/core/module/refine_spec.rb @@ -243,32 +243,6 @@ def foo; "foo from singleton class"; end 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 5648fcbd6f14..05658a8b0e80 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 aca419f522b1..a9afad4aee38 100644 --- a/spec/ruby/core/module/ruby2_keywords_spec.rb +++ b/spec/ruby/core/module/ruby2_keywords_spec.rb @@ -76,122 +76,60 @@ def kwargs(**kw) 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 diff --git a/spec/ruby/core/module/undefined_instance_methods_spec.rb b/spec/ruby/core/module/undefined_instance_methods_spec.rb index 3be860d05378..d33ee93fc111 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 '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 c16cab0e3c38..40dd4a444e1a 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/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 7a2723487dc3..e9bc9a1c5798 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -20,29 +20,27 @@ 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 @@ -> 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 diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index 818f5b858e27..1266337f94b1 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -8,12 +8,10 @@ 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/process/_fork_spec.rb b/spec/ruby/core/process/_fork_spec.rb index 8e907f54bbb8..e1f45e2656de 100644 --- a/spec/ruby/core/process/_fork_spec.rb +++ b/spec/ruby/core/process/_fork_spec.rb @@ -5,6 +5,8 @@ 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/fixtures/clocks.rb b/spec/ruby/core/process/fixtures/clocks.rb index f043f6ac1ff4..5757e280be0a 100644 --- a/spec/ruby/core/process/fixtures/clocks.rb +++ b/spec/ruby/core/process/fixtures/clocks.rb @@ -2,7 +2,7 @@ module ProcessSpecs def self.clock_constants clocks = [] - platform_is_not :windows, :solaris do + platform_is_not :windows do clocks += Process.constants.select { |c| c.to_s.start_with?('CLOCK_') } # These require CAP_WAKE_ALARM and are not documented in diff --git a/spec/ruby/core/process/setrlimit_spec.rb b/spec/ruby/core/process/setrlimit_spec.rb index b92f98fd406b..ba8d1e04ca01 100644 --- a/spec/ruby/core/process/setrlimit_spec.rb +++ b/spec/ruby/core/process/setrlimit_spec.rb @@ -73,20 +73,18 @@ Process.setrlimit(:STACK, *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil end - platform_is_not :solaris, :aix do + platform_is_not :aix do it "coerces :MEMLOCK into RLIMIT_MEMLOCK" do Process.setrlimit(:MEMLOCK, *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil end end - platform_is_not :solaris do - it "coerces :NPROC into RLIMIT_NPROC" do - Process.setrlimit(:NPROC, *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil - end + it "coerces :NPROC into RLIMIT_NPROC" do + Process.setrlimit(:NPROC, *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil + end - it "coerces :RSS into RLIMIT_RSS" do - Process.setrlimit(:RSS, *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil - end + it "coerces :RSS into RLIMIT_RSS" do + Process.setrlimit(:RSS, *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil end platform_is :netbsd, :freebsd do @@ -155,20 +153,18 @@ Process.setrlimit("STACK", *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil end - platform_is_not :solaris, :aix do + platform_is_not :aix do it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do Process.setrlimit("MEMLOCK", *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil end end - platform_is_not :solaris do - it "coerces 'NPROC' into RLIMIT_NPROC" do - Process.setrlimit("NPROC", *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil - end + it "coerces 'NPROC' into RLIMIT_NPROC" do + Process.setrlimit("NPROC", *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil + end - it "coerces 'RSS' into RLIMIT_RSS" do - Process.setrlimit("RSS", *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil - end + it "coerces 'RSS' into RLIMIT_RSS" do + Process.setrlimit("RSS", *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil end platform_is :netbsd, :freebsd do diff --git a/spec/ruby/core/queue/deq_spec.rb b/spec/ruby/core/queue/deq_spec.rb index f84d4220ea46..a2784e6a63f5 100644 --- a/spec/ruby/core/queue/deq_spec.rb +++ b/spec/ruby/core/queue/deq_spec.rb @@ -7,7 +7,5 @@ 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 d34474083452..3dff7db24270 100644 --- a/spec/ruby/core/queue/pop_spec.rb +++ b/spec/ruby/core/queue/pop_spec.rb @@ -7,7 +7,5 @@ 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 64165e0b61ef..c105da74b2ec 100644 --- a/spec/ruby/core/queue/shift_spec.rb +++ b/spec/ruby/core/queue/shift_spec.rb @@ -7,7 +7,5 @@ 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/default_spec.rb b/spec/ruby/core/random/default_spec.rb index 01d7430df871..9e4845986d93 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/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb index 65878aaabe72..c9b253f0a585 100644 --- a/spec/ruby/core/range/case_compare_spec.rb +++ b/spec/ruby/core/range/case_compare_spec.rb @@ -11,7 +11,7 @@ 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/last_spec.rb b/spec/ruby/core/range/last_spec.rb index 6698686dd569..82b3e2ff5340 100644 --- a/spec/ruby/core/range/last_spec.rb +++ b/spec/ruby/core/range/last_spec.rb @@ -8,10 +8,8 @@ (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/size_spec.rb b/spec/ruby/core/range/size_spec.rb index a1fe3ce17de3..1a3ddd197e9d 100644 --- a/spec/ruby/core/range/size_spec.rb +++ b/spec/ruby/core/range/size_spec.rb @@ -22,16 +22,7 @@ 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/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb index f9fdbcb33ef0..65fbf2ed1ca8 100644 --- a/spec/ruby/core/rational/exponent_spec.rb +++ b/spec/ruby/core/rational/exponent_spec.rb @@ -228,11 +228,9 @@ -> { Rational(0, 1) ** Rational(-3, 2) }.should raise_error(ZeroDivisionError, "divided by 0") end - platform_is_not :solaris do # See https://github.com/ruby/spec/issues/134 - it "returns Infinity for Rational(0, 1) passed a negative Float" do - [-1.0, -3.0, -3.14].each do |exponent| - (Rational(0, 1) ** exponent).infinite?.should == 1 - end + it "returns Infinity for Rational(0, 1) passed a negative Float" do + [-1.0, -3.0, -3.14].each do |exponent| + (Rational(0, 1) ** exponent).infinite?.should == 1 end end end diff --git a/spec/ruby/core/refinement/append_features_spec.rb b/spec/ruby/core/refinement/append_features_spec.rb index fb84f245bd56..f7e5f32bc1d3 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 6c2a0af4f3e6..4da8b359cccc 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 d20ab47e3303..57451bd9bc9f 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 9fdea199a219..fbc431bbd233 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 5d6676668998..64cf7cd17f7f 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 acc6e2cb2bfc..60a58380ccf0 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 '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/linear_time_spec.rb b/spec/ruby/core/regexp/linear_time_spec.rb index 2f5795fefdd4..c3b3500549b2 100644 --- a/spec/ruby/core/regexp/linear_time_spec.rb +++ b/spec/ruby/core/regexp/linear_time_spec.rb @@ -1,29 +1,27 @@ 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 "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 "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 "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 "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 "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/) end end diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb index 3ca50d5a478f..44b339100e4a 100644 --- a/spec/ruby/core/regexp/shared/new.rb +++ b/spec/ruby/core/regexp/shared/new.rb @@ -123,140 +123,67 @@ def obj.to_str() [] end (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 @@ -623,11 +550,5 @@ def obj.to_int() ScratchPad.record(:called) end 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/timeout_spec.rb b/spec/ruby/core/regexp/timeout_spec.rb index 6fce261814ef..c64103c82cb1 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 similarity index 97% rename from spec/ruby/library/set/add_spec.rb rename to spec/ruby/core/set/add_spec.rb index 68356cc111cc..73662acfd174 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 diff --git a/spec/ruby/library/set/append_spec.rb b/spec/ruby/core/set/append_spec.rb similarity index 89% rename from spec/ruby/library/set/append_spec.rb rename to spec/ruby/core/set/append_spec.rb index 8b3498b779db..82d34d9130ce 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 similarity index 94% rename from spec/ruby/library/set/case_compare_spec.rb rename to spec/ruby/core/set/case_compare_spec.rb index 70d392a27dc5..3781b1b96349 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 similarity index 90% rename from spec/ruby/library/set/case_equality_spec.rb rename to spec/ruby/core/set/case_equality_spec.rb index 10cbfd380a4d..19c1fb6b9c51 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 similarity index 98% rename from spec/ruby/library/set/classify_spec.rb rename to spec/ruby/core/set/classify_spec.rb index ec600c91d64d..d86ea2722d8c 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 similarity index 95% rename from spec/ruby/library/set/clear_spec.rb rename to spec/ruby/core/set/clear_spec.rb index 2b1c9c5b5ac0..ebeac211d3f7 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 similarity index 91% rename from spec/ruby/library/set/collect_spec.rb rename to spec/ruby/core/set/collect_spec.rb index f8813a933131..d186f1a0d97d 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 similarity index 88% rename from spec/ruby/library/set/compare_by_identity_spec.rb rename to spec/ruby/core/set/compare_by_identity_spec.rb index 602d1e758e9f..00bb8e4e6a1c 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 @@ def o.hash; 123; end 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 "3.5" 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: #") + end + end + + ruby_version_is ""..."3.5" 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 similarity index 98% rename from spec/ruby/library/set/comparison_spec.rb rename to spec/ruby/core/set/comparison_spec.rb index ddcfbae0af36..62059b70b3b4 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 similarity index 95% rename from spec/ruby/library/set/constructor_spec.rb rename to spec/ruby/core/set/constructor_spec.rb index bb8486151450..365081ad39b0 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 similarity index 98% rename from spec/ruby/library/set/delete_if_spec.rb rename to spec/ruby/core/set/delete_if_spec.rb index 33caeeaab7e5..beda73a5e5f5 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 similarity index 98% rename from spec/ruby/library/set/delete_spec.rb rename to spec/ruby/core/set/delete_spec.rb index b12524384ab2..a2543ecbee7b 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 similarity index 91% rename from spec/ruby/library/set/difference_spec.rb rename to spec/ruby/core/set/difference_spec.rb index 422f2ed3c740..149f946592b4 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 similarity index 98% rename from spec/ruby/library/set/disjoint_spec.rb rename to spec/ruby/core/set/disjoint_spec.rb index ea3b1414553e..89a3c4b1577e 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 similarity index 82% rename from spec/ruby/library/set/divide_spec.rb rename to spec/ruby/core/set/divide_spec.rb index 998a1b292c0f..cbe0042f16e6 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 @@ 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 "3.5" 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 ""..."3.5" 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 similarity index 97% rename from spec/ruby/library/set/each_spec.rb rename to spec/ruby/core/set/each_spec.rb index 44e185a4da90..3d9cdc2d468e 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 similarity index 93% rename from spec/ruby/library/set/empty_spec.rb rename to spec/ruby/core/set/empty_spec.rb index 1789a664c7c4..4b55658e20fa 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 similarity index 95% rename from spec/ruby/library/set/enumerable/to_set_spec.rb rename to spec/ruby/core/set/enumerable/to_set_spec.rb index b2d850515b66..f139e1c025e5 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 similarity index 96% rename from spec/ruby/library/set/eql_spec.rb rename to spec/ruby/core/set/eql_spec.rb index dd8e633775a8..4ad5c3aa5a14 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 similarity index 77% rename from spec/ruby/library/set/equal_value_spec.rb rename to spec/ruby/core/set/equal_value_spec.rb index f5b5f790c054..e3514928c816 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 @@ 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 ""..."3.5" 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 similarity index 97% rename from spec/ruby/library/set/exclusion_spec.rb rename to spec/ruby/core/set/exclusion_spec.rb index 5bc4b5a2bf12..bbc29afa95e4 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 similarity index 100% rename from spec/ruby/library/set/filter_spec.rb rename to 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 similarity index 97% rename from spec/ruby/library/set/fixtures/set_like.rb rename to spec/ruby/core/set/fixtures/set_like.rb index 46f61a451eef..86dec2ed52e7 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 000000000000..d7c2b3065794 --- /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 ""..."3.5" 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 similarity index 76% rename from spec/ruby/library/set/flatten_spec.rb rename to spec/ruby/core/set/flatten_spec.rb index 51b58d64392b..870eccc2f10c 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 @@ -> { 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 ""..."3.5" 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 @@ 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 ""..."3.5" 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 similarity index 64% rename from spec/ruby/library/set/hash_spec.rb rename to spec/ruby/core/set/hash_spec.rb index c5bab73931fe..4b4696e34ccb 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 @@ 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 ""..."3.5" 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 similarity index 91% rename from spec/ruby/library/set/include_spec.rb rename to spec/ruby/core/set/include_spec.rb index 68532d9a04ac..dd33bbc3bd53 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 similarity index 96% rename from spec/ruby/library/set/initialize_clone_spec.rb rename to spec/ruby/core/set/initialize_clone_spec.rb index bda42cd6e8bf..13abb7ee4e8d 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 similarity index 99% rename from spec/ruby/library/set/initialize_spec.rb rename to spec/ruby/core/set/initialize_spec.rb index 76ebc0a20aa2..ad9e1bd8c9d4 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 similarity index 91% rename from spec/ruby/library/set/inspect_spec.rb rename to spec/ruby/core/set/inspect_spec.rb index 4060c63b954e..0dcce83eb63d 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 similarity index 98% rename from spec/ruby/library/set/intersect_spec.rb rename to spec/ruby/core/set/intersect_spec.rb index e60f06db9465..0736dea5fd05 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 similarity index 94% rename from spec/ruby/library/set/intersection_spec.rb rename to spec/ruby/core/set/intersection_spec.rb index 792c2d8f0793..136b88677586 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 similarity index 73% rename from spec/ruby/library/set/join_spec.rb rename to spec/ruby/core/set/join_spec.rb index 3f511a84e411..cdb593597d86 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 @@ 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 ""..."3.5" 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 similarity index 98% rename from spec/ruby/library/set/keep_if_spec.rb rename to spec/ruby/core/set/keep_if_spec.rb index 7edc80769f0c..d6abdd6adc60 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 similarity index 90% rename from spec/ruby/library/set/length_spec.rb rename to spec/ruby/core/set/length_spec.rb index fef63d25a7f4..6bb697b4caab 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 similarity index 91% rename from spec/ruby/library/set/map_spec.rb rename to spec/ruby/core/set/map_spec.rb index e60e98b179f3..996191b0a8bc 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 similarity index 91% rename from spec/ruby/library/set/member_spec.rb rename to spec/ruby/core/set/member_spec.rb index 5b56a38ab9dc..5c82e8f826b5 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 similarity index 98% rename from spec/ruby/library/set/merge_spec.rb rename to spec/ruby/core/set/merge_spec.rb index 3ae0da827c82..2ee6a4b70943 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 diff --git a/spec/ruby/library/set/minus_spec.rb b/spec/ruby/core/set/minus_spec.rb similarity index 90% rename from spec/ruby/library/set/minus_spec.rb rename to spec/ruby/core/set/minus_spec.rb index 3fe0b6a2cc02..72f98f985ee3 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 similarity index 90% rename from spec/ruby/library/set/plus_spec.rb rename to spec/ruby/core/set/plus_spec.rb index 3e70d3269d4b..7e44ff0b7e19 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 similarity index 95% rename from spec/ruby/library/set/pretty_print_cycle_spec.rb rename to spec/ruby/core/set/pretty_print_cycle_spec.rb index 4f440353e50b..c3b383fe8083 100644 --- a/spec/ruby/library/set/pretty_print_cycle_spec.rb +++ b/spec/ruby/core/set/pretty_print_cycle_spec.rb @@ -1,5 +1,4 @@ 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 diff --git a/spec/ruby/library/set/proper_subset_spec.rb b/spec/ruby/core/set/proper_subset_spec.rb similarity index 83% rename from spec/ruby/library/set/proper_subset_spec.rb rename to spec/ruby/core/set/proper_subset_spec.rb index 6b51dedc9fb8..a84c4197c23d 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 @@ 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 ""..."3.5" 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 similarity index 82% rename from spec/ruby/library/set/proper_superset_spec.rb rename to spec/ruby/core/set/proper_superset_spec.rb index a386c8c09749..653411f6b234 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 @@ -> { 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 ""..."3.5" 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 similarity index 98% rename from spec/ruby/library/set/reject_spec.rb rename to spec/ruby/core/set/reject_spec.rb index 9131f960ad43..91d029341582 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 similarity index 96% rename from spec/ruby/library/set/replace_spec.rb rename to spec/ruby/core/set/replace_spec.rb index 7511066c9cdd..60b33eb0c0b6 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 diff --git a/spec/ruby/library/set/select_spec.rb b/spec/ruby/core/set/select_spec.rb similarity index 100% rename from spec/ruby/library/set/select_spec.rb rename to 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 000000000000..f1436e602298 --- /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]) + RUBY + output.chomp.should == "#" + end +end diff --git a/spec/ruby/library/set/shared/add.rb b/spec/ruby/core/set/shared/add.rb similarity index 100% rename from spec/ruby/library/set/shared/add.rb rename to 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 similarity index 100% rename from spec/ruby/library/set/shared/collect.rb rename to 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 similarity index 100% rename from spec/ruby/library/set/shared/difference.rb rename to 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 similarity index 100% rename from spec/ruby/library/set/shared/include.rb rename to spec/ruby/core/set/shared/include.rb diff --git a/spec/ruby/library/set/shared/inspect.rb b/spec/ruby/core/set/shared/inspect.rb similarity index 100% rename from spec/ruby/library/set/shared/inspect.rb rename to spec/ruby/core/set/shared/inspect.rb diff --git a/spec/ruby/library/set/shared/intersection.rb b/spec/ruby/core/set/shared/intersection.rb similarity index 100% rename from spec/ruby/library/set/shared/intersection.rb rename to 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 similarity index 100% rename from spec/ruby/library/set/shared/length.rb rename to 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 similarity index 98% rename from spec/ruby/library/set/shared/select.rb rename to spec/ruby/core/set/shared/select.rb index 2108d398b4e6..467b236ed39e 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 similarity index 100% rename from spec/ruby/library/set/shared/union.rb rename to 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 similarity index 90% rename from spec/ruby/library/set/size_spec.rb rename to spec/ruby/core/set/size_spec.rb index 3c8cb3851748..4ae22c5f0a09 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/library/set/sortedset/sortedset_spec.rb b/spec/ruby/core/set/sortedset/sortedset_spec.rb similarity index 96% rename from spec/ruby/library/set/sortedset/sortedset_spec.rb rename to spec/ruby/core/set/sortedset/sortedset_spec.rb index 67993dee2956..375aada81668 100644 --- a/spec/ruby/library/set/sortedset/sortedset_spec.rb +++ b/spec/ruby/core/set/sortedset/sortedset_spec.rb @@ -1,5 +1,4 @@ require_relative '../../../spec_helper' -require 'set' describe "SortedSet" do it "raises error including message that it has been extracted from the set stdlib" do diff --git a/spec/ruby/library/set/subset_spec.rb b/spec/ruby/core/set/subset_spec.rb similarity index 82% rename from spec/ruby/library/set/subset_spec.rb rename to spec/ruby/core/set/subset_spec.rb index 85666d633f71..cde61d7cd774 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 @@ 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 ""..."3.5" 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 similarity index 96% rename from spec/ruby/library/set/subtract_spec.rb rename to spec/ruby/core/set/subtract_spec.rb index 56713de8b3f3..ae4bc73d414c 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 similarity index 82% rename from spec/ruby/library/set/superset_spec.rb rename to spec/ruby/core/set/superset_spec.rb index bd9d2f3eee68..9d7bab964a23 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 @@ -> { 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 ""..."3.5" 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 similarity index 92% rename from spec/ruby/library/set/to_a_spec.rb rename to spec/ruby/core/set/to_a_spec.rb index 689e44f38a3e..1e9800167ad3 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 similarity index 94% rename from spec/ruby/library/set/to_s_spec.rb rename to spec/ruby/core/set/to_s_spec.rb index 3c26ae9346a7..55b8bfd9b20c 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 similarity index 93% rename from spec/ruby/library/set/union_spec.rb rename to spec/ruby/core/set/union_spec.rb index 20fe0ddca39c..3e77022d4b79 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 6fffe2f27264..c52baa3802a3 100644 --- a/spec/ruby/core/sizedqueue/append_spec.rb +++ b/spec/ruby/core/sizedqueue/append_spec.rb @@ -12,7 +12,5 @@ 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 985d654bb3ea..2aeb52f8a64b 100644 --- a/spec/ruby/core/sizedqueue/deq_spec.rb +++ b/spec/ruby/core/sizedqueue/deq_spec.rb @@ -7,7 +7,5 @@ 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 619373e46bef..b955909475b4 100644 --- a/spec/ruby/core/sizedqueue/enq_spec.rb +++ b/spec/ruby/core/sizedqueue/enq_spec.rb @@ -12,7 +12,5 @@ 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 5e7cfea8fb20..6338ddbaa095 100644 --- a/spec/ruby/core/sizedqueue/pop_spec.rb +++ b/spec/ruby/core/sizedqueue/pop_spec.rb @@ -7,7 +7,5 @@ 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 ce61e89b53f0..9eaa6beca089 100644 --- a/spec/ruby/core/sizedqueue/push_spec.rb +++ b/spec/ruby/core/sizedqueue/push_spec.rb @@ -12,7 +12,5 @@ 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 3220801f3a99..52974c1d9953 100644 --- a/spec/ruby/core/sizedqueue/shift_spec.rb +++ b/spec/ruby/core/sizedqueue/shift_spec.rb @@ -7,7 +7,5 @@ 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 47c7be10298b..d420f3f6830c 100644 --- a/spec/ruby/core/string/byteindex_spec.rb +++ b/spec/ruby/core/string/byteindex_spec.rb @@ -4,301 +4,295 @@ 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 - " 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 34ecbfbd2120..983222e35de6 100644 --- a/spec/ruby/core/string/byterindex_spec.rb +++ b/spec/ruby/core/string/byterindex_spec.rb @@ -4,356 +4,350 @@ 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/bytesplice_spec.rb b/spec/ruby/core/string/bytesplice_spec.rb index 5cb3b2c15815..2c770e340aad 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 @@ 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/dedup_spec.rb b/spec/ruby/core/string/dedup_spec.rb index 57d2be2cfda4..2b31d8070827 100644 --- a/spec/ruby/core/string/dedup_spec.rb +++ b/spec/ruby/core/string/dedup_spec.rb @@ -2,7 +2,5 @@ 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 33c21418124c..46e0aa0f3616 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -391,16 +391,8 @@ def universal.to_f() 0.0 end ("%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 6d46eb590ef2..55773f523806 100644 --- a/spec/ruby/core/string/rstrip_spec.rb +++ b/spec/ruby/core/string/rstrip_spec.rb @@ -68,27 +68,13 @@ -> { "".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/to_c_spec.rb b/spec/ruby/core/string/to_c_spec.rb index 4864a98e398c..1813890e7220 100644 --- a/spec/ruby/core/string/to_c_spec.rb +++ b/spec/ruby/core/string/to_c_spec.rb @@ -13,9 +13,7 @@ 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 @@ }.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 19edb500decf..ab1ba43fb3c6 100644 --- a/spec/ruby/core/string/to_f_spec.rb +++ b/spec/ruby/core/string/to_f_spec.rb @@ -120,17 +120,9 @@ "\3771.2".b.to_f.should == 0 end - ruby_version_is ""..."3.3" do - it "does not raise any exception if String is in not ASCII-compatible encoding" do - '1.2'.encode("UTF-16").to_f.should == 0.0 - end - end - - ruby_version_is "3.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 + 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 diff --git a/spec/ruby/core/string/unpack_spec.rb b/spec/ruby/core/string/unpack_spec.rb index 083484ebe958..a0abf8fa9947 100644 --- a/spec/ruby/core/string/unpack_spec.rb +++ b/spec/ruby/core/string/unpack_spec.rb @@ -26,7 +26,7 @@ "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/struct/constants_spec.rb b/spec/ruby/core/struct/constants_spec.rb index fa61a4b91208..7e8af1a21192 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 cd05aee05679..602403d1834b 100644 --- a/spec/ruby/core/struct/deconstruct_keys_spec.rb +++ b/spec/ruby/core/struct/deconstruct_keys_spec.rb @@ -80,7 +80,7 @@ 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 "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/initialize_spec.rb b/spec/ruby/core/struct/initialize_spec.rb index 1861bcafb0d0..06055594d5b1 100644 --- a/spec/ruby/core/struct/initialize_spec.rb +++ b/spec/ruby/core/struct/initialize_spec.rb @@ -41,21 +41,11 @@ 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 73e88a81c181..6d014cb94d5e 100644 --- a/spec/ruby/core/struct/new_spec.rb +++ b/spec/ruby/core/struct/new_spec.rb @@ -73,20 +73,8 @@ def obj.to_str() "Foo" end -> { 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,17 +154,15 @@ def platform -> { 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 + obj.should == obj2 + obj.args.should == 42 + obj2.args.should == 42 end end diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 54eccdba11eb..def5d6d3444b 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -27,31 +27,29 @@ 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 29c271789b52..aa7423675b5a 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/time/deconstruct_keys_spec.rb b/spec/ruby/core/time/deconstruct_keys_spec.rb index ee17e7dbd403..b5cfdaa93f88 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 8449778465e8..9182d9965297 100644 --- a/spec/ruby/core/time/minus_spec.rb +++ b/spec/ruby/core/time/minus_spec.rb @@ -109,7 +109,7 @@ 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 0fd48640d499..f288da84ddc0 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -467,259 +467,253 @@ def zone.local_to_utc(t) 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 + 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:56 +09:00") - }.should raise_error(ArgumentError, /missing sec part: 00:56 |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.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 of String into Integer") 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 - 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:56:17. +0900") - }.should raise_error(ArgumentError, /subsecond expected after dot: 00:56:17. |can't parse:/) - end + -> { + Time.new("2020-12-25 00 +09:00") + }.should raise_error(ArgumentError, /missing min part: 00 |can't parse:/) + end - 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:/) + 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 - -> { - 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 day is missing" do + -> { + Time.new("2020-12") + }.should raise_error(ArgumentError, /no time information|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 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-12-215 00:56:17 +0900") - }.should raise_error(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 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-25 000:56:17 +0900") - }.should raise_error(ArgumentError, /two digits hour is expected: 000:56:17 |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 0:56:17 +0900") - }.should raise_error(ArgumentError, /two digits hour is expected: 0:56:17 \+0|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 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-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: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 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:56:137 +0900") - }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+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:7 +0900") - }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+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. +0900") - }.should raise_error(ArgumentError, /fraction min is not supported: 00:56\.|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. +0900") - }.should raise_error(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/) - end + -> { + 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:/) - 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:7 +0900") + }.should raise_error(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z|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:56. +0900") + }.should raise_error(ArgumentError, /fraction min is not supported: 00:56\.|can't parse:/) - -> { - 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. +0900") + }.should raise_error(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/) + end - -> { - Time.new("2020-12-25 00:61:17 +09:00") - }.should raise_error(ArgumentError, /(min|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:56:61 +09:00") - }.should raise_error(ArgumentError, /(sec|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:17 +23:59:60") - }.should raise_error(ArgumentError, /utc_offset|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 +24:00") - }.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: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") - - -> { 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") + 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 +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 +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: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: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') - 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: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: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 + 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') - 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") + -> { 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 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 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 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 + 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 - 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 - 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/) + end + + 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 end end diff --git a/spec/ruby/core/time/now_spec.rb b/spec/ruby/core/time/now_spec.rb index f19e01546132..e3fe6edad667 100644 --- a/spec/ruby/core/time/now_spec.rb +++ b/spec/ruby/core/time/now_spec.rb @@ -84,99 +84,97 @@ 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/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb index 6cc8bb38973b..93a6b281e358 100644 --- a/spec/ruby/core/tracepoint/enable_spec.rb +++ b/spec/ruby/core/tracepoint/enable_spec.rb @@ -57,50 +57,25 @@ 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 036c6b7f8c71..4d4fc66504c7 100644 --- a/spec/ruby/core/unboundmethod/equal_value_spec.rb +++ b/spec/ruby/core/unboundmethod/equal_value_spec.rb @@ -76,38 +76,19 @@ (@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 false 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 e8a734dac415..b099c56de171 100644 --- a/spec/ruby/core/unboundmethod/owner_spec.rb +++ b/spec/ruby/core/unboundmethod/owner_spec.rb @@ -25,9 +25,7 @@ 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 9a890db6fd3c..5a563939d112 100644 --- a/spec/ruby/core/unboundmethod/private_spec.rb +++ b/spec/ruby/core/unboundmethod/private_spec.rb @@ -2,27 +2,8 @@ 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 b79e2da63b5b..70622d658dda 100644 --- a/spec/ruby/core/unboundmethod/protected_spec.rb +++ b/spec/ruby/core/unboundmethod/protected_spec.rb @@ -2,27 +2,8 @@ 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 c2a2795a84dd..ae75e2601c67 100644 --- a/spec/ruby/core/unboundmethod/public_spec.rb +++ b/spec/ruby/core/unboundmethod/public_spec.rb @@ -2,27 +2,8 @@ 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 b92bb0b207dc..6b2c9c3e7939 100644 --- a/spec/ruby/core/unboundmethod/shared/to_s.rb +++ b/spec/ruby/core/unboundmethod/shared/to_s.rb @@ -20,22 +20,11 @@ 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? "# { - 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 @@ def no_kw(arg1, **nil, &); inner(&) end 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 @@ -1090,3 +1069,10 @@ def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, ** end end end + +describe "if `it` is defined outside of a block" do + it "treats `it` as a captured variable" do + it = 5 + proc { it }.call(0).should == 5 + end +end diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb index 35913b9e30b2..063c52c4226d 100644 --- a/spec/ruby/language/constants_spec.rb +++ b/spec/ruby/language/constants_spec.rb @@ -161,34 +161,16 @@ class << self 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/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb index 0fcd3e57bff9..c711a536c22d 100644 --- a/spec/ruby/language/delegation_spec.rb +++ b/spec/ruby/language/delegation_spec.rb @@ -87,51 +87,47 @@ def delegate(...) 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 index 455acc9001d7..0b07f16d3027 100644 --- a/spec/ruby/language/fixtures/class_with_class_variable.rb +++ b/spec/ruby/language/fixtures/class_with_class_variable.rb @@ -6,4 +6,4 @@ def foo "#@@a" end end -end \ No newline at end of file +end diff --git a/spec/ruby/language/keyword_arguments_spec.rb b/spec/ruby/language/keyword_arguments_spec.rb index 3f8ddfa40dd1..4f6370d419e0 100644 --- a/spec/ruby/language/keyword_arguments_spec.rb +++ b/spec/ruby/language/keyword_arguments_spec.rb @@ -336,61 +336,23 @@ def m(a:, b:) 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/module_spec.rb b/spec/ruby/language/module_spec.rb index 0bfd148868b8..4db00bd7fb9e 100644 --- a/spec/ruby/language/module_spec.rb +++ b/spec/ruby/language/module_spec.rb @@ -30,20 +30,11 @@ module ModuleSpecs; Reopened = true; end 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 + module IncludedModuleSpecs; Reopened = true; end + ModuleSpecs::IncludedInObject::IncludedModuleSpecs.should_not == Object::IncludedModuleSpecs + ensure + IncludedModuleSpecs.send(:remove_const, :Reopened) end it "raises a TypeError if the constant is a Class" do diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index e6bf3b6b11d0..91019cfe5609 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -675,12 +675,39 @@ def foo $VERBOSE = @verbose end - it "can be assigned a String" do - str = "abc" - $/ = str - $/.should equal(str) + ruby_version_is ""..."3.5" do + it "can be assigned a String" do + str = +"abc" + $/ = str + $/.should equal(str) + end end + ruby_version_is "3.5" do + it "makes a new frozen String from the assigned String" do + string_subclass = Class.new(String) + str = string_subclass.new("abc") + str.instance_variable_set(:@ivar, 1) + $/ = str + $/.should.frozen? + $/.should be_an_instance_of(String) + $/.should_not.instance_variable_defined?(:@ivar) + $/.should == str + end + + it "makes a new frozen String if it's not frozen" do + str = +"abc" + $/ = str + $/.should.frozen? + $/.should == str + end + + it "assigns the given String if it's frozen and has no instance variables" do + str = "abc".freeze + $/ = str + $/.should equal(str) + end + end it "can be assigned nil" do $/ = nil $/.should be_nil @@ -724,10 +751,38 @@ def foo $VERBOSE = @verbose end - it "can be assigned a String" do - str = "abc" - $-0 = str - $-0.should equal(str) + ruby_version_is ""..."3.5" do + it "can be assigned a String" do + str = +"abc" + $-0 = str + $-0.should equal(str) + end + end + + ruby_version_is "3.5" do + it "makes a new frozen String from the assigned String" do + string_subclass = Class.new(String) + str = string_subclass.new("abc") + str.instance_variable_set(:@ivar, 1) + $-0 = str + $-0.should.frozen? + $-0.should be_an_instance_of(String) + $-0.should_not.instance_variable_defined?(:@ivar) + $-0.should == str + end + + it "makes a new frozen String if it's not frozen" do + str = +"abc" + $-0 = str + $-0.should.frozen? + $-0.should == str + end + + it "assigns the given String if it's frozen and has no instance variables" do + str = "abc".freeze + $-0 = str + $-0.should equal(str) + end end it "can be assigned nil" do @@ -1443,9 +1498,9 @@ def obj.foo2; yield; 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 8e9a0b960be4..d27a54a0282a 100644 --- a/spec/ruby/language/regexp/character_classes_spec.rb +++ b/spec/ruby/language/regexp/character_classes_spec.rb @@ -113,7 +113,7 @@ end it "doesn't matches Unicode marks with [[:alnum:]]" do - "\u{36F}".match(/[[:alnum:]]/).should be_nil + "\u{3099}".match(/[[:alnum:]]/).should be_nil end it "doesn't match Unicode control characters with [[:alnum:]]" do @@ -133,7 +133,7 @@ end it "doesn't matches Unicode marks with [[:alpha:]]" do - "\u{36F}".match(/[[:alpha:]]/).should be_nil + "\u{3099}".match(/[[:alpha:]]/).should be_nil end it "doesn't match Unicode control characters with [[:alpha:]]" do diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb index bd993acb0fee..eb080eea559a 100644 --- a/spec/ruby/language/variables_spec.rb +++ b/spec/ruby/language/variables_spec.rb @@ -363,11 +363,22 @@ module VariableSpecs a.should == [] end - it "calls #to_a to convert nil to an empty Array" do - nil.should_receive(:to_a).and_return([]) + ruby_version_is "3.5" do + it "converts nil to empty array without calling a method" do + nil.should_not_receive(:to_a) - (*a = *nil).should == [] - a.should == [] + (*a = *nil).should == [] + a.should == [] + end + end + + ruby_version_is ""..."3.5" do + it "calls #to_a to convert nil to an empty Array" do + nil.should_receive(:to_a).and_return([]) + + (*a = *nil).should == [] + a.should == [] + end end it "does not call #to_a on an Array" do diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index fba52df65d3b..6a4d220417c1 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -228,15 +228,7 @@ -> { 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/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb index 962609ebaffc..622549039fe3 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 ""..."3.5" 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 c8f26d01cdf7..df52a6f41e24 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 ""..."3.5" 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 4b6e104b10cd..ac99d5e4fda6 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 ""..."3.5" 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 326a43ade318..712628180b35 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 ""..."3.5" 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 d484c7bad952..ecc78d77dcc2 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 ""..."3.5" 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 8a2f05aa50e4..010e87a6b83e 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 ""..."3.5" 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 694bc2eeedef..b52689725073 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 ""..."3.5" 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 da15e6ed2a94..34326f672b6f 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 ""..."3.5" 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 1d5da3a3acd3..e7c91b55b965 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 ""..."3.5" 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 148926c4531d..528433d2527c 100644 --- a/spec/ruby/library/cgi/escapeElement_spec.rb +++ b/spec/ruby/library/cgi/escapeElement_spec.rb @@ -1,5 +1,9 @@ require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +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 421aac5d4ab3..6e70e87ed748 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 f05795a2f569..02921ab8bf43 100644 --- a/spec/ruby/library/cgi/escapeURIComponent_spec.rb +++ b/spec/ruby/library/cgi/escapeURIComponent_spec.rb @@ -1,57 +1,59 @@ require_relative '../../spec_helper' -require 'cgi' - -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 +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +end - it "does not escape with unreserved characters" do - string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" - CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" - end +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 - it "supports String with invalid encoding" do - string = "\xC0\<\<".dup.force_encoding("UTF-8") - CGI.escapeURIComponent(string).should == "%C0%3C%3C" - end + it "does not escape with unreserved characters" do + string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + end - it "processes String bytes one by one, not characters" do - CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2 - end + it "supports String with invalid encoding" do + string = "\xC0\<\<".dup.force_encoding("UTF-8") + CGI.escapeURIComponent(string).should == "%C0%3C%3C" + end - it "raises a TypeError with nil" do - -> { - CGI.escapeURIComponent(nil) - }.should raise_error(TypeError, 'no implicit conversion of nil into String') - end + it "processes String bytes one by one, not characters" do + CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2 + end - it "encodes empty string" do - CGI.escapeURIComponent("").should == "" - end + it "raises a TypeError with nil" do + -> { + CGI.escapeURIComponent(nil) + }.should raise_error(TypeError, 'no implicit conversion of nil into String') + end - it "encodes single whitespace" do - CGI.escapeURIComponent(" ").should == "%20" - end + it "encodes empty string" do + CGI.escapeURIComponent("").should == "" + end - it "encodes double whitespace" do - CGI.escapeURIComponent(" ").should == "%20%20" - end + it "encodes single whitespace" do + CGI.escapeURIComponent(" ").should == "%20" + end - it "preserves encoding" do - string = "whatever".encode("ASCII-8BIT") - CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT - end + it "encodes double whitespace" do + CGI.escapeURIComponent(" ").should == "%20%20" + end - it "uses implicit type conversion to String" do - object = Object.new - def object.to_str - "a b" - end + it "preserves encoding" do + string = "whatever".encode("ASCII-8BIT") + CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT + end - CGI.escapeURIComponent(object).should == "a%20b" + 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 c599a73cf067..55eb0b66c284 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 05b4c2d14c99..16a0552bacb5 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 ""..."3.5" 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 == %() - CGISpecs.cgi_new("html3").a { "link text" }.should == %(link text) + 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 == %() - CGISpecs.cgi_new("html4").a { "link text" }.should == %(link text) - end - it "returns the doctype declaration for the Transitional version of HTML4" do - CGISpecs.cgi_new("html4Tr").a.should == %() - CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(link text) + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + CGISpecs.cgi_new("html3").a.should == %() + CGISpecs.cgi_new("html3").a { "link text" }.should == %(link text) + end + + it "returns the doctype declaration for HTML4" do + CGISpecs.cgi_new("html4").a.should == %() + CGISpecs.cgi_new("html4").a { "link text" }.should == %(link text) + end + it "returns the doctype declaration for the Transitional version of HTML4" do + CGISpecs.cgi_new("html4Tr").a.should == %() + CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(link text) + 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 877ac321cd33..a4c4a6161482 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 ""..."3.5" 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 a7b833b1c53d..f8d4ca310e56 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 ""..."3.5" 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 dfca1218845b..45909a2db7ae 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 ""..."3.5" 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 == "
" + 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 == "
" - end - it "returns the doctype declaration for the Transitional version of HTML4" do - CGISpecs.cgi_new("html4Tr").br.should == "
" + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + CGISpecs.cgi_new("html3").br.should == "
" + end + + it "returns the doctype declaration for HTML4" do + CGISpecs.cgi_new("html4").br.should == "
" + end + it "returns the doctype declaration for the Transitional version of HTML4" do + CGISpecs.cgi_new("html4Tr").br.should == "
" + 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 16615028b811..74f0a098f43e 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 ""..."3.5" 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 64f852cc52f7..1acfe62fdadc 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 ""..."3.5" 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 af76fa1da955..ba410f31de00 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 ""..."3.5" 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 9a28a8883b77..49501ac8f752 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 = '' - CGISpecs.cgi_new("html3").doctype.should == expect - end +ruby_version_is ""..."3.5" do + require 'cgi' + require_relative 'fixtures/common' - it "returns the doctype declaration for HTML4" do - expect = '' - 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 = '' + CGISpecs.cgi_new("html3").doctype.should == expect + end - it "returns the doctype declaration for the Frameset version of HTML4" do - expect = '' - CGISpecs.cgi_new("html4Fr").doctype.should == expect - end + it "returns the doctype declaration for HTML4" do + expect = '' + CGISpecs.cgi_new("html4").doctype.should == expect + end + + it "returns the doctype declaration for the Frameset version of HTML4" do + expect = '' + CGISpecs.cgi_new("html4Fr").doctype.should == expect + end - it "returns the doctype declaration for the Transitional version of HTML4" do - expect = '' - CGISpecs.cgi_new("html4Tr").doctype.should == expect + it "returns the doctype declaration for the Transitional version of HTML4" do + expect = '' + 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 2a0632fd587b..b8ef0b2045de 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 ""..."3.5" 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 8c0ac97735fc..510ce27b777c 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 ""..."3.5" 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 2ddd4e1ef019..0dc30e94f78b 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 ""..."3.5" 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 == "" - @html.frameset { "link text" }.should == "link text" + it "initializes the HTML Generation methods for the Frameset version of HTML4" do + @html.frameset.should == "" + @html.frameset { "link text" }.should == "link text" + end end end diff --git a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb index baeb4465936b..a37b5f537da1 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 ""..."3.5" 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 == "" - @html.frameset { "link text" }.should == "link text" + it "initializes the HTML Generation methods for the Frameset version of HTML4" do + @html.frameset.should == "" + @html.frameset { "link text" }.should == "link text" + end end end diff --git a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb index 52ebd8c261c8..5771058fa318 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 ""..."3.5" 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 5d89c8208625..0e4052dcc4a2 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("") - end +ruby_version_is ""..."3.5" 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 = '' - @html.html.should == expected + describe "CGI::HtmlExtension#html" do + before :each do + @html = CGISpecs.cgi_new + @html.stub!(:doctype).and_return("") end - it "includes the passed block when passed a block" do - expected = 'test' - @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 = '' + @html.html.should == expected + end - describe "when passed 'PRETTY'" do - it "returns pretty output when the passed String is 'PRETTY" do - expected = "\n\n" - @html.html("PRETTY").should == expected + it "includes the passed block when passed a block" do + expected = 'test' + @html.html { "test" }.should == expected + end end - it "includes the passed block when passed a block" do - expected = "\n\n test\n\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 = "\n\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 = '' - @html.html("DOCTYPE" => '', "BLA" => "TEST").should == expected + it "includes the passed block when passed a block" do + expected = "\n\n test\n\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("DOCTYPE" => nil).should == "" - end - end + describe "when passed a Hash" do + it "returns an 'html'-element using the passed Hash for attributes" do + expected = '' + @html.html("DOCTYPE" => '', "BLA" => "TEST").should == expected + end - describe "when each HTML generation" do - it "returns the doctype declaration for HTML3" do - expect = '' - CGISpecs.cgi_new("html3").html.should == expect + "" - CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "html body" + it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do + @html.html("DOCTYPE" => false).should == "" + @html.html("DOCTYPE" => nil).should == "" + end end - it "returns the doctype declaration for HTML4" do - expect = '' - CGISpecs.cgi_new("html4").html.should == expect + "" - CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "html body" - end + describe "when each HTML generation" do + it "returns the doctype declaration for HTML3" do + expect = '' + CGISpecs.cgi_new("html3").html.should == expect + "" + CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "html body" + end + + it "returns the doctype declaration for HTML4" do + expect = '' + CGISpecs.cgi_new("html4").html.should == expect + "" + CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "html body" + end - it "returns the doctype declaration for the Transitional version of HTML4" do - expect = '' - CGISpecs.cgi_new("html4Tr").html.should == expect + "" - CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "html body" + it "returns the doctype declaration for the Transitional version of HTML4" do + expect = '' + CGISpecs.cgi_new("html4Tr").html.should == expect + "" + CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "html body" + 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 d14bec9ca34e..cd7f1ae4f775 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 ""..."3.5" 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 994ae7fedfc7..193d3dca2624 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 ""..."3.5" 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 0bf2042a33d2..e5c16f2475b6 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 ""..."3.5" 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 683bc428baa5..a462bea01553 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 ""..."3.5" 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 3462be09b04f..0ec85e96dfd7 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 ""..."3.5" 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 3dc3c879b594..865c16d23228 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 ""..."3.5" 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 1bfd43449d70..7381e7183b7f 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 ""..."3.5" 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 86fa25fc8afb..d3a5c801fa1b 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 ""..."3.5" 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 4eb0c86c1a5f..aab52d74097b 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 ""..."3.5" 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 063891b95999..3401b1035697 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 ""..."3.5" 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 44b5a5e69f39..4f63dbce599f 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 ""..."3.5" 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 db84a973d29e..a3881796fd30 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 ""..."3.5" 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 == '' + describe "when passed Hash" do + it "uses the passed Hash as attributes" do + @html.textarea("ID" => "test").should == '' - 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 4094bebed358..173055718b36 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 ""..."3.5" 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 61bc971d4916..d46b5a356405 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 ""..."3.5" 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 bc09f5bcbb59..c79d0002841a 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 ""..."3.5" 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 04539b122657..d35d0d33650e 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 ""..."3.5" 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 a7b7505c1534..1fed3bbd2ecf 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("").should == <<-EOS +ruby_version_is ""..."3.5" do + require 'cgi' + + describe "CGI.pretty when passed html" do + it "indents the passed html String with two spaces" do + CGI.pretty("").should == <<-EOS 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("", "\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("", "\t").should == <<-EOS \t \t EOS + end end end diff --git a/spec/ruby/library/cgi/print_spec.rb b/spec/ruby/library/cgi/print_spec.rb index 18ab8d673b12..5057c280a0c2 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 ""..."3.5" 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 0487569b9c08..9bfc833a3bba 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 ""..."3.5" 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 35ff3c2b30e6..f0d7f2058a14 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 ""..."3.5" 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 4a15d58914e9..e3dfcd03241a 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 ""..."3.5" 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 af5209ffbe93..9370a885a4be 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 ""..."3.5" 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 25318269b12f..c85843603772 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 ""..."3.5" 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 0471307c227f..d42421126c53 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 ""..."3.5" 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 de823f7119e3..2e3dca6f587b 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 ""..."3.5" 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 49b8389c8741..ce1be28571c8 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 ""..."3.5" 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 4befd61ab792..029ad5991a1b 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 ""..."3.5" 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 6ac5b4640730..df1c372ab7f4 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 ""..."3.5" 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 04a992cfc7cb..8d278f531862 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 ""..."3.5" 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 3ead5bd8bf6e..d519b80e3293 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 ""..."3.5" 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 525b45b50729..5892ecaf7758 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 ""..."3.5" 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 e820e0afc373..2eaf1330c053 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 ""..."3.5" 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 12365ea2847b..18520c4aafb6 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 ""..."3.5" 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 d0f1e4cee2e4..c8c5870eba84 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 ""..."3.5" 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 14d77180faba..0c35404103c8 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 ""..."3.5" 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 ced4cb05a184..72c8073a5a48 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 ""..."3.5" 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 @@ -----------------------------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 b6fe0360420b..c159c6cfe23a 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 ""..."3.5" 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 f4449e3c8ab2..e8b447f22722 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 ""..."3.5" 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 9785df85f122..9054f1cfd363 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 ""..."3.5" 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 417a749341d6..4b17f6c01bee 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 ""..."3.5" 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 02d5c9122133..c6a9c5b9736d 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 ""..."3.5" 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 a6b454a7eb4f..ef3cb9c8fb1b 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 ""..."3.5" 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 3d7072e346fe..07ef00e8c5ce 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 ""..."3.5" 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 ede7b9ff8790..f1ebb8ad8292 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 ""..."3.5" 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 6cd5dc96f8ee..737253eac9c8 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 ""..."3.5" 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 0259402b233b..e2cc696ae20e 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 ""..."3.5" 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 cf77e0031b93..c4db9e4ffe84 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 ""..."3.5" 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 5b51d6b8ee6b..d507b7d7be89 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 ""..."3.5" 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 1a93bb656199..ceee41079738 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 ""..."3.5" 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 eabdd6998bec..b540280261a7 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 ""..."3.5" 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 341b7b6feadf..49a7847eff08 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 ""..."3.5" 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 b12aaf8c5cbd..ee5d754ad36e 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 ""..."3.5" 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 0e688a99bf94..c4f8df78cffb 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 ""..."3.5" 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 f9dcf3c5b8e7..35d3b8add1e4 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 ""..."3.5" 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 df349cdf2e87..d4fcceb3799a 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 ""..."3.5" 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 ec5ef187ddb8..070a77912312 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 ""..."3.5" 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 6904eeabaa91..2641b40e945b 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 ""..."3.5" 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 ae4d50b076e3..345339328241 100644 --- a/spec/ruby/library/cgi/unescapeElement_spec.rb +++ b/spec/ruby/library/cgi/unescapeElement_spec.rb @@ -1,5 +1,9 @@ require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +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 84b30c6aa68d..e43dcc83e540 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 '& < > "' to '& < > \"'" do diff --git a/spec/ruby/library/cgi/unescape_spec.rb b/spec/ruby/library/cgi/unescape_spec.rb index c593e24b4ac1..52e1cb024363 100644 --- a/spec/ruby/library/cgi/unescape_spec.rb +++ b/spec/ruby/library/cgi/unescape_spec.rb @@ -1,6 +1,10 @@ # -*- encoding: utf-8 -*- require_relative '../../spec_helper' -require 'cgi' +begin + require 'cgi/escape' +rescue LoadError + require 'cgi' +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 bc999a5369ea..0101eb6a643b 100644 --- a/spec/ruby/library/coverage/result_spec.rb +++ b/spec/ruby/library/coverage/result_spec.rb @@ -34,39 +34,37 @@ } 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 @@ 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 757837a46224..c921b8540183 100644 --- a/spec/ruby/library/coverage/start_spec.rb +++ b/spec/ruby/library/coverage/start_spec.rb @@ -27,63 +27,61 @@ }.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 78b3784ee0a6..9226548c1f55 100644 --- a/spec/ruby/library/coverage/supported_spec.rb +++ b/spec/ruby/library/coverage/supported_spec.rb @@ -2,31 +2,29 @@ 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 92579e35c7c8..b9dd6b88162d 100644 --- a/spec/ruby/library/date/deconstruct_keys_spec.rb +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -2,43 +2,41 @@ 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 77ceaa51c4b9..154c024a2397 100644 --- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb +++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb @@ -2,45 +2,43 @@ 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 1125dbe851c8..558972523815 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 @@ 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 09e6192e7faa..58bb363653ba 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -19,17 +19,15 @@ 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/io-wait/wait_readable_spec.rb b/spec/ruby/library/io-wait/wait_readable_spec.rb index df25fdb93120..d7473f029f21 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 6ab41e9f08ca..6a3890a401a7 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 @@ 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 @@ -> { @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 @@ @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 8639dd717ba7..2017817caacc 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/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb index 612430e067d6..0f1e2aa8b93a 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 '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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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/kdf/scrypt_spec.rb b/spec/ruby/library/openssl/kdf/scrypt_spec.rb index 5dc9f2f281e6..e01b8bca8a3f 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/rbconfig/unicode_emoji_version_spec.rb b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb index 27220f498340..2c6d1f4e93ad 100644 --- a/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb @@ -2,13 +2,7 @@ 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 @@ -16,8 +10,8 @@ # Caution: ruby_version_is means is_or_later ruby_version_is "3.5" do - it "is 15.1" do - RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "15.1" + it "is 16.0" do + RbConfig::CONFIG['UNICODE_EMOJI_VERSION'].should == "16.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 bcb67a507625..961bb989a503 100644 --- a/spec/ruby/library/rbconfig/unicode_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb @@ -2,13 +2,7 @@ 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 @@ -16,8 +10,8 @@ # Caution: ruby_version_is means is_or_later ruby_version_is "3.5" do - it "is 15.1.0" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "15.1.0" + it "is 16.0.0" do + RbConfig::CONFIG['UNICODE_VERSION'].should == "16.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 f2c99a948135..000000000000 --- 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 2a4edc6dfc63..000000000000 --- 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 == "#" - end - end -end diff --git a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb index 67fad73815e5..e05fe9967ad5 100644 --- a/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb @@ -73,19 +73,15 @@ end end - platform_is_not :'solaris2.10' do # i386-solaris - it 'sets a custom socket protocol of the Addrinfo instances' do - array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, nil, Socket::IPPROTO_UDP) + it 'sets a custom socket protocol of the Addrinfo instances' do + array = Addrinfo.getaddrinfo('127.0.0.1', 80, nil, nil, Socket::IPPROTO_UDP) - array[0].protocol.should == Socket::IPPROTO_UDP - end + array[0].protocol.should == Socket::IPPROTO_UDP end - platform_is_not :solaris do - it 'sets the canonical name when AI_CANONNAME is given as a flag' do - array = Addrinfo.getaddrinfo('localhost', 80, nil, nil, nil, Socket::AI_CANONNAME) + it 'sets the canonical name when AI_CANONNAME is given as a flag' do + array = Addrinfo.getaddrinfo('localhost', 80, nil, nil, nil, Socket::AI_CANONNAME) - array[0].canonname.should be_an_instance_of(String) - end + array[0].canonname.should be_an_instance_of(String) end end diff --git a/spec/ruby/library/socket/addrinfo/initialize_spec.rb b/spec/ruby/library/socket/addrinfo/initialize_spec.rb index d8885c5d622d..b7477efc7959 100644 --- a/spec/ruby/library/socket/addrinfo/initialize_spec.rb +++ b/spec/ruby/library/socket/addrinfo/initialize_spec.rb @@ -362,7 +362,7 @@ end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) @@ -390,7 +390,7 @@ end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) @@ -495,7 +495,7 @@ end end - platform_is_not :windows, :aix, :solaris do + platform_is_not :windows, :aix do (Socket.constants.grep(/^IPPROTO/) - valid).each do |type| it "raises SocketError when using #{type}" do value = Socket.const_get(type) diff --git a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb index c4220a6f3e69..2d69a33b53b7 100644 --- a/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb +++ b/spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb @@ -32,10 +32,8 @@ @array[3].should == 'SOCK_STREAM' end - platform_is_not :'solaris2.10' do # i386-solaris - it 'includes the protocol as the 5th value' do - @array[4].should == 'IPPROTO_TCP' - end + it 'includes the protocol as the 5th value' do + @array[4].should == 'IPPROTO_TCP' end it 'includes the canonical name as the 6th value' do diff --git a/spec/ruby/library/socket/addrinfo/udp_spec.rb b/spec/ruby/library/socket/addrinfo/udp_spec.rb index b05cbf9b0bc6..ac02e76ef58f 100644 --- a/spec/ruby/library/socket/addrinfo/udp_spec.rb +++ b/spec/ruby/library/socket/addrinfo/udp_spec.rb @@ -27,10 +27,8 @@ Addrinfo.udp(ip_address, 80).socktype.should == Socket::SOCK_DGRAM end - platform_is_not :solaris do - it 'sets the socket protocol' do - Addrinfo.udp(ip_address, 80).protocol.should == Socket::IPPROTO_UDP - end + it 'sets the socket protocol' do + Addrinfo.udp(ip_address, 80).protocol.should == Socket::IPPROTO_UDP end end end diff --git a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb index 344d1485c5c3..eca45599d777 100644 --- a/spec/ruby/library/socket/ancillarydata/initialize_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/initialize_spec.rb @@ -106,7 +106,7 @@ Socket::AncillaryData.new(:INET, :SOCKET, :RIGHTS, '').type.should == Socket::SCM_RIGHTS end - platform_is_not :"solaris2.10", :aix do + platform_is_not :aix do it 'sets the type to SCM_TIMESTAMP when using :TIMESTAMP as the type argument' do Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '').type.should == Socket::SCM_TIMESTAMP end diff --git a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb index 65ffcb01af37..95052fd91c2d 100644 --- a/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb +++ b/spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb @@ -50,7 +50,7 @@ -> { data.unix_rights }.should raise_error(TypeError) end - platform_is_not :"solaris2.10", :aix do + platform_is_not :aix do it 'raises TypeError when the type is not SCM_RIGHTS' do data = Socket::AncillaryData.new(:INET, :SOCKET, :TIMESTAMP, '') diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb index e20c571922ea..40033a5f5d10 100644 --- a/spec/ruby/library/socket/basicsocket/recv_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb @@ -32,28 +32,26 @@ ScratchPad.recorded.should == 'hello' end - platform_is_not :solaris do - it "accepts flags to specify unusual receiving behaviour" do - t = Thread.new do - client = @server.accept + it "accepts flags to specify unusual receiving behaviour" do + t = Thread.new do + client = @server.accept - # in-band data (TCP), doesn't receive the flag. - ScratchPad.record client.recv(10) + # in-band data (TCP), doesn't receive the flag. + ScratchPad.record client.recv(10) - # this recv is important (TODO: explain) - client.recv(10) - client.close - end - Thread.pass while t.status and t.status != "sleep" - t.status.should_not be_nil - - socket = TCPSocket.new('127.0.0.1', @port) - socket.send('helloU', Socket::MSG_OOB) - socket.shutdown(1) - t.join - socket.close - ScratchPad.recorded.should == 'hello' + # this recv is important (TODO: explain) + client.recv(10) + client.close end + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.send('helloU', Socket::MSG_OOB) + socket.shutdown(1) + t.join + socket.close + ScratchPad.recorded.should == 'hello' end it "gets lines delimited with a custom separator" do diff --git a/spec/ruby/library/socket/basicsocket/send_spec.rb b/spec/ruby/library/socket/basicsocket/send_spec.rb index 36da125279b3..25ba3f5655da 100644 --- a/spec/ruby/library/socket/basicsocket/send_spec.rb +++ b/spec/ruby/library/socket/basicsocket/send_spec.rb @@ -38,7 +38,7 @@ data.should == 'hello' end - platform_is_not :solaris, :windows do + platform_is_not :windows do it "accepts flags to specify unusual sending behaviour" do data = nil peek_data = nil diff --git a/spec/ruby/library/socket/constants/constants_spec.rb b/spec/ruby/library/socket/constants/constants_spec.rb index 637bc6740af7..b9a9d427253f 100644 --- a/spec/ruby/library/socket/constants/constants_spec.rb +++ b/spec/ruby/library/socket/constants/constants_spec.rb @@ -68,7 +68,7 @@ end end - platform_is_not :solaris, :windows, :aix, :android do + platform_is_not :windows, :aix, :android do it "defines multicast options" do consts = ["IP_MAX_MEMBERSHIPS"] consts.each do |c| diff --git a/spec/ruby/library/socket/shared/pack_sockaddr.rb b/spec/ruby/library/socket/shared/pack_sockaddr.rb index 26fdf682b153..f309aa02c7ad 100644 --- a/spec/ruby/library/socket/shared/pack_sockaddr.rb +++ b/spec/ruby/library/socket/shared/pack_sockaddr.rb @@ -22,11 +22,9 @@ Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0'] end - platform_is_not :solaris do - it 'resolves the service name to a port' do - sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1') - Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] - end + it 'resolves the service name to a port' do + sockaddr_in = Socket.public_send(@method, 'http', '127.0.0.1') + Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '127.0.0.1'] end describe 'using an IPv4 address' do @@ -38,25 +36,12 @@ end end - platform_is_not :solaris do - describe 'using an IPv6 address' do - it 'returns a String of 28 bytes' do - str = Socket.public_send(@method, 80, '::1') + describe 'using an IPv6 address' do + it 'returns a String of 28 bytes' do + str = Socket.public_send(@method, 80, '::1') - str.should be_an_instance_of(String) - str.bytesize.should == 28 - end - end - end - - platform_is :solaris do - describe 'using an IPv6 address' do - it 'returns a String of 32 bytes' do - str = Socket.public_send(@method, 80, '::1') - - str.should be_an_instance_of(String) - str.bytesize.should == 32 - end + str.should be_an_instance_of(String) + str.bytesize.should == 28 end end end diff --git a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb index 3cf667fc4a13..359b8719fb06 100644 --- a/spec/ruby/library/socket/socket/connect_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/connect_nonblock_spec.rb @@ -16,42 +16,40 @@ @thread.join if @thread end - platform_is_not :solaris do - it "connects the socket to the remote side" do - port = nil - accept = false - @thread = Thread.new do - server = TCPServer.new(@hostname, 0) - port = server.addr[1] - Thread.pass until accept - conn = server.accept - conn << "hello!" - conn.close - server.close - end - - Thread.pass until port + it "connects the socket to the remote side" do + port = nil + accept = false + @thread = Thread.new do + server = TCPServer.new(@hostname, 0) + port = server.addr[1] + Thread.pass until accept + conn = server.accept + conn << "hello!" + conn.close + server.close + end - addr = Socket.sockaddr_in(port, @hostname) - begin - @socket.connect_nonblock(addr) - rescue Errno::EINPROGRESS - end + Thread.pass until port - accept = true - IO.select nil, [@socket] + addr = Socket.sockaddr_in(port, @hostname) + begin + @socket.connect_nonblock(addr) + rescue Errno::EINPROGRESS + end - begin - @socket.connect_nonblock(addr) - rescue Errno::EISCONN - # Not all OS's use this errno, so we trap and ignore it - end + accept = true + IO.select nil, [@socket] - @socket.read(6).should == "hello!" + begin + @socket.connect_nonblock(addr) + rescue Errno::EISCONN + # Not all OS's use this errno, so we trap and ignore it end + + @socket.read(6).should == "hello!" end - platform_is_not :freebsd, :solaris, :aix do + platform_is_not :freebsd, :aix do it "raises Errno::EINPROGRESS when the connect would block" do -> do @socket.connect_nonblock(@addr) @@ -135,7 +133,7 @@ end end - platform_is_not :freebsd, :solaris do + platform_is_not :freebsd do it 'raises IO:EINPROGRESSWaitWritable when the connection would block' do @server.bind(@sockaddr) diff --git a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb index e0eff3cef435..9f049597d0d2 100644 --- a/spec/ruby/library/socket/socket/getaddrinfo_spec.rb +++ b/spec/ruby/library/socket/socket/getaddrinfo_spec.rb @@ -11,7 +11,7 @@ BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup end - platform_is_not :solaris, :windows do + platform_is_not :windows do it "gets the address information" do expected = [] # The check for AP_INET6's class is needed because ipaddr.rb adds diff --git a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb index a4c83555208f..5d936046f5cb 100644 --- a/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb +++ b/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb @@ -18,11 +18,8 @@ @array = suppress_warning { Socket.gethostbyaddr(@addr) } end - # RubyCI Solaris 11x defines 127.0.0.1 as unstable11x - platform_is_not :"solaris2.11" do - it 'includes the hostname as the first value' do - @array[0].should == SocketSpecs.hostname_reverse_lookup - end + it 'includes the hostname as the first value' do + @array[0].should == SocketSpecs.hostname_reverse_lookup end it 'includes the aliases as the 2nd value' do diff --git a/spec/ruby/library/socket/socket/getifaddrs_spec.rb b/spec/ruby/library/socket/socket/getifaddrs_spec.rb index 7df542abe6e6..839854ea2711 100644 --- a/spec/ruby/library/socket/socket/getifaddrs_spec.rb +++ b/spec/ruby/library/socket/socket/getifaddrs_spec.rb @@ -1,6 +1,6 @@ require_relative '../spec_helper' -platform_is_not :aix, :"solaris2.10" do +platform_is_not :aix do describe 'Socket.getifaddrs' do before do @ifaddrs = Socket.getifaddrs diff --git a/spec/ruby/library/socket/tcpsocket/shared/new.rb b/spec/ruby/library/socket/tcpsocket/shared/new.rb index 90f8d7e6a28b..5280eb790080 100644 --- a/spec/ruby/library/socket/tcpsocket/shared/new.rb +++ b/spec/ruby/library/socket/tcpsocket/shared/new.rb @@ -14,26 +14,13 @@ } 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 diff --git a/spec/ruby/library/stringio/fileno_spec.rb b/spec/ruby/library/stringio/fileno_spec.rb index eea03a5af3c4..5a9f440a0fc6 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/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb index e0dd3f9b8f4a..33f1c0e35919 100644 --- a/spec/ruby/library/stringio/shared/each.rb +++ b/spec/ruby/library/stringio/shared/each.rb @@ -36,22 +36,11 @@ 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 diff --git a/spec/ruby/library/stringscanner/named_captures_spec.rb b/spec/ruby/library/stringscanner/named_captures_spec.rb index f35051b8cb47..a68d66c216a8 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?(/(?\w+) (?\w+) (?\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?(/(?\w+) (?\w+) (?\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?(/(?\w+) (?\w+) (?\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?(/(?\w+) (?\w+) (?\s+)?/) + @s.named_captures.should == {"wday" => "Fri", "month" => "Dec", "day" => nil} end end diff --git a/spec/ruby/library/stringscanner/shared/pos.rb b/spec/ruby/library/stringscanner/shared/pos.rb index 6d540881f2cd..eea7ead6b5e2 100644 --- a/spec/ruby/library/stringscanner/shared/pos.rb +++ b/spec/ruby/library/stringscanner/shared/pos.rb @@ -22,6 +22,13 @@ @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/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb index 2b9524c53d84..fc9db47dd819 100644 --- a/spec/ruby/library/syslog/constants_spec.rb +++ b/spec/ruby/library/syslog/constants_spec.rb @@ -4,7 +4,7 @@ require 'syslog' describe "Syslog::Constants" do - platform_is_not :windows, :solaris, :aix do + platform_is_not :windows, :aix do before :all do @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH diff --git a/spec/ruby/library/syslog/log_spec.rb b/spec/ruby/library/syslog/log_spec.rb index 8589fb1f7332..0c855b8257ea 100644 --- a/spec/ruby/library/syslog/log_spec.rb +++ b/spec/ruby/library/syslog/log_spec.rb @@ -4,7 +4,7 @@ require 'syslog' describe "Syslog.log" do - platform_is_not :windows, :darwin, :solaris, :aix, :android do + platform_is_not :windows, :darwin, :aix, :android do before :each do Syslog.opened?.should be_false diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb index 12e4ea8366a2..9f9302b21440 100644 --- a/spec/ruby/library/syslog/shared/log.rb +++ b/spec/ruby/library/syslog/shared/log.rb @@ -1,5 +1,5 @@ describe :syslog_log, shared: true do - platform_is_not :windows, :darwin, :solaris, :aix, :android do + platform_is_not :windows, :darwin, :aix, :android do before :each do Syslog.opened?.should be_false end diff --git a/spec/ruby/library/uri/generic/host_spec.rb b/spec/ruby/library/uri/generic/host_spec.rb index 210124ef6612..4a5a162512da 100644 --- a/spec/ruby/library/uri/generic/host_spec.rb +++ b/spec/ruby/library/uri/generic/host_spec.rb @@ -2,11 +2,9 @@ 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 8cebd374a141..c436ee3c038d 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 '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/optional/capi/binding_spec.rb b/spec/ruby/optional/capi/binding_spec.rb index 216570545783..5d0ef2efb87d 100644 --- a/spec/ruby/optional/capi/binding_spec.rb +++ b/spec/ruby/optional/capi/binding_spec.rb @@ -8,21 +8,9 @@ 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/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb index 21a887f04765..7abb5d4ed958 100644 --- a/spec/ruby/optional/capi/class_spec.rb +++ b/spec/ruby/optional/capi/class_spec.rb @@ -385,17 +385,6 @@ CApiClassSpecs.const_get(cls.name) }.should raise_error(NameError, /wrong constant name/) end - - ruby_version_is "3.5" do - it "calls .inherited before .const_added" do - ScratchPad.record([]) - @s.rb_define_class_id_under(CApiClassSpecs::Callbacks, :Subclass, CApiClassSpecs::Callbacks) - ScratchPad.recorded.should == [ - [:inherited, "CApiClassSpecs::Callbacks::Subclass", :location], - [:const_added, :Subclass, :location], - ] - end - end end describe "rb_define_class_id_under" do diff --git a/spec/ruby/optional/capi/digest_spec.rb b/spec/ruby/optional/capi/digest_spec.rb index 58476e4c8168..c75373390635 100644 --- a/spec/ruby/optional/capi/digest_spec.rb +++ b/spec/ruby/optional/capi/digest_spec.rb @@ -96,4 +96,4 @@ def verify_context(current_body) @context[1, byte_count].should == current_body end end -end \ No newline at end of file +end diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index db693f041ba0..0c3c98a5c0a8 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -735,14 +735,12 @@ 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/ext/class_spec.c b/spec/ruby/optional/capi/ext/class_spec.c index c13f02ecf23c..8ac0e7a93f5a 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 9aee8db37fb6..05819ea47667 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 index 683ec96b6744..b341fdb7032e 100644 --- a/spec/ruby/optional/capi/ext/digest_spec.c +++ b/spec/ruby/optional/capi/ext/digest_spec.c @@ -103,7 +103,7 @@ static rb_digest_metadata_t * get_metadata_ptr(VALUE obj) { // 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 = RTYPEDDATA_DATA(obj); + algo = (rb_digest_metadata_t *) RTYPEDDATA_DATA(obj); #else # undef RUBY_UNTYPED_DATA_WARNING # define RUBY_UNTYPED_DATA_WARNING 0 diff --git a/spec/ruby/optional/capi/ext/fiber_spec.c b/spec/ruby/optional/capi/ext/fiber_spec.c index f06a54494ea0..db54f7ad8c6c 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 0e5b3d1c0aa6..653917f2c4f6 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 cc440e6b0706..f3ede15729bd 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 abd8d20ff4f2..ff71a7e58922 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -351,7 +351,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 +358,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); @@ -436,10 +434,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 aa60662e1e3b..eab0eb75342a 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; @@ -414,11 +387,6 @@ 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 +411,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); diff --git a/spec/ruby/optional/capi/ext/rbasic_spec.c b/spec/ruby/optional/capi/ext/rbasic_spec.c index 26be2fed6d37..5a95b92804dc 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 90073ab82ea6..8aaec36f4658 100644 --- a/spec/ruby/optional/capi/ext/rubyspec.h +++ b/spec/ruby/optional/capi/ext/rubyspec.h @@ -35,6 +35,10 @@ (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 +#endif + #if RUBY_VERSION_SINCE(3, 4) #define RUBY_VERSION_IS_3_4 #endif @@ -43,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/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index a140c86347ca..b49bb3f26708 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); } @@ -635,10 +625,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/thread_spec.c b/spec/ruby/optional/capi/ext/thread_spec.c index 3511c2fbcf8e..6ee111b7b7ea 100644 --- a/spec/ruby/optional/capi/ext/thread_spec.c +++ b/spec/ruby/optional/capi/ext/thread_spec.c @@ -118,7 +118,6 @@ static VALUE thread_spec_rb_thread_wait_for(VALUE self, VALUE s, VALUE ms) { return Qnil; } - VALUE thread_spec_call_proc(void *arg_ptr) { VALUE arg_array = (VALUE)arg_ptr; VALUE arg = rb_ary_pop(arg_array); @@ -167,6 +166,12 @@ static VALUE thread_spec_ruby_native_thread_p_new_thread(VALUE self) { #endif } +#ifdef RUBY_VERSION_IS_3_5 +static VALUE thread_spec_ruby_thread_has_gvl_p(VALUE self) { + return ruby_thread_has_gvl_p() ? Qtrue : Qfalse; +} +#endif + void Init_thread_spec(void) { VALUE cls = rb_define_class("CApiThreadSpecs", rb_cObject); rb_define_method(cls, "rb_thread_alone", thread_spec_rb_thread_alone, 0); @@ -180,6 +185,9 @@ 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 + rb_define_method(cls, "ruby_thread_has_gvl_p", thread_spec_ruby_thread_has_gvl_p, 0); +#endif } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/fixtures/class.rb b/spec/ruby/optional/capi/fixtures/class.rb index 2560fef17da9..b463e3b4c322 100644 --- a/spec/ruby/optional/capi/fixtures/class.rb +++ b/spec/ruby/optional/capi/fixtures/class.rb @@ -101,14 +101,4 @@ class B module M end end - - class Callbacks - def self.inherited(child) - ScratchPad << [:inherited, child.name, Object.const_source_location(child.name) ? :location : :unknown_location] - end - - def self.const_added(const_name) - ScratchPad << [:const_added, const_name, const_source_location(const_name) ? :location : :unknown_location] - end - end end diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb index 08e03fcb26e4..3a27de3bfa29 100644 --- a/spec/ruby/optional/capi/hash_spec.rb +++ b/spec/ruby/optional/capi/hash_spec.rb @@ -50,19 +50,17 @@ 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/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index ba301ec17229..d915a72c22af 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -242,10 +242,8 @@ class CApiKernelSpecs::Exc < StandardError @s.rb_yield(1) { break 73 }.should == 73 end - platform_is_not :"solaris2.10" do # NOTE: i386-pc-solaris2.10 - it "rb_yield through a callback to a block that breaks with a value returns the value" do - @s.rb_yield_indirected(1) { break 73 }.should == 73 - end + it "rb_yield through a callback to a block that breaks with a value returns the value" do + @s.rb_yield_indirected(1) { break 73 }.should == 73 end it "rb_yield to block passed to enumerator" do diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 7bc7bd992aaa..27faecbb49f5 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -888,7 +888,7 @@ def reach 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/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb index 9d80a93e1d6d..e3485d4b7b53 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/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 18eaeda8e070..715f76eaea24 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -1040,11 +1040,9 @@ def inspect @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 "truncates a string to a supplied precision if that is shorter than the string" do diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb index af641f0564e9..cd9ae8ff1923 100644 --- a/spec/ruby/optional/capi/thread_spec.rb +++ b/spec/ruby/optional/capi/thread_spec.rb @@ -184,4 +184,12 @@ def call_capi_rb_thread_wakeup thr.value.should be_true end end + + ruby_version_is "3.5" 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 + end + end + end end diff --git a/spec/ruby/security/cve_2020_10663_spec.rb b/spec/ruby/security/cve_2020_10663_spec.rb index 03f004efeb56..80e860348b10 100644 --- a/spec/ruby/security/cve_2020_10663_spec.rb +++ b/spec/ruby/security/cve_2020_10663_spec.rb @@ -1,46 +1,49 @@ require_relative '../spec_helper' -require 'json' -module JSONSpecs - class MyClass - def initialize(foo) - @foo = foo - end +ruby_version_is ""..."3.5" do + require 'json' - def self.json_create(hash) - new(*hash['args']) - end + module JSONSpecs + class MyClass + def initialize(foo) + @foo = foo + end + + def self.json_create(hash) + new(*hash['args']) + end - def to_json(*args) - { 'json_class' => self.class.name, 'args' => [ @foo ] }.to_json(*args) + def to_json(*args) + { 'json_class' => self.class.name, 'args' => [ @foo ] }.to_json(*args) + end end end -end -guard -> { - JSON.const_defined?(:Pure) or - version_is(JSON::VERSION, '2.3.0') -} do - describe "CVE-2020-10663 is resisted by" do - it "only creating custom objects if passed create_additions: true or using JSON.load" do - obj = JSONSpecs::MyClass.new("bar") - JSONSpecs::MyClass.should.json_creatable? - json = JSON.dump(obj) + guard -> { + JSON.const_defined?(:Pure) or + version_is(JSON::VERSION, '2.3.0') + } do + describe "CVE-2020-10663 is resisted by" do + it "only creating custom objects if passed create_additions: true or using JSON.load" do + obj = JSONSpecs::MyClass.new("bar") + JSONSpecs::MyClass.should.json_creatable? + json = JSON.dump(obj) - JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass - JSON(json, create_additions: true).class.should == JSONSpecs::MyClass - if version_is(JSON::VERSION, '2.8.0') - warning = /\Wcreate_additions:\s*true\W\s+is\s+deprecated/ - else - warning = '' - end - -> { - JSON.load(json).class.should == JSONSpecs::MyClass - }.should output_to_fd(warning, STDERR) + JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass + JSON(json, create_additions: true).class.should == JSONSpecs::MyClass + if version_is(JSON::VERSION, '2.8.0') + warning = /\Wcreate_additions:\s*true\W\s+is\s+deprecated/ + else + warning = '' + end + -> { + JSON.load(json).class.should == JSONSpecs::MyClass + }.should output_to_fd(warning, STDERR) - JSON.parse(json).class.should == Hash - JSON.parse(json, nil).class.should == Hash - JSON(json).class.should == Hash + JSON.parse(json).class.should == Hash + JSON.parse(json, nil).class.should == Hash + JSON(json).class.should == Hash + end end end end diff --git a/spec/ruby/security/cve_2024_49761_spec.rb b/spec/ruby/security/cve_2024_49761_spec.rb index 54ede390326e..c66b438eef60 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?(/�*((?:\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?(/�*((?:\d+)|(?:x[a-fA-F0-9]+));/).should == true end end diff --git a/spec/ruby/shared/file/sticky.rb b/spec/ruby/shared/file/sticky.rb index 38bb6ed26b97..e07fa22fd7d1 100644 --- a/spec/ruby/shared/file/sticky.rb +++ b/spec/ruby/shared/file/sticky.rb @@ -8,7 +8,7 @@ Dir.rmdir(@dir) if File.exist?(@dir) end - platform_is_not :windows, :darwin, :freebsd, :netbsd, :openbsd, :solaris, :aix do + platform_is_not :windows, :darwin, :freebsd, :netbsd, :openbsd, :aix do it "returns true if the named file has the sticky bit, otherwise false" do Dir.mkdir @dir, 01755 diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb index 0abba5301e02..a154da627473 100644 --- a/spec/ruby/shared/queue/deque.rb +++ b/spec/ruby/shared/queue/deque.rb @@ -65,66 +65,64 @@ 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 2f2551767571..6804af3fb332 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -49,83 +49,81 @@ 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 From 5924ca0c3e28085321680ed0e5b28bde5b809020 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 12 May 2025 15:47:36 +0300 Subject: [PATCH 2/5] Add slow tags --- spec/tags/command_line/dash_0_tags.txt | 1 + spec/tags/core/set/set_tags.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 spec/tags/command_line/dash_0_tags.txt create mode 100644 spec/tags/core/set/set_tags.txt diff --git a/spec/tags/command_line/dash_0_tags.txt b/spec/tags/command_line/dash_0_tags.txt new file mode 100644 index 000000000000..8b8440d79e1e --- /dev/null +++ b/spec/tags/command_line/dash_0_tags.txt @@ -0,0 +1 @@ +slow:The -0 command line option sets $/ and $-0 diff --git a/spec/tags/core/set/set_tags.txt b/spec/tags/core/set/set_tags.txt new file mode 100644 index 000000000000..4e1f64012047 --- /dev/null +++ b/spec/tags/core/set/set_tags.txt @@ -0,0 +1 @@ +slow:Set is available without explicit requiring From d5f925064ed1740a07d66b7a786479df31bba79c Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 12 May 2025 15:47:53 +0300 Subject: [PATCH 3/5] Tag failing specs --- spec/tags/command_line/dash_0_tags.txt | 1 + spec/tags/core/file/printf_tags.txt | 3 +++ spec/tags/core/kernel/printf_tags.txt | 6 ++++++ spec/tags/core/kernel/sprintf_tags.txt | 6 ++++++ spec/tags/core/set/compare_by_identity_tags.txt | 1 + spec/tags/core/set/divide_tags.txt | 1 + spec/tags/core/string/modulo_tags.txt | 3 +++ .../objectspace/trace_object_allocations_tags.txt | 9 +++++++++ spec/tags/library/stringio/printf_tags.txt | 3 +++ 9 files changed, 33 insertions(+) create mode 100644 spec/tags/core/set/compare_by_identity_tags.txt create mode 100644 spec/tags/core/set/divide_tags.txt diff --git a/spec/tags/command_line/dash_0_tags.txt b/spec/tags/command_line/dash_0_tags.txt index 8b8440d79e1e..e5cffd8c2046 100644 --- a/spec/tags/command_line/dash_0_tags.txt +++ b/spec/tags/command_line/dash_0_tags.txt @@ -1 +1,2 @@ slow:The -0 command line option sets $/ and $-0 +fails:The -0 command line option sets $/ and $-0 diff --git a/spec/tags/core/file/printf_tags.txt b/spec/tags/core/file/printf_tags.txt index 1fa8a5974161..7b0bfd515f50 100644 --- a/spec/tags/core/file/printf_tags.txt +++ b/spec/tags/core/file/printf_tags.txt @@ -5,3 +5,6 @@ fails:File#printf flags # applies to format o does nothing for negative argument fails:File#printf flags # applies to formats bBxX does nothing for zero argument fails:File#printf other formats c displays only the first character if argument is a string of several characters fails:File#printf other formats c displays no characters if argument is an empty string +fails:File#printf integer formats d converts to the empty string if precision is 0 and value is 0 +fails:File#printf integer formats i converts to the empty string if precision is 0 and value is 0 +fails:File#printf integer formats u converts to the empty string if precision is 0 and value is 0 diff --git a/spec/tags/core/kernel/printf_tags.txt b/spec/tags/core/kernel/printf_tags.txt index 70bc8e1c090b..48982d88aa9d 100644 --- a/spec/tags/core/kernel/printf_tags.txt +++ b/spec/tags/core/kernel/printf_tags.txt @@ -8,3 +8,9 @@ fails:Kernel.printf formatting io is specified other formats c displays only the fails:Kernel.printf formatting io is specified other formats c displays no characters if argument is an empty string fails:Kernel.printf formatting io is not specified other formats c displays only the first character if argument is a string of several characters fails:Kernel.printf formatting io is not specified other formats c displays no characters if argument is an empty string +fails:Kernel.printf formatting io is specified integer formats d converts to the empty string if precision is 0 and value is 0 +fails:Kernel.printf formatting io is specified integer formats i converts to the empty string if precision is 0 and value is 0 +fails:Kernel.printf formatting io is specified integer formats u converts to the empty string if precision is 0 and value is 0 +fails:Kernel.printf formatting io is not specified integer formats d converts to the empty string if precision is 0 and value is 0 +fails:Kernel.printf formatting io is not specified integer formats i converts to the empty string if precision is 0 and value is 0 +fails:Kernel.printf formatting io is not specified integer formats u converts to the empty string if precision is 0 and value is 0 diff --git a/spec/tags/core/kernel/sprintf_tags.txt b/spec/tags/core/kernel/sprintf_tags.txt index 21bc1b23b2e5..64e425e7e991 100644 --- a/spec/tags/core/kernel/sprintf_tags.txt +++ b/spec/tags/core/kernel/sprintf_tags.txt @@ -12,3 +12,9 @@ fails:Kernel#sprintf other formats c displays only the first character if argume fails:Kernel#sprintf other formats c displays no characters if argument is an empty string fails:Kernel.sprintf other formats c displays only the first character if argument is a string of several characters fails:Kernel.sprintf other formats c displays no characters if argument is an empty string +fails:Kernel#sprintf integer formats d converts to the empty string if precision is 0 and value is 0 +fails:Kernel#sprintf integer formats i converts to the empty string if precision is 0 and value is 0 +fails:Kernel#sprintf integer formats u converts to the empty string if precision is 0 and value is 0 +fails:Kernel.sprintf integer formats d converts to the empty string if precision is 0 and value is 0 +fails:Kernel.sprintf integer formats i converts to the empty string if precision is 0 and value is 0 +fails:Kernel.sprintf integer formats u converts to the empty string if precision is 0 and value is 0 diff --git a/spec/tags/core/set/compare_by_identity_tags.txt b/spec/tags/core/set/compare_by_identity_tags.txt new file mode 100644 index 000000000000..bcee51db40bb --- /dev/null +++ b/spec/tags/core/set/compare_by_identity_tags.txt @@ -0,0 +1 @@ +fails:Set#compare_by_identity is not equal to set what does not compare by identity diff --git a/spec/tags/core/set/divide_tags.txt b/spec/tags/core/set/divide_tags.txt new file mode 100644 index 000000000000..981ba7bb8915 --- /dev/null +++ b/spec/tags/core/set/divide_tags.txt @@ -0,0 +1 @@ +fails:Set#divide when passed a block with an arity of 2 returns an enumerator when not passed a block diff --git a/spec/tags/core/string/modulo_tags.txt b/spec/tags/core/string/modulo_tags.txt index 5d03579ee583..c0e0f333f38a 100644 --- a/spec/tags/core/string/modulo_tags.txt +++ b/spec/tags/core/string/modulo_tags.txt @@ -8,3 +8,6 @@ fails:String#% flags # applies to formats bBxX does nothing for zero argument fails:String#% other formats c displays only the first character if argument is a string of several characters fails:String#% other formats c displays no characters if argument is an empty string fails:String#% supports only the first character as argument for %c +fails:String#% integer formats d converts to the empty string if precision is 0 and value is 0 +fails:String#% integer formats i converts to the empty string if precision is 0 and value is 0 +fails:String#% integer formats u converts to the empty string if precision is 0 and value is 0 diff --git a/spec/tags/library/objectspace/trace_object_allocations_tags.txt b/spec/tags/library/objectspace/trace_object_allocations_tags.txt index 07ea4bcb9089..4b76dec0a416 100644 --- a/spec/tags/library/objectspace/trace_object_allocations_tags.txt +++ b/spec/tags/library/objectspace/trace_object_allocations_tags.txt @@ -12,3 +12,12 @@ slow:ObjectSpace.trace_object_allocations records info for allocation_class_path slow:ObjectSpace.trace_object_allocations records info for allocation_method_id slow:ObjectSpace.trace_object_allocations can be used without a block using trace_object_allocations_start and _stop slow:ObjectSpace.trace_object_allocations returns nil for class_path, generation, method_id, sourcefile, and sourceline for immutable objects +fails:ObjectSpace.trace_object_allocations records info for allocation_class_path +fails:ObjectSpace.trace_object_allocations records info for allocation_method_id +fails:ObjectSpace.trace_object_allocations can be cleared using trace_object_allocations_clear +fails:ObjectSpace.trace_object_allocations does not clears allocation data after returning +fails:ObjectSpace.trace_object_allocations can be used without a block using trace_object_allocations_start and _stop +fails:ObjectSpace.trace_object_allocations does not clears allocation data after trace_object_allocations_stop +fails:ObjectSpace.trace_object_allocations can be nested +fails:ObjectSpace.trace_object_allocations can be nested without a block using trace_object_allocations_start and _stop +fails:ObjectSpace.trace_object_allocations can be nested with more _stop than _start diff --git a/spec/tags/library/stringio/printf_tags.txt b/spec/tags/library/stringio/printf_tags.txt index 3467e66f0812..f89f6648bcd3 100644 --- a/spec/tags/library/stringio/printf_tags.txt +++ b/spec/tags/library/stringio/printf_tags.txt @@ -3,3 +3,6 @@ fails:StringIO#printf formatting flags # applies to format o does nothing for ne fails:StringIO#printf formatting flags # applies to formats bBxX does nothing for zero argument fails:StringIO#printf formatting other formats c displays only the first character if argument is a string of several characters fails:StringIO#printf formatting other formats c displays no characters if argument is an empty string +fails:StringIO#printf formatting integer formats d converts to the empty string if precision is 0 and value is 0 +fails:StringIO#printf formatting integer formats i converts to the empty string if precision is 0 and value is 0 +fails:StringIO#printf formatting integer formats u converts to the empty string if precision is 0 and value is 0 From ef1a4ab443a3cfab84533b1124babafec47b51ce Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Tue, 13 May 2025 14:44:15 +0300 Subject: [PATCH 4/5] Restore `ruby_version_is "3.2.3" do` guards --- spec/ruby/core/fiber/storage_spec.rb | 18 +++++----- spec/ruby/core/string/to_f_spec.rb | 10 +++--- spec/ruby/core/time/new_spec.rb | 52 +++++++++++++++------------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb index 3d39f32009b5..015caaf3bbff 100644 --- a/spec/ruby/core/fiber/storage_spec.rb +++ b/spec/ruby/core/fiber/storage_spec.rb @@ -84,15 +84,17 @@ Fiber.new { Fiber[:life] }.resume.should be_nil end - 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_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 "can't use invalid keys" do - invalid_keys = [Object.new, 12] - invalid_keys.each do |key| - -> { Fiber[key] }.should raise_error(TypeError) + 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 diff --git a/spec/ruby/core/string/to_f_spec.rb b/spec/ruby/core/string/to_f_spec.rb index ab1ba43fb3c6..a91ccc168ecf 100644 --- a/spec/ruby/core/string/to_f_spec.rb +++ b/spec/ruby/core/string/to_f_spec.rb @@ -120,9 +120,11 @@ "\3771.2".b.to_f.should == 0 end - 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") + 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 end diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index f288da84ddc0..9638de31e78e 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -550,16 +550,18 @@ def obj.to_int; 3; end }.should raise_error(ArgumentError, /missing min part: 00 |can't parse:/) end - 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 + 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:/) + it "raises ArgumentError if day is missing" do + -> { + Time.new("2020-12") + }.should raise_error(ArgumentError, /no time information|can't parse:/) + end end it "raises ArgumentError if subsecond is missing after dot" do @@ -698,22 +700,24 @@ def obj.to_int; 3; end }.should raise_error(ArgumentError, /can't parse.+ abc/) end - 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/) + 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 end From d25c5e3b4022139f4253ad5aa509eee607d941e0 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Wed, 14 May 2025 14:50:30 +0300 Subject: [PATCH 5/5] Don't run specs on Ruby 3.1 ruby/spec now is compatible only with Ruby 3.2 --- ci.jsonnet | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci.jsonnet b/ci.jsonnet index 418f92ea8bb9..b7bd9b69963c 100644 --- a/ci.jsonnet +++ b/ci.jsonnet @@ -324,8 +324,7 @@ local part_definitions = { "CHECK_LEAKS": "true", "RUBY_SPEC_TEST_ZLIB_CRC_TABLE": "false", # CRuby was built on OL6 and is used on OL7 }, - run+: jt(["-u", "ruby", "mspec", "spec/ruby"]) + # 3.2.2 - jt(["-u", "/cm/shared/apps-ol7/ruby/3.1.2/bin/ruby", "mspec", "spec/ruby"]), + run+: jt(["-u", "ruby", "mspec", "spec/ruby"]), # 3.2.2 }, test_fast: {