summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/.rubocop.yml5
-rw-r--r--spec/ruby/.rubocop_todo.yml5
-rw-r--r--spec/ruby/CONTRIBUTING.md72
-rw-r--r--spec/ruby/core/array/append_spec.rb2
-rw-r--r--spec/ruby/core/array/collect_spec.rb4
-rw-r--r--spec/ruby/core/array/element_reference_spec.rb2
-rw-r--r--spec/ruby/core/array/element_set_spec.rb35
-rw-r--r--spec/ruby/core/array/index_spec.rb2
-rw-r--r--spec/ruby/core/array/length_spec.rb2
-rw-r--r--spec/ruby/core/array/map_spec.rb4
-rw-r--r--spec/ruby/core/array/prepend_spec.rb2
-rw-r--r--spec/ruby/core/array/push_spec.rb2
-rw-r--r--spec/ruby/core/array/replace_spec.rb2
-rw-r--r--spec/ruby/core/array/size_spec.rb2
-rw-r--r--spec/ruby/core/array/slice_spec.rb2
-rw-r--r--spec/ruby/core/array/unshift_spec.rb2
-rw-r--r--spec/ruby/core/basicobject/__send___spec.rb2
-rw-r--r--spec/ruby/core/bignum/bignum_spec.rb31
-rw-r--r--spec/ruby/core/bignum/bit_and_spec.rb50
-rw-r--r--spec/ruby/core/bignum/bit_length_spec.rb33
-rw-r--r--spec/ruby/core/bignum/bit_or_spec.rb41
-rw-r--r--spec/ruby/core/bignum/bit_xor_spec.rb47
-rw-r--r--spec/ruby/core/bignum/case_compare_spec.rb6
-rw-r--r--spec/ruby/core/bignum/coerce_spec.rb65
-rw-r--r--spec/ruby/core/bignum/comparison_spec.rb162
-rw-r--r--spec/ruby/core/bignum/complement_spec.rb9
-rw-r--r--spec/ruby/core/bignum/div_spec.rb21
-rw-r--r--spec/ruby/core/bignum/divide_spec.rb18
-rw-r--r--spec/ruby/core/bignum/divmod_spec.rb81
-rw-r--r--spec/ruby/core/bignum/element_reference_spec.rb30
-rw-r--r--spec/ruby/core/bignum/eql_spec.rb22
-rw-r--r--spec/ruby/core/bignum/equal_value_spec.rb6
-rw-r--r--spec/ruby/core/bignum/even_spec.rb19
-rw-r--r--spec/ruby/core/bignum/exponent_spec.rb29
-rw-r--r--spec/ruby/core/bignum/fdiv_spec.rb5
-rw-r--r--spec/ruby/core/bignum/gt_spec.rb20
-rw-r--r--spec/ruby/core/bignum/gte_spec.rb19
-rw-r--r--spec/ruby/core/bignum/hash_spec.rb12
-rw-r--r--spec/ruby/core/bignum/left_shift_spec.rb73
-rw-r--r--spec/ruby/core/bignum/lt_spec.rb22
-rw-r--r--spec/ruby/core/bignum/lte_spec.rb24
-rw-r--r--spec/ruby/core/bignum/magnitude_spec.rb6
-rw-r--r--spec/ruby/core/bignum/minus_spec.rb19
-rw-r--r--spec/ruby/core/bignum/modulo_spec.rb10
-rw-r--r--spec/ruby/core/bignum/multiply_spec.rb20
-rw-r--r--spec/ruby/core/bignum/odd_spec.rb19
-rw-r--r--spec/ruby/core/bignum/plus_spec.rb19
-rw-r--r--spec/ruby/core/bignum/remainder_spec.rb21
-rw-r--r--spec/ruby/core/bignum/right_shift_spec.rb99
-rw-r--r--spec/ruby/core/bignum/shared/abs.rb6
-rw-r--r--spec/ruby/core/bignum/shared/divide.rb27
-rw-r--r--spec/ruby/core/bignum/shared/equal.rb31
-rw-r--r--spec/ruby/core/bignum/shared/modulo.rb29
-rw-r--r--spec/ruby/core/bignum/size_spec.rb16
-rw-r--r--spec/ruby/core/bignum/to_f_spec.rb13
-rw-r--r--spec/ruby/core/bignum/to_s_spec.rb48
-rw-r--r--spec/ruby/core/bignum/uminus_spec.rb11
-rw-r--r--spec/ruby/core/binding/clone_spec.rb2
-rw-r--r--spec/ruby/core/binding/dup_spec.rb2
-rw-r--r--spec/ruby/core/complex/abs2_spec.rb2
-rw-r--r--spec/ruby/core/complex/abs_spec.rb2
-rw-r--r--spec/ruby/core/complex/angle_spec.rb2
-rw-r--r--spec/ruby/core/complex/arg_spec.rb2
-rw-r--r--spec/ruby/core/complex/coerce_spec.rb2
-rw-r--r--spec/ruby/core/complex/conj_spec.rb2
-rw-r--r--spec/ruby/core/complex/conjugate_spec.rb2
-rw-r--r--spec/ruby/core/complex/denominator_spec.rb2
-rw-r--r--spec/ruby/core/complex/hash_spec.rb14
-rw-r--r--spec/ruby/core/complex/imag_spec.rb2
-rw-r--r--spec/ruby/core/complex/inspect_spec.rb2
-rw-r--r--spec/ruby/core/complex/magnitude_spec.rb2
-rw-r--r--spec/ruby/core/complex/numerator_spec.rb2
-rw-r--r--spec/ruby/core/complex/polar_spec.rb4
-rw-r--r--spec/ruby/core/complex/real_spec.rb2
-rw-r--r--spec/ruby/core/complex/rect_spec.rb4
-rw-r--r--spec/ruby/core/complex/rectangular_spec.rb4
-rw-r--r--spec/ruby/core/complex/to_s_spec.rb2
-rw-r--r--spec/ruby/core/dir/exist_spec.rb2
-rw-r--r--spec/ruby/core/dir/exists_spec.rb2
-rw-r--r--spec/ruby/core/dir/path_spec.rb2
-rw-r--r--spec/ruby/core/dir/to_path_spec.rb2
-rw-r--r--spec/ruby/core/encoding/name_spec.rb2
-rw-r--r--spec/ruby/core/encoding/to_s_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/collect_concat_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/collect_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/detect_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/entries_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/find_all_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/find_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/flat_map_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/include_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/map_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/member_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/select_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/to_a_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/each_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/each_with_index_spec.rb4
-rw-r--r--spec/ruby/core/enumerator/inject_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/lazy/chunk_spec.rb71
-rw-r--r--spec/ruby/core/enumerator/new_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/next_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/rewind_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/with_index_spec.rb4
-rw-r--r--spec/ruby/core/env/each_pair_spec.rb2
-rw-r--r--spec/ruby/core/env/each_spec.rb2
-rw-r--r--spec/ruby/core/env/element_set_spec.rb2
-rw-r--r--spec/ruby/core/env/fetch_spec.rb5
-rw-r--r--spec/ruby/core/env/has_key_spec.rb2
-rw-r--r--spec/ruby/core/env/has_value_spec.rb2
-rw-r--r--spec/ruby/core/env/include_spec.rb2
-rw-r--r--spec/ruby/core/env/index_spec.rb2
-rw-r--r--spec/ruby/core/env/key_spec.rb4
-rw-r--r--spec/ruby/core/env/length_spec.rb2
-rw-r--r--spec/ruby/core/env/member_spec.rb2
-rw-r--r--spec/ruby/core/env/size_spec.rb2
-rw-r--r--spec/ruby/core/env/store_spec.rb2
-rw-r--r--spec/ruby/core/env/to_h_spec.rb2
-rw-r--r--spec/ruby/core/env/to_hash_spec.rb2
-rw-r--r--spec/ruby/core/env/value_spec.rb2
-rw-r--r--spec/ruby/core/exception/exception_spec.rb2
-rw-r--r--spec/ruby/core/exception/fixtures/common.rb3
-rw-r--r--spec/ruby/core/exception/new_spec.rb2
-rw-r--r--spec/ruby/core/exception/no_method_error_spec.rb36
-rw-r--r--spec/ruby/core/fiber/resume_spec.rb5
-rw-r--r--spec/ruby/core/file/delete_spec.rb2
-rw-r--r--spec/ruby/core/file/exist_spec.rb2
-rw-r--r--spec/ruby/core/file/exists_spec.rb2
-rw-r--r--spec/ruby/core/file/fnmatch_spec.rb4
-rw-r--r--spec/ruby/core/file/open_spec.rb2
-rw-r--r--spec/ruby/core/file/path_spec.rb31
-rw-r--r--spec/ruby/core/file/shared/path.rb80
-rw-r--r--spec/ruby/core/file/stat/world_readable_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/world_writable_spec.rb2
-rw-r--r--spec/ruby/core/file/to_path_spec.rb47
-rw-r--r--spec/ruby/core/file/unlink_spec.rb2
-rw-r--r--spec/ruby/core/file/world_readable_spec.rb2
-rw-r--r--spec/ruby/core/file/world_writable_spec.rb2
-rw-r--r--spec/ruby/core/fixnum/bit_and_spec.rb46
-rw-r--r--spec/ruby/core/fixnum/bit_length_spec.rb42
-rw-r--r--spec/ruby/core/fixnum/bit_or_spec.rb26
-rw-r--r--spec/ruby/core/fixnum/bit_xor_spec.rb24
-rw-r--r--spec/ruby/core/fixnum/coerce_spec.rb39
-rw-r--r--spec/ruby/core/fixnum/comparison_spec.rb26
-rw-r--r--spec/ruby/core/fixnum/complement_spec.rb10
-rw-r--r--spec/ruby/core/fixnum/div_spec.rb44
-rw-r--r--spec/ruby/core/fixnum/divide_spec.rb35
-rw-r--r--spec/ruby/core/fixnum/divmod_spec.rb35
-rw-r--r--spec/ruby/core/fixnum/element_reference_spec.rb80
-rw-r--r--spec/ruby/core/fixnum/even_spec.rb23
-rw-r--r--spec/ruby/core/fixnum/exponent_spec.rb76
-rw-r--r--spec/ruby/core/fixnum/fixnum_spec.rb31
-rw-r--r--spec/ruby/core/fixnum/gt_spec.rb19
-rw-r--r--spec/ruby/core/fixnum/gte_spec.rb20
-rw-r--r--spec/ruby/core/fixnum/hash_spec.rb11
-rw-r--r--spec/ruby/core/fixnum/left_shift_spec.rb91
-rw-r--r--spec/ruby/core/fixnum/lt_spec.rb19
-rw-r--r--spec/ruby/core/fixnum/lte_spec.rb20
-rw-r--r--spec/ruby/core/fixnum/magnitude_spec.rb6
-rw-r--r--spec/ruby/core/fixnum/minus_spec.rb29
-rw-r--r--spec/ruby/core/fixnum/modulo_spec.rb10
-rw-r--r--spec/ruby/core/fixnum/multiply_spec.rb27
-rw-r--r--spec/ruby/core/fixnum/odd_spec.rb23
-rw-r--r--spec/ruby/core/fixnum/plus_spec.rb29
-rw-r--r--spec/ruby/core/fixnum/right_shift_spec.rb91
-rw-r--r--spec/ruby/core/fixnum/shared/abs.rb9
-rw-r--r--spec/ruby/core/fixnum/shared/equal.rb24
-rw-r--r--spec/ruby/core/fixnum/shared/modulo.rb42
-rw-r--r--spec/ruby/core/fixnum/size_spec.rb19
-rw-r--r--spec/ruby/core/fixnum/succ_spec.rb15
-rw-r--r--spec/ruby/core/fixnum/to_f_spec.rb9
-rw-r--r--spec/ruby/core/fixnum/to_s_spec.rb50
-rw-r--r--spec/ruby/core/fixnum/uminus_spec.rb16
-rw-r--r--spec/ruby/core/fixnum/zero_spec.rb9
-rw-r--r--spec/ruby/core/float/abs_spec.rb2
-rw-r--r--spec/ruby/core/float/magnitude_spec.rb2
-rw-r--r--spec/ruby/core/float/modulo_spec.rb4
-rw-r--r--spec/ruby/core/float/to_i_spec.rb2
-rw-r--r--spec/ruby/core/float/to_int_spec.rb2
-rw-r--r--spec/ruby/core/float/truncate_spec.rb2
-rw-r--r--spec/ruby/core/hash/delete_if_spec.rb4
-rw-r--r--spec/ruby/core/hash/each_key_spec.rb4
-rw-r--r--spec/ruby/core/hash/each_pair_spec.rb6
-rw-r--r--spec/ruby/core/hash/each_spec.rb6
-rw-r--r--spec/ruby/core/hash/each_value_spec.rb4
-rw-r--r--spec/ruby/core/hash/element_set_spec.rb2
-rw-r--r--spec/ruby/core/hash/fetch_spec.rb14
-rw-r--r--spec/ruby/core/hash/fetch_values_spec.rb6
-rw-r--r--spec/ruby/core/hash/has_key_spec.rb2
-rw-r--r--spec/ruby/core/hash/has_value_spec.rb2
-rw-r--r--spec/ruby/core/hash/include_spec.rb2
-rw-r--r--spec/ruby/core/hash/keep_if_spec.rb4
-rw-r--r--spec/ruby/core/hash/key_spec.rb4
-rw-r--r--spec/ruby/core/hash/length_spec.rb2
-rw-r--r--spec/ruby/core/hash/member_spec.rb2
-rw-r--r--spec/ruby/core/hash/merge_spec.rb2
-rw-r--r--spec/ruby/core/hash/rehash_spec.rb15
-rw-r--r--spec/ruby/core/hash/reject_spec.rb8
-rw-r--r--spec/ruby/core/hash/replace_spec.rb2
-rw-r--r--spec/ruby/core/hash/select_spec.rb8
-rw-r--r--spec/ruby/core/hash/size_spec.rb2
-rw-r--r--spec/ruby/core/hash/store_spec.rb2
-rw-r--r--spec/ruby/core/hash/transform_keys_spec.rb38
-rw-r--r--spec/ruby/core/hash/update_spec.rb2
-rw-r--r--spec/ruby/core/hash/value_spec.rb2
-rw-r--r--spec/ruby/core/hash/values_at_spec.rb2
-rw-r--r--spec/ruby/core/integer/abs_spec.rb (renamed from spec/ruby/core/bignum/abs_spec.rb)4
-rw-r--r--spec/ruby/core/integer/bit_and_spec.rb97
-rw-r--r--spec/ruby/core/integer/bit_length_spec.rb76
-rw-r--r--spec/ruby/core/integer/bit_or_spec.rb68
-rw-r--r--spec/ruby/core/integer/bit_xor_spec.rb72
-rw-r--r--spec/ruby/core/integer/case_compare_spec.rb (renamed from spec/ruby/core/fixnum/case_compare_spec.rb)4
-rw-r--r--spec/ruby/core/integer/ceil_spec.rb4
-rw-r--r--spec/ruby/core/integer/chr_spec.rb4
-rw-r--r--spec/ruby/core/integer/coerce_spec.rb105
-rw-r--r--spec/ruby/core/integer/comparison_spec.rb189
-rw-r--r--spec/ruby/core/integer/complement_spec.rb20
-rw-r--r--spec/ruby/core/integer/div_spec.rb138
-rw-r--r--spec/ruby/core/integer/divide_spec.rb93
-rw-r--r--spec/ruby/core/integer/divmod_spec.rb117
-rw-r--r--spec/ruby/core/integer/dup_spec.rb10
-rw-r--r--spec/ruby/core/integer/element_reference_spec.rb111
-rw-r--r--spec/ruby/core/integer/equal_value_spec.rb (renamed from spec/ruby/core/fixnum/equal_value_spec.rb)5
-rw-r--r--spec/ruby/core/integer/even_spec.rb42
-rw-r--r--spec/ruby/core/integer/exponent_spec.rb7
-rw-r--r--spec/ruby/core/integer/fdiv_spec.rb (renamed from spec/ruby/core/fixnum/fdiv_spec.rb)6
-rw-r--r--spec/ruby/core/integer/floor_spec.rb4
-rw-r--r--spec/ruby/core/integer/gt_spec.rb47
-rw-r--r--spec/ruby/core/integer/gte_spec.rb47
-rw-r--r--spec/ruby/core/integer/left_shift_spec.rb165
-rw-r--r--spec/ruby/core/integer/lt_spec.rb50
-rw-r--r--spec/ruby/core/integer/lte_spec.rb53
-rw-r--r--spec/ruby/core/integer/magnitude_spec.rb (renamed from spec/ruby/core/fixnum/abs_spec.rb)4
-rw-r--r--spec/ruby/core/integer/minus_spec.rb47
-rw-r--r--spec/ruby/core/integer/modulo_spec.rb10
-rw-r--r--spec/ruby/core/integer/multiply_spec.rb50
-rw-r--r--spec/ruby/core/integer/next_spec.rb2
-rw-r--r--spec/ruby/core/integer/odd_spec.rb40
-rw-r--r--spec/ruby/core/integer/plus_spec.rb48
-rw-r--r--spec/ruby/core/integer/pow_spec.rb51
-rw-r--r--spec/ruby/core/integer/remainder_spec.rb51
-rw-r--r--spec/ruby/core/integer/right_shift_spec.rb191
-rw-r--r--spec/ruby/core/integer/round_spec.rb4
-rw-r--r--spec/ruby/core/integer/shared/abs.rb18
-rw-r--r--spec/ruby/core/integer/shared/arithmetic_coerce.rb31
-rw-r--r--spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb33
-rw-r--r--spec/ruby/core/integer/shared/comparison_coerce.rb33
-rw-r--r--spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb35
-rw-r--r--spec/ruby/core/integer/shared/equal.rb58
-rw-r--r--spec/ruby/core/integer/shared/exponent.rb118
-rw-r--r--spec/ruby/core/integer/shared/modulo.rb74
-rw-r--r--spec/ruby/core/integer/size_spec.rb34
-rw-r--r--spec/ruby/core/integer/succ_spec.rb2
-rw-r--r--spec/ruby/core/integer/to_f_spec.rb23
-rw-r--r--spec/ruby/core/integer/to_i_spec.rb2
-rw-r--r--spec/ruby/core/integer/to_int_spec.rb2
-rw-r--r--spec/ruby/core/integer/to_s_spec.rb99
-rw-r--r--spec/ruby/core/integer/truncate_spec.rb4
-rw-r--r--spec/ruby/core/integer/uminus_spec.rb28
-rw-r--r--spec/ruby/core/io/close_spec.rb26
-rw-r--r--spec/ruby/core/io/codepoints_spec.rb2
-rw-r--r--spec/ruby/core/io/each_codepoint_spec.rb2
-rw-r--r--spec/ruby/core/io/tell_spec.rb2
-rw-r--r--spec/ruby/core/io/ungetc_spec.rb16
-rw-r--r--spec/ruby/core/kernel/Hash_spec.rb8
-rw-r--r--spec/ruby/core/kernel/is_a_spec.rb2
-rw-r--r--spec/ruby/core/kernel/kind_of_spec.rb2
-rw-r--r--spec/ruby/core/kernel/lambda_spec.rb2
-rw-r--r--spec/ruby/core/kernel/method_spec.rb2
-rw-r--r--spec/ruby/core/kernel/proc_spec.rb2
-rw-r--r--spec/ruby/core/kernel/public_method_spec.rb2
-rw-r--r--spec/ruby/core/kernel/public_send_spec.rb2
-rw-r--r--spec/ruby/core/kernel/send_spec.rb2
-rw-r--r--spec/ruby/core/kernel/shared/sprintf.rb18
-rw-r--r--spec/ruby/core/kernel/system_spec.rb12
-rw-r--r--spec/ruby/core/kernel/yield_self_spec.rb4
-rw-r--r--spec/ruby/core/matchdata/eql_spec.rb2
-rw-r--r--spec/ruby/core/matchdata/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/matchdata/length_spec.rb2
-rw-r--r--spec/ruby/core/matchdata/size_spec.rb2
-rw-r--r--spec/ruby/core/method/call_spec.rb2
-rw-r--r--spec/ruby/core/method/case_compare_spec.rb2
-rw-r--r--spec/ruby/core/method/element_reference_spec.rb2
-rw-r--r--spec/ruby/core/method/eql_spec.rb2
-rw-r--r--spec/ruby/core/method/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/method/inspect_spec.rb2
-rw-r--r--spec/ruby/core/method/to_proc_spec.rb4
-rw-r--r--spec/ruby/core/method/to_s_spec.rb2
-rw-r--r--spec/ruby/core/module/const_missing_spec.rb9
-rw-r--r--spec/ruby/core/module/define_method_spec.rb25
-rw-r--r--spec/ruby/core/module/eql_spec.rb2
-rw-r--r--spec/ruby/core/module/equal_spec.rb2
-rw-r--r--spec/ruby/core/module/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/numeric/abs_spec.rb2
-rw-r--r--spec/ruby/core/numeric/angle_spec.rb2
-rw-r--r--spec/ruby/core/numeric/arg_spec.rb2
-rw-r--r--spec/ruby/core/numeric/coerce_spec.rb35
-rw-r--r--spec/ruby/core/numeric/conj_spec.rb2
-rw-r--r--spec/ruby/core/numeric/conjugate_spec.rb2
-rw-r--r--spec/ruby/core/numeric/imag_spec.rb2
-rw-r--r--spec/ruby/core/numeric/imaginary_spec.rb2
-rw-r--r--spec/ruby/core/numeric/magnitude_spec.rb2
-rw-r--r--spec/ruby/core/numeric/phase_spec.rb2
-rw-r--r--spec/ruby/core/numeric/polar_spec.rb2
-rw-r--r--spec/ruby/core/numeric/real_spec.rb2
-rw-r--r--spec/ruby/core/numeric/rect_spec.rb2
-rw-r--r--spec/ruby/core/numeric/rectangular_spec.rb2
-rw-r--r--spec/ruby/core/proc/clone_spec.rb2
-rw-r--r--spec/ruby/core/proc/dup_spec.rb2
-rw-r--r--spec/ruby/core/proc/eql_spec.rb2
-rw-r--r--spec/ruby/core/proc/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/process/last_status_spec.rb20
-rw-r--r--spec/ruby/core/process/setrlimit_spec.rb4
-rw-r--r--spec/ruby/core/range/begin_spec.rb2
-rw-r--r--spec/ruby/core/range/end_spec.rb2
-rw-r--r--spec/ruby/core/range/eql_spec.rb2
-rw-r--r--spec/ruby/core/range/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/range/first_spec.rb2
-rw-r--r--spec/ruby/core/range/last_spec.rb2
-rw-r--r--spec/ruby/core/rational/abs_spec.rb2
-rw-r--r--spec/ruby/core/rational/ceil_spec.rb2
-rw-r--r--spec/ruby/core/rational/coerce_spec.rb2
-rw-r--r--spec/ruby/core/rational/comparison_spec.rb12
-rw-r--r--spec/ruby/core/rational/denominator_spec.rb2
-rw-r--r--spec/ruby/core/rational/div_spec.rb8
-rw-r--r--spec/ruby/core/rational/divide_spec.rb8
-rw-r--r--spec/ruby/core/rational/divmod_spec.rb6
-rw-r--r--spec/ruby/core/rational/equal_value_spec.rb8
-rw-r--r--spec/ruby/core/rational/exponent_spec.rb2
-rw-r--r--spec/ruby/core/rational/fdiv_spec.rb2
-rw-r--r--spec/ruby/core/rational/floor_spec.rb2
-rw-r--r--spec/ruby/core/rational/hash_spec.rb2
-rw-r--r--spec/ruby/core/rational/inspect_spec.rb2
-rw-r--r--spec/ruby/core/rational/magnitude_spec.rb2
-rw-r--r--spec/ruby/core/rational/minus_spec.rb2
-rw-r--r--spec/ruby/core/rational/modulo_spec.rb2
-rw-r--r--spec/ruby/core/rational/multiply_spec.rb8
-rw-r--r--spec/ruby/core/rational/numerator_spec.rb2
-rw-r--r--spec/ruby/core/rational/plus_spec.rb8
-rw-r--r--spec/ruby/core/rational/quo_spec.rb2
-rw-r--r--spec/ruby/core/rational/remainder_spec.rb2
-rw-r--r--spec/ruby/core/rational/round_spec.rb2
-rw-r--r--spec/ruby/core/rational/to_f_spec.rb2
-rw-r--r--spec/ruby/core/rational/to_i_spec.rb2
-rw-r--r--spec/ruby/core/rational/to_r_spec.rb2
-rw-r--r--spec/ruby/core/rational/to_s_spec.rb2
-rw-r--r--spec/ruby/core/rational/truncate_spec.rb2
-rw-r--r--spec/ruby/core/regexp/match_spec.rb4
-rw-r--r--spec/ruby/core/signal/signame_spec.rb7
-rw-r--r--spec/ruby/core/signal/trap_spec.rb6
-rw-r--r--spec/ruby/core/string/case_compare_spec.rb4
-rw-r--r--spec/ruby/core/string/chars_spec.rb2
-rw-r--r--spec/ruby/core/string/codepoints_spec.rb2
-rw-r--r--spec/ruby/core/string/each_char_spec.rb4
-rw-r--r--spec/ruby/core/string/each_codepoint_spec.rb4
-rw-r--r--spec/ruby/core/string/each_line_spec.rb4
-rw-r--r--spec/ruby/core/string/eql_spec.rb2
-rw-r--r--spec/ruby/core/string/equal_value_spec.rb4
-rw-r--r--spec/ruby/core/string/intern_spec.rb2
-rw-r--r--spec/ruby/core/string/length_spec.rb2
-rw-r--r--spec/ruby/core/string/lines_spec.rb2
-rw-r--r--spec/ruby/core/string/modulo_spec.rb9
-rw-r--r--spec/ruby/core/string/next_spec.rb4
-rw-r--r--spec/ruby/core/string/size_spec.rb2
-rw-r--r--spec/ruby/core/string/start_with_spec.rb31
-rw-r--r--spec/ruby/core/string/succ_spec.rb4
-rw-r--r--spec/ruby/core/string/to_s_spec.rb2
-rw-r--r--spec/ruby/core/string/to_str_spec.rb2
-rw-r--r--spec/ruby/core/string/to_sym_spec.rb2
-rw-r--r--spec/ruby/core/string/uminus_spec.rb25
-rw-r--r--spec/ruby/core/struct/eql_spec.rb2
-rw-r--r--spec/ruby/core/struct/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/struct/inspect_spec.rb2
-rw-r--r--spec/ruby/core/struct/to_s_spec.rb2
-rw-r--r--spec/ruby/core/symbol/element_reference_spec.rb2
-rw-r--r--spec/ruby/core/symbol/id2name_spec.rb2
-rw-r--r--spec/ruby/core/symbol/slice_spec.rb2
-rw-r--r--spec/ruby/core/symbol/to_s_spec.rb2
-rw-r--r--spec/ruby/core/thread/backtrace_spec.rb8
-rw-r--r--spec/ruby/core/thread/current_spec.rb16
-rw-r--r--spec/ruby/core/thread/fetch_spec.rb38
-rw-r--r--spec/ruby/core/thread/priority_spec.rb20
-rw-r--r--spec/ruby/core/time/asctime_spec.rb2
-rw-r--r--spec/ruby/core/time/ctime_spec.rb2
-rw-r--r--spec/ruby/core/time/day_spec.rb2
-rw-r--r--spec/ruby/core/time/dst_spec.rb2
-rw-r--r--spec/ruby/core/time/getgm_spec.rb2
-rw-r--r--spec/ruby/core/time/getutc_spec.rb2
-rw-r--r--spec/ruby/core/time/gm_spec.rb8
-rw-r--r--spec/ruby/core/time/gmt_offset_spec.rb2
-rw-r--r--spec/ruby/core/time/gmtime_spec.rb2
-rw-r--r--spec/ruby/core/time/gmtoff_spec.rb2
-rw-r--r--spec/ruby/core/time/isdst_spec.rb2
-rw-r--r--spec/ruby/core/time/local_spec.rb10
-rw-r--r--spec/ruby/core/time/mday_spec.rb2
-rw-r--r--spec/ruby/core/time/mktime_spec.rb10
-rw-r--r--spec/ruby/core/time/mon_spec.rb2
-rw-r--r--spec/ruby/core/time/month_spec.rb2
-rw-r--r--spec/ruby/core/time/new_spec.rb6
-rw-r--r--spec/ruby/core/time/now_spec.rb2
-rw-r--r--spec/ruby/core/time/to_i_spec.rb2
-rw-r--r--spec/ruby/core/time/tv_sec_spec.rb2
-rw-r--r--spec/ruby/core/time/utc_offset_spec.rb2
-rw-r--r--spec/ruby/core/time/utc_spec.rb10
-rw-r--r--spec/ruby/core/unboundmethod/inspect_spec.rb2
-rw-r--r--spec/ruby/core/unboundmethod/to_s_spec.rb2
-rw-r--r--spec/ruby/language/def_spec.rb37
-rw-r--r--spec/ruby/language/defined_spec.rb16
-rw-r--r--spec/ruby/language/fixtures/def.rb6
-rw-r--r--spec/ruby/language/fixtures/defined.rb5
-rw-r--r--spec/ruby/language/regexp_spec.rb20
-rw-r--r--spec/ruby/library/bigdecimal/case_compare_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/eql_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/equal_value_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/exponent_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/modulo_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/power_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/to_i_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/to_int_spec.rb2
-rw-r--r--spec/ruby/library/cgi/http_header_spec.rb2
-rw-r--r--spec/ruby/library/date/civil_spec.rb2
-rw-r--r--spec/ruby/library/date/commercial_spec.rb2
-rw-r--r--spec/ruby/library/date/new_spec.rb2
-rw-r--r--spec/ruby/library/digest/md5/append_spec.rb2
-rw-r--r--spec/ruby/library/digest/sha256/append_spec.rb2
-rw-r--r--spec/ruby/library/digest/sha384/append_spec.rb2
-rw-r--r--spec/ruby/library/digest/sha512/append_spec.rb2
-rw-r--r--spec/ruby/library/etc/endgrent_spec.rb2
-rw-r--r--spec/ruby/library/etc/endpwent_spec.rb2
-rw-r--r--spec/ruby/library/etc/getgrent_spec.rb2
-rw-r--r--spec/ruby/library/etc/getpwent_spec.rb2
-rw-r--r--spec/ruby/library/etc/group_spec.rb2
-rw-r--r--spec/ruby/library/fiber/transfer_spec.rb37
-rw-r--r--spec/ruby/library/getoptlong/each_option_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/each_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/get_option_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/get_spec.rb2
-rw-r--r--spec/ruby/library/matrix/I_spec.rb2
-rw-r--r--spec/ruby/library/matrix/antisymmetric_spec.rb52
-rw-r--r--spec/ruby/library/matrix/collect_spec.rb2
-rw-r--r--spec/ruby/library/matrix/conj_spec.rb2
-rw-r--r--spec/ruby/library/matrix/conjugate_spec.rb2
-rw-r--r--spec/ruby/library/matrix/det_spec.rb2
-rw-r--r--spec/ruby/library/matrix/determinant_spec.rb2
-rw-r--r--spec/ruby/library/matrix/eql_spec.rb2
-rw-r--r--spec/ruby/library/matrix/equal_value_spec.rb2
-rw-r--r--spec/ruby/library/matrix/identity_spec.rb2
-rw-r--r--spec/ruby/library/matrix/imag_spec.rb2
-rw-r--r--spec/ruby/library/matrix/imaginary_spec.rb2
-rw-r--r--spec/ruby/library/matrix/inv_spec.rb2
-rw-r--r--spec/ruby/library/matrix/inverse_spec.rb2
-rw-r--r--spec/ruby/library/matrix/map_spec.rb2
-rw-r--r--spec/ruby/library/matrix/rect_spec.rb2
-rw-r--r--spec/ruby/library/matrix/rectangular_spec.rb2
-rw-r--r--spec/ruby/library/matrix/t_spec.rb2
-rw-r--r--spec/ruby/library/matrix/tr_spec.rb2
-rw-r--r--spec/ruby/library/matrix/trace_spec.rb2
-rw-r--r--spec/ruby/library/matrix/transpose_spec.rb2
-rw-r--r--spec/ruby/library/matrix/unit_spec.rb2
-rw-r--r--spec/ruby/library/net/ftp/initialize_spec.rb318
-rw-r--r--spec/ruby/library/rexml/document/add_spec.rb4
-rw-r--r--spec/ruby/library/rexml/document/expanded_name_spec.rb4
-rw-r--r--spec/ruby/library/scanf/io/block_scanf_spec.rb2
-rw-r--r--spec/ruby/library/scanf/io/scanf_spec.rb2
-rw-r--r--spec/ruby/library/scanf/string/block_scanf_spec.rb2
-rw-r--r--spec/ruby/library/scanf/string/scanf_spec.rb2
-rw-r--r--spec/ruby/library/socket/addrinfo/to_s_spec.rb2
-rw-r--r--spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb2
-rw-r--r--spec/ruby/library/stringio/codepoints_spec.rb2
-rw-r--r--spec/ruby/library/stringio/each_codepoint_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/beginning_of_line_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/bol_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/clear_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/concat_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/empty_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/eos_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/matched_size_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/peek_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/peep_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/pointer_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/pos_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/rest_size_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/restsize_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/terminate_spec.rb2
-rw-r--r--spec/ruby/library/weakref/fixtures/classes.rb3
-rw-r--r--spec/ruby/optional/capi/ext/numeric_spec.c20
-rw-r--r--spec/ruby/optional/capi/ext/rubyspec.h1
-rw-r--r--spec/ruby/optional/capi/hash_spec.rb7
-rw-r--r--spec/ruby/optional/capi/numeric_spec.rb24
-rw-r--r--spec/ruby/optional/capi/string_spec.rb18
-rw-r--r--spec/ruby/security/cve_2011_4815_spec.rb11
-rw-r--r--spec/ruby/shared/complex/Complex.rb12
-rw-r--r--spec/ruby/shared/complex/hash.rb16
-rw-r--r--spec/ruby/shared/fiber/resume.rb11
-rw-r--r--spec/ruby/shared/hash/key_error.rb25
494 files changed, 4128 insertions, 3104 deletions
diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml
index d29261079e..cec5309dc8 100644
--- a/spec/ruby/.rubocop.yml
+++ b/spec/ruby/.rubocop.yml
@@ -60,6 +60,11 @@ Lint/EmptyWhen:
- language/case_spec.rb
- optional/capi/spec_helper.rb
+Lint/NestedMethodDefinition:
+ Exclude:
+ - language/def_spec.rb
+ - language/fixtures/def.rb
+
Lint/UriRegexp:
Exclude:
- 'library/uri/regexp_spec.rb'
diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml
index c227ca032d..5fc8c91a85 100644
--- a/spec/ruby/.rubocop_todo.yml
+++ b/spec/ruby/.rubocop_todo.yml
@@ -89,11 +89,6 @@ Lint/MultipleCompare:
Exclude:
- 'language/precedence_spec.rb'
-# Offense count: 8
-Lint/NestedMethodDefinition:
- Exclude:
- - 'language/def_spec.rb'
-
# Offense count: 12
Lint/ParenthesesAsGroupedExpression:
Exclude:
diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md
index fc88475970..f3a8a539a8 100644
--- a/spec/ruby/CONTRIBUTING.md
+++ b/spec/ruby/CONTRIBUTING.md
@@ -166,6 +166,76 @@ Use the implementation test suite for these.
If an implementation does not support some feature, simply tag the related specs as failing instead.
+### Shared Specs
+
+Often throughout Ruby, identical functionality is used by different methods and modules. In order
+to avoid duplication of specs, we have shared specs that are re-used in other specs. The use is a
+bit tricky however, so let's go over it.
+
+Commonly, if a shared spec is only reused within its own module, the shared spec will live within a
+shared directory inside that module's directory. For example, the `core/hash/shared/key.rb` spec is
+only used by `Hash` specs, and so it lives inside `core/hash/shared/`.
+
+When a shared spec is used across multiple modules or classes, it lives within the `shared/` directory.
+An example of this is the `shared/file/socket.rb` which is used by `core/file/socket_spec.rb`,
+`core/filetest/socket_spec.rb`, and `core/file/state/socket_spec.rb` and so it lives in the root `shared/`.
+
+Defining a shared spec involves adding a `shared: true` option to the top-level `describe` block. This
+will signal not to run the specs directly by the runner. Shared specs have access to two instance
+variables from the implementor spec: `@method` and `@object`, which the implementor spec will pass in.
+
+Here's an example of a snippet of a shared spec and two specs which integrates it:
+
+``` ruby
+# core/hash/shared/key.rb
+describe :hash_key_p, shared: true do
+ it "returns true if the key's matching value was false" do
+ { xyz: false }.send(@method, :xyz).should == true
+ end
+end
+
+# core/hash/key_spec.rb
+describe "Hash#key?" do
+ it_behaves_like :hash_key_p, :key?
+end
+
+# core/hash/include_spec.rb
+describe "Hash#include?" do
+ it_behaves_like :hash_key_p, :include?
+end
+```
+
+In the example, the first `describe` defines the shared spec `:hash_key_p`, which defines a spec that
+calls the `@method` method with an expectation. In the implementor spec, we use `it_behaves_like` to
+integrate the shared spec. `it_behaves_like` takes 3 parameters: the key of the shared spec, a method,
+and an object. These last two parameters are accessible via `@method` and `@object` in the shared spec.
+
+Sometimes, shared specs require more context from the implementor class than a simple object. We can address
+this by passing a lambda as the method, which will have the scope of the implementor. Here's an example of
+how this is used currently:
+
+``` ruby
+describe :kernel_sprintf, shared: true do
+ it "raises TypeError exception if cannot convert to Integer" do
+ -> { @method.call("%b", Object.new) }.should raise_error(TypeError)
+ end
+end
+
+describe "Kernel#sprintf" do
+ it_behaves_like :kernel_sprintf, -> (format, *args) {
+ sprintf(format, *args)
+ }
+end
+
+describe "Kernel.sprintf" do
+ it_behaves_like :kernel_sprintf, -> (format, *args) {
+ Kernel.sprintf(format, *args)
+ }
+end
+```
+
+In the above example, the method being passed is a lambda that triggers the specific conditions of the shared spec.
+
### Style
-Do not leave any trailing space and respect the existing style.
+Do not leave any trailing space and follow the existing style.
diff --git a/spec/ruby/core/array/append_spec.rb b/spec/ruby/core/array/append_spec.rb
index 5131e71b3c..ff47b5d9a8 100644
--- a/spec/ruby/core/array/append_spec.rb
+++ b/spec/ruby/core/array/append_spec.rb
@@ -37,6 +37,6 @@ end
ruby_version_is "2.5" do
describe "Array#append" do
- it_behaves_like(:array_push, :append)
+ it_behaves_like :array_push, :append
end
end
diff --git a/spec/ruby/core/array/collect_spec.rb b/spec/ruby/core/array/collect_spec.rb
index 1c2c28c6bd..2b0814d307 100644
--- a/spec/ruby/core/array/collect_spec.rb
+++ b/spec/ruby/core/array/collect_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Array#collect" do
- it_behaves_like(:array_collect, :collect)
+ it_behaves_like :array_collect, :collect
end
describe "Array#collect!" do
- it_behaves_like(:array_collect_b, :collect!)
+ it_behaves_like :array_collect_b, :collect!
end
diff --git a/spec/ruby/core/array/element_reference_spec.rb b/spec/ruby/core/array/element_reference_spec.rb
index 55b6b73d1e..5d6f4cca36 100644
--- a/spec/ruby/core/array/element_reference_spec.rb
+++ b/spec/ruby/core/array/element_reference_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/slice', __FILE__)
describe "Array#[]" do
- it_behaves_like(:array_slice, :[])
+ it_behaves_like :array_slice, :[]
end
describe "Array.[]" do
diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb
index 9c6a1d05a8..28f3aa5eee 100644
--- a/spec/ruby/core/array/element_set_spec.rb
+++ b/spec/ruby/core/array/element_set_spec.rb
@@ -350,11 +350,13 @@ describe "Array#[]= with [m..n]" do
it "returns non-array value if non-array value assigned" do
a = [1, 2, 3, 4, 5]
(a[2..4] = 10).should == 10
+ (a.[]=(2..4, 10)).should == 10
end
it "returns array if array assigned" do
a = [1, 2, 3, 4, 5]
(a[2..4] = [7, 8]).should == [7, 8]
+ (a.[]=(2..4, [7, 8])).should == [7, 8]
end
it "just sets the section defined by range to nil even if the rhs is nil" do
@@ -394,15 +396,32 @@ describe "Array#[]= with [m..n]" do
a.should == [1, 2, 3, 8, 4, 5]
end
- it "accepts Range subclasses" do
- a = [1, 2, 3, 4]
- range_incl = ArraySpecs::MyRange.new(1, 2)
- range_excl = ArraySpecs::MyRange.new(-3, -1, true)
+ describe "Range subclasses" do
+ before :each do
+ @range_incl = ArraySpecs::MyRange.new(1, 2)
+ @range_excl = ArraySpecs::MyRange.new(-3, -1, true)
+ end
+
+ it "accepts Range subclasses" do
+ a = [1, 2, 3, 4]
+
+ a[@range_incl] = ["a", "b"]
+ a.should == [1, "a", "b", 4]
+ a[@range_excl] = ["A", "B"]
+ a.should == [1, "A", "B", 4]
+ end
+
+ it "returns non-array value if non-array value assigned" do
+ a = [1, 2, 3, 4, 5]
+ (a[@range_incl] = 10).should == 10
+ (a.[]=(@range_incl, 10)).should == 10
+ end
- a[range_incl] = ["a", "b"]
- a.should == [1, "a", "b", 4]
- a[range_excl] = ["A", "B"]
- a.should == [1, "A", "B", 4]
+ it "returns array if array assigned" do
+ a = [1, 2, 3, 4, 5]
+ (a[@range_incl] = [7, 8]).should == [7, 8]
+ a.[]=(@range_incl, [7, 8]).should == [7, 8]
+ end
end
end
diff --git a/spec/ruby/core/array/index_spec.rb b/spec/ruby/core/array/index_spec.rb
index 55ed7b2a94..69c23b1a08 100644
--- a/spec/ruby/core/array/index_spec.rb
+++ b/spec/ruby/core/array/index_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/index', __FILE__)
describe "Array#index" do
- it_behaves_like(:array_index, :index)
+ it_behaves_like :array_index, :index
end
diff --git a/spec/ruby/core/array/length_spec.rb b/spec/ruby/core/array/length_spec.rb
index 6f4469dda5..ad795e5ff7 100644
--- a/spec/ruby/core/array/length_spec.rb
+++ b/spec/ruby/core/array/length_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "Array#length" do
- it_behaves_like(:array_length, :length)
+ it_behaves_like :array_length, :length
end
diff --git a/spec/ruby/core/array/map_spec.rb b/spec/ruby/core/array/map_spec.rb
index c23bb4241a..bcfd8d639d 100644
--- a/spec/ruby/core/array/map_spec.rb
+++ b/spec/ruby/core/array/map_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Array#map" do
- it_behaves_like(:array_collect, :map)
+ it_behaves_like :array_collect, :map
end
describe "Array#map!" do
- it_behaves_like(:array_collect_b, :map!)
+ it_behaves_like :array_collect_b, :map!
end
diff --git a/spec/ruby/core/array/prepend_spec.rb b/spec/ruby/core/array/prepend_spec.rb
index d8c6bad1a8..d859a698c5 100644
--- a/spec/ruby/core/array/prepend_spec.rb
+++ b/spec/ruby/core/array/prepend_spec.rb
@@ -4,6 +4,6 @@ require File.expand_path('../shared/unshift', __FILE__)
ruby_version_is "2.5" do
describe "Array#prepend" do
- it_behaves_like(:array_unshift, :prepend)
+ it_behaves_like :array_unshift, :prepend
end
end
diff --git a/spec/ruby/core/array/push_spec.rb b/spec/ruby/core/array/push_spec.rb
index 0207474579..67f90aff81 100644
--- a/spec/ruby/core/array/push_spec.rb
+++ b/spec/ruby/core/array/push_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/push', __FILE__)
describe "Array#push" do
- it_behaves_like(:array_push, :push)
+ it_behaves_like :array_push, :push
end
diff --git a/spec/ruby/core/array/replace_spec.rb b/spec/ruby/core/array/replace_spec.rb
index e8b0d53e04..92f84cba50 100644
--- a/spec/ruby/core/array/replace_spec.rb
+++ b/spec/ruby/core/array/replace_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/replace', __FILE__)
describe "Array#replace" do
- it_behaves_like(:array_replace, :replace)
+ it_behaves_like :array_replace, :replace
end
diff --git a/spec/ruby/core/array/size_spec.rb b/spec/ruby/core/array/size_spec.rb
index 2c8a18ade6..6ac5ebf41b 100644
--- a/spec/ruby/core/array/size_spec.rb
+++ b/spec/ruby/core/array/size_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "Array#size" do
- it_behaves_like(:array_length, :size)
+ it_behaves_like :array_length, :size
end
diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb
index 31d2983aef..fd31c6e323 100644
--- a/spec/ruby/core/array/slice_spec.rb
+++ b/spec/ruby/core/array/slice_spec.rb
@@ -156,5 +156,5 @@ describe "Array#slice!" do
end
describe "Array#slice" do
- it_behaves_like(:array_slice, :slice)
+ it_behaves_like :array_slice, :slice
end
diff --git a/spec/ruby/core/array/unshift_spec.rb b/spec/ruby/core/array/unshift_spec.rb
index eb224acfe8..e2203eeeb1 100644
--- a/spec/ruby/core/array/unshift_spec.rb
+++ b/spec/ruby/core/array/unshift_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/unshift', __FILE__)
describe "Array#unshift" do
- it_behaves_like(:array_unshift, :unshift)
+ it_behaves_like :array_unshift, :unshift
end
diff --git a/spec/ruby/core/basicobject/__send___spec.rb b/spec/ruby/core/basicobject/__send___spec.rb
index f25339fac7..26543ba5d5 100644
--- a/spec/ruby/core/basicobject/__send___spec.rb
+++ b/spec/ruby/core/basicobject/__send___spec.rb
@@ -6,5 +6,5 @@ describe "BasicObject#__send__" do
BasicObject.should have_public_instance_method(:__send__)
end
- it_behaves_like(:basicobject_send, :__send__)
+ it_behaves_like :basicobject_send, :__send__
end
diff --git a/spec/ruby/core/bignum/bignum_spec.rb b/spec/ruby/core/bignum/bignum_spec.rb
deleted file mode 100644
index 3df43aec2d..0000000000
--- a/spec/ruby/core/bignum/bignum_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum" do
- it "includes Comparable" do
- Bignum.include?(Comparable).should == true
- end
-
- it ".allocate raises a TypeError" do
- lambda do
- Bignum.allocate
- end.should raise_error(TypeError)
- end
-
- it ".new is undefined" do
- lambda do
- Bignum.new
- end.should raise_error(NoMethodError)
- end
-
- ruby_version_is '2.4' do
- it "unified into Integer" do
- Bignum.should equal(Integer)
- end
-
- it "is deprecated" do
- -> {
- Bignum
- }.should complain(/constant ::Bignum is deprecated/)
- end
- end
-end
diff --git a/spec/ruby/core/bignum/bit_and_spec.rb b/spec/ruby/core/bignum/bit_and_spec.rb
deleted file mode 100644
index 4bc5c11e1b..0000000000
--- a/spec/ruby/core/bignum/bit_and_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#&" do
- before :each do
- @bignum = bignum_value(5)
- end
-
- it "returns self bitwise AND other" do
- @bignum = bignum_value(5)
- (@bignum & 3).should == 1
- (@bignum & 52).should == 4
- (@bignum & bignum_value(9921)).should == 9223372036854775809
-
- ((2*bignum_value) & 1).should == 0
- ((2*bignum_value) & (2*bignum_value)).should == 18446744073709551616
- end
-
- it "returns self bitwise AND other when one operand is negative" do
- ((2*bignum_value) & -1).should == (2*bignum_value)
- ((4*bignum_value) & -1).should == (4*bignum_value)
- (@bignum & -0xffffffffffffff5).should == 9223372036854775809
- (@bignum & -@bignum).should == 1
- (@bignum & -0x8000000000000000).should == 9223372036854775808
- end
-
- it "returns self bitwise AND other when both operands are negative" do
- (-@bignum & -0x4000000000000005).should == -13835058055282163717
- (-@bignum & -@bignum).should == -9223372036854775813
- (-@bignum & -0x4000000000000000).should == -13835058055282163712
- end
-
- it "returns self bitwise AND other when both are negative and a multiple in bitsize of Fixnum::MIN" do
- val = - ((1 << 93) - 1)
- (val & val).should == val
-
- val = - ((1 << 126) - 1)
- (val & val).should == val
- end
-
- it "raises a TypeError when passed a Float" do
- lambda { (@bignum & 3.4) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("bignum bit and")
- obj.should_not_receive(:to_int)
-
- lambda { @bignum & obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/bit_length_spec.rb b/spec/ruby/core/bignum/bit_length_spec.rb
deleted file mode 100644
index 1c4c518345..0000000000
--- a/spec/ruby/core/bignum/bit_length_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#bit_length" do
- it "returns the position of the leftmost bit of a positive number" do
- (2**1000-1).bit_length.should == 1000
- (2**1000).bit_length.should == 1001
- (2**1000+1).bit_length.should == 1001
-
- (2**10000-1).bit_length.should == 10000
- (2**10000).bit_length.should == 10001
- (2**10000+1).bit_length.should == 10001
-
- (1 << 100).bit_length.should == 101
- (1 << 100).succ.bit_length.should == 101
- (1 << 100).pred.bit_length.should == 100
- (1 << 10000).bit_length.should == 10001
- end
-
- it "returns the position of the leftmost 0 bit of a negative number" do
- (-2**10000-1).bit_length.should == 10001
- (-2**10000).bit_length.should == 10000
- (-2**10000+1).bit_length.should == 10000
-
- (-2**1000-1).bit_length.should == 1001
- (-2**1000).bit_length.should == 1000
- (-2**1000+1).bit_length.should == 1000
-
- ((-1 << 100)-1).bit_length.should == 101
- ((-1 << 100)-1).succ.bit_length.should == 100
- ((-1 << 100)-1).pred.bit_length.should == 101
- ((-1 << 10000)-1).bit_length.should == 10001
- end
-end
diff --git a/spec/ruby/core/bignum/bit_or_spec.rb b/spec/ruby/core/bignum/bit_or_spec.rb
deleted file mode 100644
index 6bcb6ead6b..0000000000
--- a/spec/ruby/core/bignum/bit_or_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#|" do
- before :each do
- @bignum = bignum_value(11)
- end
-
- it "returns self bitwise OR other" do
- (@bignum | 2).should == 9223372036854775819
- (@bignum | 9).should == 9223372036854775819
- (@bignum | bignum_value).should == 9223372036854775819
- end
-
- it "returns self bitwise OR other when one operand is negative" do
- (@bignum | -0x40000000000000000).should == -64563604257983430645
- (@bignum | -@bignum).should == -1
- (@bignum | -0x8000000000000000).should == -9223372036854775797
- end
-
- it "returns self bitwise OR other when both operands are negative" do
- (-@bignum | -0x4000000000000005).should == -1
- (-@bignum | -@bignum).should == -9223372036854775819
- (-@bignum | -0x4000000000000000).should == -11
- end
-
- it "raises a TypeError when passed a Float" do
- not_supported_on :opal do
- lambda {
- bignum_value | bignum_value(0xffff).to_f
- }.should raise_error(TypeError)
- end
- lambda { @bignum | 9.9 }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("bignum bit or")
- obj.should_not_receive(:to_int)
-
- lambda { @bignum | obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/bit_xor_spec.rb b/spec/ruby/core/bignum/bit_xor_spec.rb
deleted file mode 100644
index ef4b4e6ae3..0000000000
--- a/spec/ruby/core/bignum/bit_xor_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#^" do
- before :each do
- @bignum = bignum_value(18)
- end
-
- it "returns self bitwise EXCLUSIVE OR other" do
- (@bignum ^ 2).should == 9223372036854775824
- (@bignum ^ @bignum).should == 0
- (@bignum ^ 14).should == 9223372036854775836
- end
-
- it "returns self bitwise EXCLUSIVE OR other when one operand is negative" do
- (@bignum ^ -0x40000000000000000).should == -64563604257983430638
- (@bignum ^ -@bignum).should == -4
- (@bignum ^ -0x8000000000000000).should == -18446744073709551598
- end
-
- it "returns self bitwise EXCLUSIVE OR other when both operands are negative" do
- (-@bignum ^ -0x40000000000000000).should == 64563604257983430638
- (-@bignum ^ -@bignum).should == 0
- (-@bignum ^ -0x4000000000000000).should == 13835058055282163694
- end
-
- it "returns self bitwise EXCLUSIVE OR other when all bits are 1 and other value is negative" do
- (9903520314283042199192993791 ^ -1).should == -9903520314283042199192993792
- (784637716923335095479473677900958302012794430558004314111 ^ -1).should ==
- -784637716923335095479473677900958302012794430558004314112
- end
-
- it "raises a TypeError when passed a Float" do
- not_supported_on :opal do
- lambda {
- bignum_value ^ bignum_value(0xffff).to_f
- }.should raise_error(TypeError)
- end
- lambda { @bignum ^ 14.5 }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("bignum bit xor")
- obj.should_not_receive(:to_int)
-
- lambda { @bignum ^ obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/case_compare_spec.rb b/spec/ruby/core/bignum/case_compare_spec.rb
deleted file mode 100644
index d7e0a89487..0000000000
--- a/spec/ruby/core/bignum/case_compare_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
-
-describe "Bignum#===" do
- it_behaves_like :bignum_equal, :===
-end
diff --git a/spec/ruby/core/bignum/coerce_spec.rb b/spec/ruby/core/bignum/coerce_spec.rb
deleted file mode 100644
index 40decaf51a..0000000000
--- a/spec/ruby/core/bignum/coerce_spec.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#coerce" do
- it "coerces other to a Bignum and returns [other, self] when passed a Fixnum" do
- a = bignum_value
- ary = a.coerce(2)
-
- ary[0].should be_kind_of(Bignum)
- ary[1].should be_kind_of(Bignum)
- ary.should == [2, a]
- end
-
- it "returns [other, self] when passed a Bignum" do
- a = bignum_value
- b = bignum_value
- ary = a.coerce(b)
-
- ary[0].should be_kind_of(Bignum)
- ary[1].should be_kind_of(Bignum)
- ary.should == [b, a]
- end
-
- it "raises a TypeError when not passed a Fixnum or Bignum" do
- a = bignum_value
-
- lambda { a.coerce(nil) }.should raise_error(TypeError)
- lambda { a.coerce(mock('str')) }.should raise_error(TypeError)
- lambda { a.coerce(1..4) }.should raise_error(TypeError)
- lambda { a.coerce(:test) }.should raise_error(TypeError)
- end
-
- ruby_version_is ""..."2.4" do
- it "raises a TypeError when passed a String" do
- a = bignum_value
- lambda { a.coerce("123") }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a Float" do
- a = bignum_value
- lambda { a.coerce(12.3) }.should raise_error(TypeError)
- end
- end
-
- ruby_version_is "2.4" do
- it "coerces both values to Floats and returns [other, self] when passed a Float" do
- a = bignum_value
- a.coerce(1.2).should == [1.2, a.to_f]
- end
-
- it "coerces both values to Floats and returns [other, self] when passed a String" do
- a = bignum_value
- a.coerce("123").should == [123.0, a.to_f]
- end
-
- it "calls #to_f to coerce other to a Float" do
- b = mock("bignum value")
- b.should_receive(:to_f).and_return(1.2)
-
- a = bignum_value
- ary = a.coerce(b)
-
- ary.should == [1.2, a.to_f]
- end
- end
-end
diff --git a/spec/ruby/core/bignum/comparison_spec.rb b/spec/ruby/core/bignum/comparison_spec.rb
deleted file mode 100644
index 435cc9aea2..0000000000
--- a/spec/ruby/core/bignum/comparison_spec.rb
+++ /dev/null
@@ -1,162 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#<=>" do
- describe "with a Fixnum" do
- it "returns -1 when other is larger" do
- (-bignum_value <=> 2).should == -1
- end
-
- it "returns 1 when other is smaller" do
- (bignum_value <=> 2).should == 1
- end
- end
-
- describe "with a Bignum" do
- describe "when other is negative" do
- it "returns -1 when self is negative and other is larger" do
- (-bignum_value(42) <=> -bignum_value).should == -1
- end
-
- it "returns 0 when other is equal" do
- (-bignum_value <=> -bignum_value).should == 0
- end
-
- it "returns 1 when self is negative and other is smaller" do
- (-bignum_value <=> -bignum_value(94)).should == 1
- end
-
- it "returns 1 when self is positive" do
- (bignum_value <=> -bignum_value).should == 1
- end
- end
-
- describe "when other is positive" do
- it "returns -1 when self is negative" do
- (-bignum_value <=> bignum_value).should == -1
- end
-
- it "returns -1 when self is positive and other is larger" do
- (bignum_value <=> bignum_value(38)).should == -1
- end
-
- it "returns 0 when other is equal" do
- (bignum_value <=> bignum_value).should == 0
- end
-
- it "returns 1 when other is smaller" do
- (bignum_value(56) <=> bignum_value).should == 1
- end
- end
- end
-
- describe "with a Float" do
- describe "when other is negative" do
- it "returns -1 when self is negative and other is larger" do
- (-bignum_value(0xffff) <=> -bignum_value.to_f).should == -1
- end
-
- it "returns 0 when other is equal" do
- (-bignum_value <=> -bignum_value.to_f).should == 0
- end
-
- it "returns 1 when self is negative and other is smaller" do
- (-bignum_value <=> -bignum_value(0xffef).to_f).should == 1
- end
-
- it "returns 1 when self is positive" do
- (bignum_value <=> -bignum_value.to_f).should == 1
- end
- end
-
- describe "when other is positive" do
- it "returns -1 when self is negative" do
- (-bignum_value <=> bignum_value.to_f).should == -1
- end
-
- it "returns -1 when self is positive and other is larger" do
- (bignum_value <=> bignum_value(0xfffe).to_f).should == -1
- end
-
- it "returns 0 when other is equal" do
- (bignum_value <=> bignum_value.to_f).should == 0
- end
-
- it "returns 1 when other is smaller" do
- (bignum_value(0xfeff) <=> bignum_value.to_f).should == 1
- end
- end
- end
-
- describe "with an Object" do
- before :each do
- @big = bignum_value
- @num = mock("value for Bignum#<=>")
- end
-
- it "calls #coerce on other" do
- @num.should_receive(:coerce).with(@big).and_return([@big.to_f, 2.5])
- @big <=> @num
- end
-
- ruby_version_is ""..."2.5" do
- it "returns nil if #coerce raises an exception" do
- @num.should_receive(:coerce).with(@big).and_raise(RuntimeError)
- lambda {
- @result = (@big <=> @num)
- }.should complain(/Numerical comparison operators will no more rescue exceptions/)
- @result.should be_nil
- end
- end
-
- ruby_version_is "2.5" do
- it "lets the exception go through if #coerce raises an exception" do
- @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error"))
- lambda {
- @big <=> @num
- }.should raise_error(RuntimeError, "my error")
- end
- end
-
- it "raises an exception if #coerce raises a non-StandardError exception" do
- @num.should_receive(:coerce).with(@big).and_raise(Exception)
- lambda { @big <=> @num }.should raise_error(Exception)
- end
-
- it "returns nil if #coerce does not return an Array" do
- @num.should_receive(:coerce).with(@big).and_return(nil)
- (@big <=> @num).should be_nil
- end
-
- it "returns -1 if the coerced value is larger" do
- @num.should_receive(:coerce).with(@big).and_return([@big, bignum_value(10)])
- (@big <=> @num).should == -1
- end
-
- it "returns 0 if the coerced value is equal" do
- @num.should_receive(:coerce).with(@big).and_return([@big, bignum_value])
- (@big <=> @num).should == 0
- end
-
- it "returns 1 if the coerced value is smaller" do
- @num.should_receive(:coerce).with(@big).and_return([@big, 22])
- (@big <=> @num).should == 1
- end
- end
-
- # The tests below are taken from matz's revision 23730 for Ruby trunk
- it "returns 1 when self is Infinity and other is a Bignum" do
- (infinity_value <=> Float::MAX.to_i*2).should == 1
- end
-
- it "returns -1 when self is negative and other is Infinty" do
- (-Float::MAX.to_i*2 <=> infinity_value).should == -1
- end
-
- it "returns 1 when self is negative and other is -Infinity" do
- (-Float::MAX.to_i*2 <=> -infinity_value).should == 1
- end
-
- it "returns -1 when self is -Infinity and other is negative" do
- (-infinity_value <=> -Float::MAX.to_i*2).should == -1
- end
-end
diff --git a/spec/ruby/core/bignum/complement_spec.rb b/spec/ruby/core/bignum/complement_spec.rb
deleted file mode 100644
index be6bc21b19..0000000000
--- a/spec/ruby/core/bignum/complement_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#~" do
- it "returns self with each bit flipped" do
- (~bignum_value(48)).should == -9223372036854775857
- (~(-bignum_value(21))).should == 9223372036854775828
- (~bignum_value(1)).should == -9223372036854775810
- end
-end
diff --git a/spec/ruby/core/bignum/div_spec.rb b/spec/ruby/core/bignum/div_spec.rb
deleted file mode 100644
index 6c165289e8..0000000000
--- a/spec/ruby/core/bignum/div_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/divide', __FILE__)
-
-describe "Bignum#div" do
- it_behaves_like(:bignum_divide, :div)
-
- it "returns a result of integer division of self by a float argument" do
- bignum_value(88).div(4294967295.5).should eql(2147483648)
- not_supported_on :opal do
- bignum_value(88).div(4294967295.0).should eql(2147483648)
- bignum_value(88).div(bignum_value(88).to_f).should eql(1)
- bignum_value(88).div(-bignum_value(88).to_f).should eql(-1)
- end
- end
-
- # #5490
- it "raises ZeroDivisionError if the argument is Float zero" do
- lambda { bignum_value(88).div(0.0) }.should raise_error(ZeroDivisionError)
- lambda { bignum_value(88).div(-0.0) }.should raise_error(ZeroDivisionError)
- end
-end
diff --git a/spec/ruby/core/bignum/divide_spec.rb b/spec/ruby/core/bignum/divide_spec.rb
deleted file mode 100644
index b81938b707..0000000000
--- a/spec/ruby/core/bignum/divide_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/divide', __FILE__)
-
-describe "Bignum#/" do
- it_behaves_like(:bignum_divide, :/)
-
- it "returns self divided by float" do
- not_supported_on :opal do
- (bignum_value(88) / 4294967295.0).should be_close(2147483648.5, TOLERANCE)
- end
- (bignum_value(88) / 4294967295.5).should be_close(2147483648.25, TOLERANCE)
- end
-
- it "does NOT raise ZeroDivisionError if other is zero and is a Float" do
- (bignum_value / 0.0).to_s.should == 'Infinity'
- (bignum_value / -0.0).to_s.should == '-Infinity'
- end
-end
diff --git a/spec/ruby/core/bignum/divmod_spec.rb b/spec/ruby/core/bignum/divmod_spec.rb
deleted file mode 100644
index 656f23482b..0000000000
--- a/spec/ruby/core/bignum/divmod_spec.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#divmod" do
- before :each do
- @bignum = bignum_value(55)
- end
-
- # Based on MRI's test/test_integer.rb (test_divmod),
- # MRI maintains the following property:
- # if q, r = a.divmod(b) ==>
- # assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
- # So, r is always between 0 and b.
- it "returns an Array containing quotient and modulus obtained from dividing self by the given argument" do
- @bignum.divmod(4).should == [2305843009213693965, 3]
- @bignum.divmod(13).should == [709490156681136604, 11]
-
- @bignum.divmod(4.5).should == [2049638230412172288, 3.5]
-
- not_supported_on :opal do
- @bignum.divmod(4.0).should == [2305843009213693952, 0.0]
- @bignum.divmod(13.0).should == [709490156681136640, 8.0]
-
- @bignum.divmod(2.0).should == [4611686018427387904, 0.0]
- end
-
- @bignum.divmod(bignum_value).should == [1, 55]
-
- (-(10**50)).divmod(-(10**40 + 1)).should == [9999999999, -9999999999999999999999999999990000000001]
- (10**50).divmod(10**40 + 1).should == [9999999999, 9999999999999999999999999999990000000001]
-
- (-10**50).divmod(10**40 + 1).should == [-10000000000, 10000000000]
- (10**50).divmod(-(10**40 + 1)).should == [-10000000000, -10000000000]
- end
-
- describe "with q = floor(x/y), a = q*b + r," do
- it "returns [q,r] when a < 0, b > 0 and |a| < b" do
- a = -@bignum + 1
- b = @bignum
- a.divmod(b).should == [-1, 1]
- end
-
- it "returns [q,r] when a > 0, b < 0 and a > |b|" do
- b = -@bignum + 1
- a = @bignum
- a.divmod(b).should == [-2, -@bignum + 2]
- end
-
- it "returns [q,r] when a > 0, b < 0 and a < |b|" do
- a = @bignum - 1
- b = -@bignum
- a.divmod(b).should == [-1, -1]
- end
-
- it "returns [q,r] when a < 0, b < 0 and |a| < |b|" do
- a = -@bignum + 1
- b = -@bignum
- a.divmod(b).should == [0, -@bignum + 1]
- end
- end
-
- it "raises a ZeroDivisionError when the given argument is 0" do
- lambda { @bignum.divmod(0) }.should raise_error(ZeroDivisionError)
- lambda { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError)
- end
-
- # Behaviour established as correct in r23953
- it "raises a FloatDomainError if other is NaN" do
- lambda { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError)
- end
-
- it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
- lambda { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError)
- lambda { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when the given argument is not an Integer" do
- lambda { @bignum.divmod(mock('10')) }.should raise_error(TypeError)
- lambda { @bignum.divmod("10") }.should raise_error(TypeError)
- lambda { @bignum.divmod(:symbol) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/element_reference_spec.rb b/spec/ruby/core/bignum/element_reference_spec.rb
deleted file mode 100644
index e5ee9e15ac..0000000000
--- a/spec/ruby/core/bignum/element_reference_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#[]" do
- before :each do
- @bignum = bignum_value(4996)
- end
-
- it "returns the nth bit in the binary representation of self" do
- @bignum[2].should == 1
- @bignum[9.2].should == 1
- @bignum[21].should == 0
- @bignum[0xffffffff].should == 0
- @bignum[-0xffffffff].should == 0
- end
-
- it "tries to convert the given argument to an Integer using #to_int" do
- @bignum[1.3].should == @bignum[1]
-
- (obj = mock('2')).should_receive(:to_int).at_least(1).and_return(2)
- @bignum[obj].should == 1
- end
-
- it "raises a TypeError when the given argument can't be converted to Integer" do
- obj = mock('asdf')
- lambda { @bignum[obj] }.should raise_error(TypeError)
-
- obj.should_receive(:to_int).and_return("asdf")
- lambda { @bignum[obj] }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/eql_spec.rb b/spec/ruby/core/bignum/eql_spec.rb
deleted file mode 100644
index c9eff9ef08..0000000000
--- a/spec/ruby/core/bignum/eql_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#eql? when given a Bignum" do
- it "returns true if the given argument has the same value" do
- a = bignum_value(13)
- a.should eql(bignum_value(13))
- (-a).should eql(-bignum_value(13))
- end
-end
-
-describe "Bignum#eql? when given a non-Bignum" do
- it "returns false" do
- a = bignum_value(13)
- a.should_not eql(a.to_f)
-
- a.should_not eql(2)
- a.should_not eql(3.14)
- a.should_not eql(:symbol)
- a.should_not eql("String")
- a.should_not eql(mock('str'))
- end
-end
diff --git a/spec/ruby/core/bignum/equal_value_spec.rb b/spec/ruby/core/bignum/equal_value_spec.rb
deleted file mode 100644
index 0117d58683..0000000000
--- a/spec/ruby/core/bignum/equal_value_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
-
-describe "Bignum#==" do
- it_behaves_like :bignum_equal, :==
-end
diff --git a/spec/ruby/core/bignum/even_spec.rb b/spec/ruby/core/bignum/even_spec.rb
deleted file mode 100644
index a84ea80075..0000000000
--- a/spec/ruby/core/bignum/even_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#even?" do
- it "returns true if self is even and positive" do
- (10000**10).even?.should be_true
- end
-
- it "returns true if self is even and negative" do
- (-10000**10).even?.should be_true
- end
-
- it "returns false if self is odd and positive" do
- (9879**976).even?.should be_false
- end
-
- it "returns false if self is odd and negative" do
- (-9879**976).even?.should be_false
- end
-end
diff --git a/spec/ruby/core/bignum/exponent_spec.rb b/spec/ruby/core/bignum/exponent_spec.rb
deleted file mode 100644
index 9026c1ff3b..0000000000
--- a/spec/ruby/core/bignum/exponent_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#**" do
- before :each do
- @bignum = bignum_value(47)
- end
-
- it "returns self raised to other power" do
- (@bignum ** 4).should == 7237005577332262361485077344629993318496048279512298547155833600056910050625
- (@bignum ** 1.2).should be_close(57262152889751597425762.57804, TOLERANCE)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum ** mock('10') }.should raise_error(TypeError)
- lambda { @bignum ** "10" }.should raise_error(TypeError)
- lambda { @bignum ** :symbol }.should raise_error(TypeError)
- end
-
- it "switch to a Float when the values is too big" do
- flt = (@bignum ** @bignum)
- flt.should be_kind_of(Float)
- flt.infinite?.should == 1
- end
-
- it "returns a complex number when negative and raised to a fractional power" do
- ((-@bignum) ** (1.0/3)) .should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
- ((-@bignum) ** Rational(1,3)).should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
- end
-end
diff --git a/spec/ruby/core/bignum/fdiv_spec.rb b/spec/ruby/core/bignum/fdiv_spec.rb
deleted file mode 100644
index 35f3ede010..0000000000
--- a/spec/ruby/core/bignum/fdiv_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#fdiv" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/bignum/gt_spec.rb b/spec/ruby/core/bignum/gt_spec.rb
deleted file mode 100644
index 5c814eedd1..0000000000
--- a/spec/ruby/core/bignum/gt_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#>" do
- before :each do
- @bignum = bignum_value(732)
- end
-
- it "returns true if self is greater than the given argument" do
- (@bignum > (@bignum - 1)).should == true
- (@bignum > 14.6).should == true
- (@bignum > 10).should == true
-
- (@bignum > (@bignum + 500)).should == false
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { @bignum > "4" }.should raise_error(ArgumentError)
- lambda { @bignum > mock('str') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/bignum/gte_spec.rb b/spec/ruby/core/bignum/gte_spec.rb
deleted file mode 100644
index e32ce19e0f..0000000000
--- a/spec/ruby/core/bignum/gte_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#>=" do
- before :each do
- @bignum = bignum_value(14)
- end
-
- it "returns true if self is greater than or equal to other" do
- (@bignum >= @bignum).should == true
- (@bignum >= (@bignum + 2)).should == false
- (@bignum >= 5664.2).should == true
- (@bignum >= 4).should == true
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { @bignum >= "4" }.should raise_error(ArgumentError)
- lambda { @bignum >= mock('str') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/bignum/hash_spec.rb b/spec/ruby/core/bignum/hash_spec.rb
deleted file mode 100644
index bdc85c3fdc..0000000000
--- a/spec/ruby/core/bignum/hash_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#hash" do
- it "is provided" do
- bignum_value.respond_to?(:hash).should == true
- end
-
- it "is stable" do
- bignum_value.hash.should == bignum_value.hash
- bignum_value.hash.should_not == bignum_value(1).hash
- end
-end
diff --git a/spec/ruby/core/bignum/left_shift_spec.rb b/spec/ruby/core/bignum/left_shift_spec.rb
deleted file mode 100644
index 364f51b708..0000000000
--- a/spec/ruby/core/bignum/left_shift_spec.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#<< with n << m" do
- before :each do
- @bignum = bignum_value * 16
- end
-
- it "returns n shifted left m bits when n > 0, m > 0" do
- (@bignum << 4).should == 2361183241434822606848
- end
-
- it "returns n shifted left m bits when n < 0, m > 0" do
- (-@bignum << 9).should == -75557863725914323419136
- end
-
- it "returns n shifted right m bits when n > 0, m < 0" do
- (@bignum << -1).should == 73786976294838206464
- end
-
- it "returns n shifted right m bits when n < 0, m < 0" do
- (-@bignum << -2).should == -36893488147419103232
- end
-
- it "returns n when n > 0, m == 0" do
- (@bignum << 0).should == @bignum
- end
-
- it "returns n when n < 0, m == 0" do
- (-@bignum << 0).should == -@bignum
- end
-
- it "returns 0 when m < 0 and m == p where 2**p > n >= 2**(p-1)" do
- (@bignum << -68).should == 0
- end
-
- it "returns 0 when m < 0 and m is a Bignum" do
- (@bignum << -bignum_value).should == 0
- end
-
- it "returns a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
- result = (fixnum_max * 2) << -1
- result.should be_an_instance_of(Fixnum)
- result.should == fixnum_max
- end
-
- it "returns a Fixnum == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do
- result = (fixnum_min * 2) << -1
- result.should be_an_instance_of(Fixnum)
- result.should == fixnum_min
- end
-
- it "calls #to_int to convert the argument to an Integer" do
- obj = mock("4")
- obj.should_receive(:to_int).and_return(4)
-
- (@bignum << obj).should == 2361183241434822606848
- end
-
- it "raises a TypeError when #to_int does not return an Integer" do
- obj = mock("a string")
- obj.should_receive(:to_int).and_return("asdf")
-
- lambda { @bignum << obj }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed nil" do
- lambda { @bignum << nil }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a String" do
- lambda { @bignum << "4" }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/lt_spec.rb b/spec/ruby/core/bignum/lt_spec.rb
deleted file mode 100644
index 802c68a58b..0000000000
--- a/spec/ruby/core/bignum/lt_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#<" do
- before :each do
- @bignum = bignum_value(32)
- end
-
- it "returns true if self is less than the given argument" do
- (@bignum < @bignum + 1).should == true
- (-@bignum < -(@bignum - 1)).should == true
-
- (@bignum < 1).should == false
- (@bignum < 5).should == false
-
- (@bignum < 4.999).should == false
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { @bignum < "4" }.should raise_error(ArgumentError)
- lambda { @bignum < mock('str') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/bignum/lte_spec.rb b/spec/ruby/core/bignum/lte_spec.rb
deleted file mode 100644
index 9a1d22d3be..0000000000
--- a/spec/ruby/core/bignum/lte_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#<=" do
- before :each do
- @bignum = bignum_value(39)
- end
-
- it "returns true if self is less than or equal to other" do
- (@bignum <= @bignum).should == true
- (-@bignum <= -(@bignum - 1)).should == true
-
- (@bignum <= 4.999).should == false
- end
-
- it "returns false if compares with near float" do
- (@bignum <= (@bignum + 0.0)).should == false
- (@bignum <= (@bignum + 0.5)).should == false
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { @bignum <= "4" }.should raise_error(ArgumentError)
- lambda { @bignum <= mock('str') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/bignum/magnitude_spec.rb b/spec/ruby/core/bignum/magnitude_spec.rb
deleted file mode 100644
index 35b9ba6f1e..0000000000
--- a/spec/ruby/core/bignum/magnitude_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/abs', __FILE__)
-
-describe "Bignum#magnitude" do
- it_behaves_like(:bignum_abs, :magnitude)
-end
diff --git a/spec/ruby/core/bignum/minus_spec.rb b/spec/ruby/core/bignum/minus_spec.rb
deleted file mode 100644
index 754ef7fa42..0000000000
--- a/spec/ruby/core/bignum/minus_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#-" do
- before :each do
- @bignum = bignum_value(314)
- end
-
- it "returns self minus the given Integer" do
- (@bignum - 9).should == 9223372036854776113
- (@bignum - 12.57).should be_close(9223372036854776109.43, TOLERANCE)
- (@bignum - bignum_value(42)).should == 272
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum - mock('10') }.should raise_error(TypeError)
- lambda { @bignum - "10" }.should raise_error(TypeError)
- lambda { @bignum - :symbol }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/modulo_spec.rb b/spec/ruby/core/bignum/modulo_spec.rb
deleted file mode 100644
index eee1dc76a6..0000000000
--- a/spec/ruby/core/bignum/modulo_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/modulo', __FILE__)
-
-describe "Bignum#%" do
- it_behaves_like(:bignum_modulo, :%)
-end
-
-describe "Bignum#modulo" do
- it_behaves_like(:bignum_modulo, :modulo)
-end
diff --git a/spec/ruby/core/bignum/multiply_spec.rb b/spec/ruby/core/bignum/multiply_spec.rb
deleted file mode 100644
index 486e36ecbc..0000000000
--- a/spec/ruby/core/bignum/multiply_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#*" do
- before :each do
- @bignum = bignum_value(772)
- end
-
- it "returns self multiplied by the given Integer" do
- (@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
- (@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
- (@bignum * 10).should == 92233720368547765800
- (@bignum * (@bignum - 40)).should == 85070591730234629737795195287525433200
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum * mock('10') }.should raise_error(TypeError)
- lambda { @bignum * "10" }.should raise_error(TypeError)
- lambda { @bignum * :symbol }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/odd_spec.rb b/spec/ruby/core/bignum/odd_spec.rb
deleted file mode 100644
index 9d4c1191f6..0000000000
--- a/spec/ruby/core/bignum/odd_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#odd?" do
- it "returns true if self is odd and positive" do
- (987279**19).odd?.should be_true
- end
-
- it "returns true if self is odd and negative" do
- (-9873389**97).odd?.should be_true
- end
-
- it "returns false if self is even and positive" do
- (10000000**10).odd?.should be_false
- end
-
- it "returns false if self is even and negative" do
- (-1000000**100).odd?.should be_false
- end
-end
diff --git a/spec/ruby/core/bignum/plus_spec.rb b/spec/ruby/core/bignum/plus_spec.rb
deleted file mode 100644
index 411e226649..0000000000
--- a/spec/ruby/core/bignum/plus_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#+" do
- before :each do
- @bignum = bignum_value(76)
- end
-
- it "returns self plus the given Integer" do
- (@bignum + 4).should == 9223372036854775888
- (@bignum + 4.2).should be_close(9223372036854775888.2, TOLERANCE)
- (@bignum + bignum_value(3)).should == 18446744073709551695
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum + mock('10') }.should raise_error(TypeError)
- lambda { @bignum + "10" }.should raise_error(TypeError)
- lambda { @bignum + :symbol}.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/remainder_spec.rb b/spec/ruby/core/bignum/remainder_spec.rb
deleted file mode 100644
index 59f7eb4326..0000000000
--- a/spec/ruby/core/bignum/remainder_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#remainder" do
- it "returns the remainder of dividing self by other" do
- a = bignum_value(79)
- a.remainder(2).should == 1
- a.remainder(97.345).should be_close(46.5674996147722, TOLERANCE)
- a.remainder(bignum_value).should == 79
- end
-
- it "raises a ZeroDivisionError if other is zero and not a Float" do
- lambda { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError)
- end
-
- it "does raises ZeroDivisionError if other is zero and a Float" do
- a = bignum_value(7)
- b = bignum_value(32)
- lambda { a.remainder(0.0) }.should raise_error(ZeroDivisionError)
- lambda { b.remainder(-0.0) }.should raise_error(ZeroDivisionError)
- end
-end
diff --git a/spec/ruby/core/bignum/right_shift_spec.rb b/spec/ruby/core/bignum/right_shift_spec.rb
deleted file mode 100644
index d65f7c00a9..0000000000
--- a/spec/ruby/core/bignum/right_shift_spec.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#>> with n >> m" do
- before :each do
- @bignum = bignum_value * 16
- end
-
- it "returns n shifted right m bits when n > 0, m > 0" do
- (@bignum >> 1).should == 73786976294838206464
- end
-
- it "returns n shifted right m bits when n < 0, m > 0" do
- (-@bignum >> 2).should == -36893488147419103232
- end
-
- it "respects twos complement signed shifting" do
- # This explicit left hand value is important because it is the
- # exact bit pattern that matters, so it's important it's right
- # here to show the significance.
- #
-
- (-42949672980000000000000 >> 14).should == -2621440001220703125
- (-42949672980000000000001 >> 14).should == -2621440001220703126
- # Note the off by one -------------------- ^^^^^^^^^^^^^^^^^^^^
- # This is because even though we discard the lowest bit, in twos
- # complement it would influence the bits to the left of it.
-
- (-42949672980000000000000 >> 15).should == -1310720000610351563
- (-42949672980000000000001 >> 15).should == -1310720000610351563
-
- (-0xfffffffffffffffff >> 32).should == -68719476736
- end
-
- it "respects twos complement signed shifting for very large values" do
- giant = 42949672980000000000000000000000000000000000000000000000000000000000000000000000000000000000
- neg = -giant
-
- (giant >> 84).should == 2220446050284288846538547929770901490087453566957265138626098632812
- (neg >> 84).should == -2220446050284288846538547929770901490087453566957265138626098632813
- end
-
- it "returns n shifted left m bits when n > 0, m < 0" do
- (@bignum >> -2).should == 590295810358705651712
- end
-
- it "returns n shifted left m bits when n < 0, m < 0" do
- (-@bignum >> -3).should == -1180591620717411303424
- end
-
- it "returns n when n > 0, m == 0" do
- (@bignum >> 0).should == @bignum
- end
-
- it "returns n when n < 0, m == 0" do
- (-@bignum >> 0).should == -@bignum
- end
-
- it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
- (@bignum >> 68).should == 0
- end
-
- it "returns 0 when m is a Bignum" do
- (@bignum >> bignum_value).should == 0
- end
-
- it "returns a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
- result = (fixnum_max * 2) >> 1
- result.should be_an_instance_of(Fixnum)
- result.should == fixnum_max
- end
-
- it "returns a Fixnum == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do
- result = (fixnum_min * 2) >> 1
- result.should be_an_instance_of(Fixnum)
- result.should == fixnum_min
- end
-
- it "calls #to_int to convert the argument to an Integer" do
- obj = mock("2")
- obj.should_receive(:to_int).and_return(2)
-
- (@bignum >> obj).should == 36893488147419103232
- end
-
- it "raises a TypeError when #to_int does not return an Integer" do
- obj = mock("a string")
- obj.should_receive(:to_int).and_return("asdf")
-
- lambda { @bignum >> obj }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed nil" do
- lambda { @bignum >> nil }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a String" do
- lambda { @bignum >> "4" }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/shared/abs.rb b/spec/ruby/core/bignum/shared/abs.rb
deleted file mode 100644
index 35fd85060c..0000000000
--- a/spec/ruby/core/bignum/shared/abs.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :bignum_abs, shared: true do
- it "returns the absolute value" do
- bignum_value(39).send(@method).should == 9223372036854775847
- (-bignum_value(18)).send(@method).should == 9223372036854775826
- end
-end
diff --git a/spec/ruby/core/bignum/shared/divide.rb b/spec/ruby/core/bignum/shared/divide.rb
deleted file mode 100644
index cbde69bbb2..0000000000
--- a/spec/ruby/core/bignum/shared/divide.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-describe :bignum_divide, shared: true do
- before :each do
- @bignum = bignum_value(88)
- end
-
- it "returns self divided by other" do
- @bignum.send(@method, 4).should == 2305843009213693974
-
- @bignum.send(@method, bignum_value(2)).should be_close(1, TOLERANCE)
-
- (-(10**50)).send(@method, -(10**40 + 1)).should == 9999999999
- (10**50).send(@method, 10**40 + 1).should == 9999999999
-
- (-10**50).send(@method, 10**40 + 1).should == -10000000000
- (10**50).send(@method, -(10**40 + 1)).should == -10000000000
- end
-
- it "raises a ZeroDivisionError if other is zero and not a Float" do
- lambda { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
- lambda { @bignum.send(@method, "2") }.should raise_error(TypeError)
- lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/shared/equal.rb b/spec/ruby/core/bignum/shared/equal.rb
deleted file mode 100644
index ffe4daf4f1..0000000000
--- a/spec/ruby/core/bignum/shared/equal.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :bignum_equal, shared: true do
- before :each do
- @bignum = bignum_value
- end
-
- it "returns true if self has the same value as the given argument" do
- @bignum.send(@method, @bignum).should == true
- @bignum.send(@method, @bignum.to_f).should == true
-
- @bignum.send(@method, @bignum + 1).should == false
- (@bignum + 1).send(@method, @bignum).should == false
-
- @bignum.send(@method, 9).should == false
- @bignum.send(@method, 9.01).should == false
-
- @bignum.send(@method, bignum_value(10)).should == false
- end
-
- it "calls 'other == self' if the given argument is not an Integer" do
- obj = mock('not integer')
- obj.should_receive(:==).and_return(true)
- @bignum.send(@method, obj).should == true
- end
-
- it "returns the result of 'other == self' as a boolean" do
- obj = mock('not integer')
- obj.should_receive(:==).exactly(2).times.and_return("woot", nil)
- @bignum.send(@method, obj).should == true
- @bignum.send(@method, obj).should == false
- end
-end
diff --git a/spec/ruby/core/bignum/shared/modulo.rb b/spec/ruby/core/bignum/shared/modulo.rb
deleted file mode 100644
index 9814e22f3b..0000000000
--- a/spec/ruby/core/bignum/shared/modulo.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-describe :bignum_modulo, shared: true do
- before :each do
- @bignum = bignum_value
- end
-
- it "returns the modulus obtained from dividing self by the given argument" do
- @bignum.send(@method, 5).should == 3
- @bignum.send(@method, -5).should == -2
- @bignum.send(@method, -100).should == -92
- @bignum.send(@method, 2.22).should be_close(0.780180180180252, TOLERANCE)
- @bignum.send(@method, bignum_value(10)).should == 9223372036854775808
- end
-
- it "raises a ZeroDivisionError when the given argument is 0" do
- lambda { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
- lambda { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- lambda { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
- lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
- lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/bignum/size_spec.rb b/spec/ruby/core/bignum/size_spec.rb
deleted file mode 100644
index 8629cba972..0000000000
--- a/spec/ruby/core/bignum/size_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#size" do
- it "returns the number of bytes required to hold the unsigned bignum data" do
- # that is, n such that 256 * n <= val.abs < 256 * (n+1)
- (256**7).size.should == 8
- (256**8).size.should == 9
- (256**9).size.should == 10
- (256**10).size.should == 11
- (256**10-1).size.should == 10
- (256**11).size.should == 12
- (256**12).size.should == 13
- (256**20-1).size.should == 20
- (256**40-1).size.should == 40
- end
-end
diff --git a/spec/ruby/core/bignum/to_f_spec.rb b/spec/ruby/core/bignum/to_f_spec.rb
deleted file mode 100644
index 8d99045c95..0000000000
--- a/spec/ruby/core/bignum/to_f_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#to_f" do
- it "returns self converted to a Float" do
- bignum_value(0x4000_0aa0_0bb0_0000).to_f.should eql(13_835_069_737_789_292_544.00)
- bignum_value(0x8000_0000_0000_0ccc).to_f.should eql(18_446_744_073_709_555_712.00)
- (-bignum_value(99)).to_f.should eql(-9_223_372_036_854_775_808.00)
- end
-
- it "converts number close to Float::MAX without exceeding MAX or producing NaN" do
- (10**308).to_f.should == 10.0 ** 308
- end
-end
diff --git a/spec/ruby/core/bignum/to_s_spec.rb b/spec/ruby/core/bignum/to_s_spec.rb
deleted file mode 100644
index 524639adb6..0000000000
--- a/spec/ruby/core/bignum/to_s_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#to_s when given a base" do
- it "returns self converted to a String using the given base" do
- a = 2**64
- a.to_s(2).should == "10000000000000000000000000000000000000000000000000000000000000000"
- a.to_s(8).should == "2000000000000000000000"
- a.to_s(16).should == "10000000000000000"
- a.to_s(32).should == "g000000000000"
- end
-
- it "raises an ArgumentError if the base is less than 2 or higher than 36" do
- lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
- lambda { 123.to_s(0) }.should raise_error(ArgumentError)
- lambda { 123.to_s(1) }.should raise_error(ArgumentError)
- lambda { 123.to_s(37) }.should raise_error(ArgumentError)
- end
-end
-
-describe "Bignum#to_s when given no base" do
- it "returns self converted to a String using base 10" do
- bignum_value(9).to_s.should == "9223372036854775817"
- bignum_value.to_s.should == "9223372036854775808"
- (-bignum_value(675)).to_s.should == "-9223372036854776483"
- end
-end
-
-with_feature :encoding do
- describe "Bignum#to_s" do
- before :each do
- @internal = Encoding.default_internal
- end
-
- after :each do
- Encoding.default_internal = @internal
- end
-
- it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
- end
-
- it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
- Encoding.default_internal = Encoding::IBM437
- bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
- end
- end
-end
diff --git a/spec/ruby/core/bignum/uminus_spec.rb b/spec/ruby/core/bignum/uminus_spec.rb
deleted file mode 100644
index 7ec432ac71..0000000000
--- a/spec/ruby/core/bignum/uminus_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Bignum#-@" do
- it "returns self as a negative value" do
- bignum_value.send(:-@).should == -9223372036854775808
- (-bignum_value).send(:-@).should == 9223372036854775808
-
- bignum_value(921).send(:-@).should == -9223372036854776729
- (-bignum_value(921).send(:-@)).should == 9223372036854776729
- end
-end
diff --git a/spec/ruby/core/binding/clone_spec.rb b/spec/ruby/core/binding/clone_spec.rb
index d607ae2a9e..5bdfdaf78d 100644
--- a/spec/ruby/core/binding/clone_spec.rb
+++ b/spec/ruby/core/binding/clone_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/clone', __FILE__)
describe "Binding#clone" do
- it_behaves_like(:binding_clone, :clone)
+ it_behaves_like :binding_clone, :clone
end
diff --git a/spec/ruby/core/binding/dup_spec.rb b/spec/ruby/core/binding/dup_spec.rb
index 7f242626d7..890821b633 100644
--- a/spec/ruby/core/binding/dup_spec.rb
+++ b/spec/ruby/core/binding/dup_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/clone', __FILE__)
describe "Binding#dup" do
- it_behaves_like(:binding_clone, :dup)
+ it_behaves_like :binding_clone, :dup
end
diff --git a/spec/ruby/core/complex/abs2_spec.rb b/spec/ruby/core/complex/abs2_spec.rb
index debfade075..f2145dcb61 100644
--- a/spec/ruby/core/complex/abs2_spec.rb
+++ b/spec/ruby/core/complex/abs2_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/abs2', __FILE__)
describe "Complex#abs2" do
- it_behaves_like(:complex_abs2, :abs2)
+ it_behaves_like :complex_abs2, :abs2
end
diff --git a/spec/ruby/core/complex/abs_spec.rb b/spec/ruby/core/complex/abs_spec.rb
index a00d161ee9..9252c22263 100644
--- a/spec/ruby/core/complex/abs_spec.rb
+++ b/spec/ruby/core/complex/abs_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/abs', __FILE__)
describe "Complex#abs" do
- it_behaves_like(:complex_abs, :abs)
+ it_behaves_like :complex_abs, :abs
end
diff --git a/spec/ruby/core/complex/angle_spec.rb b/spec/ruby/core/complex/angle_spec.rb
index f0c46bfd03..d5f80fe529 100644
--- a/spec/ruby/core/complex/angle_spec.rb
+++ b/spec/ruby/core/complex/angle_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/arg', __FILE__)
describe "Complex#angle" do
- it_behaves_like(:complex_arg, :angle)
+ it_behaves_like :complex_arg, :angle
end
diff --git a/spec/ruby/core/complex/arg_spec.rb b/spec/ruby/core/complex/arg_spec.rb
index 48f8a94cf5..92f5d79ba8 100644
--- a/spec/ruby/core/complex/arg_spec.rb
+++ b/spec/ruby/core/complex/arg_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/arg', __FILE__)
describe "Complex#arg" do
- it_behaves_like(:complex_arg, :arg)
+ it_behaves_like :complex_arg, :arg
end
diff --git a/spec/ruby/core/complex/coerce_spec.rb b/spec/ruby/core/complex/coerce_spec.rb
index 7c01170fde..308da64356 100644
--- a/spec/ruby/core/complex/coerce_spec.rb
+++ b/spec/ruby/core/complex/coerce_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/coerce', __FILE__)
describe "Complex#coerce" do
- it_behaves_like(:complex_coerce, :coerce)
+ it_behaves_like :complex_coerce, :coerce
end
diff --git a/spec/ruby/core/complex/conj_spec.rb b/spec/ruby/core/complex/conj_spec.rb
index ad2c885b3b..fec4516755 100644
--- a/spec/ruby/core/complex/conj_spec.rb
+++ b/spec/ruby/core/complex/conj_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/conjugate', __FILE__)
describe "Complex#conj" do
- it_behaves_like(:complex_conjugate, :conj)
+ it_behaves_like :complex_conjugate, :conj
end
diff --git a/spec/ruby/core/complex/conjugate_spec.rb b/spec/ruby/core/complex/conjugate_spec.rb
index 7fc2ddb430..e5a01bfe45 100644
--- a/spec/ruby/core/complex/conjugate_spec.rb
+++ b/spec/ruby/core/complex/conjugate_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/conjugate', __FILE__)
describe "Complex#conjugate" do
- it_behaves_like(:complex_conjugate, :conjugate)
+ it_behaves_like :complex_conjugate, :conjugate
end
diff --git a/spec/ruby/core/complex/denominator_spec.rb b/spec/ruby/core/complex/denominator_spec.rb
index 2568967968..7b541910ec 100644
--- a/spec/ruby/core/complex/denominator_spec.rb
+++ b/spec/ruby/core/complex/denominator_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/denominator', __FILE__)
describe "Complex#denominator" do
- it_behaves_like(:complex_denominator, :denominator)
+ it_behaves_like :complex_denominator, :denominator
end
diff --git a/spec/ruby/core/complex/hash_spec.rb b/spec/ruby/core/complex/hash_spec.rb
index db4b3590df..8cdee8b6ab 100644
--- a/spec/ruby/core/complex/hash_spec.rb
+++ b/spec/ruby/core/complex/hash_spec.rb
@@ -1,6 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/hash', __FILE__)
describe "Complex#hash" do
- it_behaves_like(:complex_hash, :hash)
+ it "is static" do
+ Complex(1).hash.should == Complex(1).hash
+ Complex(1, 0).hash.should == Complex(1).hash
+ Complex(1, 1).hash.should == Complex(1, 1).hash
+ end
+
+ it "is different for different instances" do
+ Complex(1, 2).hash.should_not == Complex(1, 1).hash
+ Complex(2, 1).hash.should_not == Complex(1, 1).hash
+
+ Complex(1, 2).hash.should_not == Complex(2, 1).hash
+ end
end
diff --git a/spec/ruby/core/complex/imag_spec.rb b/spec/ruby/core/complex/imag_spec.rb
index 6aa8803f5d..aa2e24a0d0 100644
--- a/spec/ruby/core/complex/imag_spec.rb
+++ b/spec/ruby/core/complex/imag_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/image', __FILE__)
describe "Complex#imag" do
- it_behaves_like(:complex_image, :imag)
+ it_behaves_like :complex_image, :imag
end
diff --git a/spec/ruby/core/complex/inspect_spec.rb b/spec/ruby/core/complex/inspect_spec.rb
index b766e7f730..96be2ddb6f 100644
--- a/spec/ruby/core/complex/inspect_spec.rb
+++ b/spec/ruby/core/complex/inspect_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/inspect', __FILE__)
describe "Complex#inspect" do
- it_behaves_like(:complex_inspect, :inspect)
+ it_behaves_like :complex_inspect, :inspect
end
diff --git a/spec/ruby/core/complex/magnitude_spec.rb b/spec/ruby/core/complex/magnitude_spec.rb
index e9175d763e..d2c5eb80dd 100644
--- a/spec/ruby/core/complex/magnitude_spec.rb
+++ b/spec/ruby/core/complex/magnitude_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/abs', __FILE__)
describe "Complex#magnitude" do
- it_behaves_like(:complex_abs, :magnitude)
+ it_behaves_like :complex_abs, :magnitude
end
diff --git a/spec/ruby/core/complex/numerator_spec.rb b/spec/ruby/core/complex/numerator_spec.rb
index 8c0e8761bd..322c950a43 100644
--- a/spec/ruby/core/complex/numerator_spec.rb
+++ b/spec/ruby/core/complex/numerator_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/numerator', __FILE__)
describe "Complex#numerator" do
- it_behaves_like(:complex_numerator, :numerator)
+ it_behaves_like :complex_numerator, :numerator
end
diff --git a/spec/ruby/core/complex/polar_spec.rb b/spec/ruby/core/complex/polar_spec.rb
index d847e916ff..110efbbfba 100644
--- a/spec/ruby/core/complex/polar_spec.rb
+++ b/spec/ruby/core/complex/polar_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../shared/complex/polar', __FILE__)
describe "Complex.polar" do
- it_behaves_like(:complex_polar_class, :polar)
+ it_behaves_like :complex_polar_class, :polar
it "raises a TypeError when given non real arguments" do
lambda{ Complex.polar(nil) }.should raise_error(TypeError)
@@ -10,5 +10,5 @@ describe "Complex.polar" do
end
describe "Complex#polar" do
- it_behaves_like(:complex_polar, :polar)
+ it_behaves_like :complex_polar, :polar
end
diff --git a/spec/ruby/core/complex/real_spec.rb b/spec/ruby/core/complex/real_spec.rb
index 1293e02d3c..a663be117f 100644
--- a/spec/ruby/core/complex/real_spec.rb
+++ b/spec/ruby/core/complex/real_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../shared/complex/real', __FILE__)
describe "Complex#real" do
- it_behaves_like(:complex_real, :real)
+ it_behaves_like :complex_real, :real
end
describe "Complex#real?" do
diff --git a/spec/ruby/core/complex/rect_spec.rb b/spec/ruby/core/complex/rect_spec.rb
index cf2ff9e83b..b2faa4ec70 100644
--- a/spec/ruby/core/complex/rect_spec.rb
+++ b/spec/ruby/core/complex/rect_spec.rb
@@ -1,9 +1,9 @@
require File.expand_path('../../../shared/complex/rect', __FILE__)
describe "Complex#rect" do
- it_behaves_like(:complex_rect, :rect)
+ it_behaves_like :complex_rect, :rect
end
describe "Complex.rect" do
- it_behaves_like(:complex_rect_class, :rect)
+ it_behaves_like :complex_rect_class, :rect
end
diff --git a/spec/ruby/core/complex/rectangular_spec.rb b/spec/ruby/core/complex/rectangular_spec.rb
index 0eb29c3500..39f78ad518 100644
--- a/spec/ruby/core/complex/rectangular_spec.rb
+++ b/spec/ruby/core/complex/rectangular_spec.rb
@@ -1,9 +1,9 @@
require File.expand_path('../../../shared/complex/rect', __FILE__)
describe "Complex#rectangular" do
- it_behaves_like(:complex_rect, :rectangular)
+ it_behaves_like :complex_rect, :rectangular
end
describe "Complex.rectangular" do
- it_behaves_like(:complex_rect_class, :rectangular)
+ it_behaves_like :complex_rect_class, :rectangular
end
diff --git a/spec/ruby/core/complex/to_s_spec.rb b/spec/ruby/core/complex/to_s_spec.rb
index c398bb000e..d6debe6317 100644
--- a/spec/ruby/core/complex/to_s_spec.rb
+++ b/spec/ruby/core/complex/to_s_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/complex/to_s', __FILE__)
describe "Complex#to_s" do
- it_behaves_like(:complex_to_s, :to_s)
+ it_behaves_like :complex_to_s, :to_s
end
diff --git a/spec/ruby/core/dir/exist_spec.rb b/spec/ruby/core/dir/exist_spec.rb
index 194284b5a0..2eb21fa5e0 100644
--- a/spec/ruby/core/dir/exist_spec.rb
+++ b/spec/ruby/core/dir/exist_spec.rb
@@ -11,5 +11,5 @@ describe "Dir.exist?" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_exist, :exist?)
+ it_behaves_like :dir_exist, :exist?
end
diff --git a/spec/ruby/core/dir/exists_spec.rb b/spec/ruby/core/dir/exists_spec.rb
index 002506a22f..9f235f381d 100644
--- a/spec/ruby/core/dir/exists_spec.rb
+++ b/spec/ruby/core/dir/exists_spec.rb
@@ -11,5 +11,5 @@ describe "Dir.exists?" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_exist, :exists?)
+ it_behaves_like :dir_exist, :exists?
end
diff --git a/spec/ruby/core/dir/path_spec.rb b/spec/ruby/core/dir/path_spec.rb
index 1601220636..1e620892f8 100644
--- a/spec/ruby/core/dir/path_spec.rb
+++ b/spec/ruby/core/dir/path_spec.rb
@@ -11,5 +11,5 @@ describe "Dir#path" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_path, :path)
+ it_behaves_like :dir_path, :path
end
diff --git a/spec/ruby/core/dir/to_path_spec.rb b/spec/ruby/core/dir/to_path_spec.rb
index 85609fbfff..a17d2bcb07 100644
--- a/spec/ruby/core/dir/to_path_spec.rb
+++ b/spec/ruby/core/dir/to_path_spec.rb
@@ -11,5 +11,5 @@ describe "Dir#to_path" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_path, :to_path)
+ it_behaves_like :dir_path, :to_path
end
diff --git a/spec/ruby/core/encoding/name_spec.rb b/spec/ruby/core/encoding/name_spec.rb
index 4ea89a563a..a8b2b93c1b 100644
--- a/spec/ruby/core/encoding/name_spec.rb
+++ b/spec/ruby/core/encoding/name_spec.rb
@@ -2,6 +2,6 @@ require File.expand_path('../shared/name', __FILE__)
with_feature :encoding do
describe "Encoding#name" do
- it_behaves_like(:encoding_name, :name)
+ it_behaves_like :encoding_name, :name
end
end
diff --git a/spec/ruby/core/encoding/to_s_spec.rb b/spec/ruby/core/encoding/to_s_spec.rb
index ddc57e321e..46dba8e091 100644
--- a/spec/ruby/core/encoding/to_s_spec.rb
+++ b/spec/ruby/core/encoding/to_s_spec.rb
@@ -2,6 +2,6 @@ require File.expand_path('../shared/name', __FILE__)
with_feature :encoding do
describe "Encoding#to_s" do
- it_behaves_like(:encoding_name, :to_s)
+ it_behaves_like :encoding_name, :to_s
end
end
diff --git a/spec/ruby/core/enumerable/collect_concat_spec.rb b/spec/ruby/core/enumerable/collect_concat_spec.rb
index 6f21012060..763544a68a 100644
--- a/spec/ruby/core/enumerable/collect_concat_spec.rb
+++ b/spec/ruby/core/enumerable/collect_concat_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect_concat', __FILE__)
describe "Enumerable#collect_concat" do
- it_behaves_like(:enumerable_collect_concat , :collect_concat)
+ it_behaves_like :enumerable_collect_concat , :collect_concat
end
diff --git a/spec/ruby/core/enumerable/collect_spec.rb b/spec/ruby/core/enumerable/collect_spec.rb
index a830eef9f7..ff43ee693b 100644
--- a/spec/ruby/core/enumerable/collect_spec.rb
+++ b/spec/ruby/core/enumerable/collect_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Enumerable#collect" do
- it_behaves_like(:enumerable_collect , :collect)
+ it_behaves_like :enumerable_collect , :collect
end
diff --git a/spec/ruby/core/enumerable/detect_spec.rb b/spec/ruby/core/enumerable/detect_spec.rb
index f69e456052..db47563a6e 100644
--- a/spec/ruby/core/enumerable/detect_spec.rb
+++ b/spec/ruby/core/enumerable/detect_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find', __FILE__)
describe "Enumerable#detect" do
- it_behaves_like(:enumerable_find , :detect)
+ it_behaves_like :enumerable_find , :detect
end
diff --git a/spec/ruby/core/enumerable/entries_spec.rb b/spec/ruby/core/enumerable/entries_spec.rb
index 94eceee713..0f2ecf5f92 100644
--- a/spec/ruby/core/enumerable/entries_spec.rb
+++ b/spec/ruby/core/enumerable/entries_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/entries', __FILE__)
describe "Enumerable#entries" do
- it_behaves_like(:enumerable_entries , :entries)
+ it_behaves_like :enumerable_entries , :entries
end
diff --git a/spec/ruby/core/enumerable/find_all_spec.rb b/spec/ruby/core/enumerable/find_all_spec.rb
index 3d587d7709..7c84b6ec7e 100644
--- a/spec/ruby/core/enumerable/find_all_spec.rb
+++ b/spec/ruby/core/enumerable/find_all_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find_all', __FILE__)
describe "Enumerable#find_all" do
- it_behaves_like(:enumerable_find_all , :find_all)
+ it_behaves_like :enumerable_find_all , :find_all
end
diff --git a/spec/ruby/core/enumerable/find_spec.rb b/spec/ruby/core/enumerable/find_spec.rb
index 62e1194537..5c4ffa0208 100644
--- a/spec/ruby/core/enumerable/find_spec.rb
+++ b/spec/ruby/core/enumerable/find_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find', __FILE__)
describe "Enumerable#find" do
- it_behaves_like(:enumerable_find , :find)
+ it_behaves_like :enumerable_find , :find
end
diff --git a/spec/ruby/core/enumerable/flat_map_spec.rb b/spec/ruby/core/enumerable/flat_map_spec.rb
index aaddeed05d..613f1dfb7d 100644
--- a/spec/ruby/core/enumerable/flat_map_spec.rb
+++ b/spec/ruby/core/enumerable/flat_map_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect_concat', __FILE__)
describe "Enumerable#flat_map" do
- it_behaves_like(:enumerable_collect_concat , :flat_map)
+ it_behaves_like :enumerable_collect_concat , :flat_map
end
diff --git a/spec/ruby/core/enumerable/include_spec.rb b/spec/ruby/core/enumerable/include_spec.rb
index 2cc0b6e83a..d288e68ad2 100644
--- a/spec/ruby/core/enumerable/include_spec.rb
+++ b/spec/ruby/core/enumerable/include_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/include', __FILE__)
describe "Enumerable#include?" do
- it_behaves_like(:enumerable_include, :include?)
+ it_behaves_like :enumerable_include, :include?
end
diff --git a/spec/ruby/core/enumerable/map_spec.rb b/spec/ruby/core/enumerable/map_spec.rb
index b2ddf1eb9d..f8158ceb7d 100644
--- a/spec/ruby/core/enumerable/map_spec.rb
+++ b/spec/ruby/core/enumerable/map_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Enumerable#map" do
- it_behaves_like(:enumerable_collect , :map)
+ it_behaves_like :enumerable_collect , :map
end
diff --git a/spec/ruby/core/enumerable/member_spec.rb b/spec/ruby/core/enumerable/member_spec.rb
index 862c949817..97375b8dcc 100644
--- a/spec/ruby/core/enumerable/member_spec.rb
+++ b/spec/ruby/core/enumerable/member_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/include', __FILE__)
describe "Enumerable#member?" do
- it_behaves_like(:enumerable_include, :member?)
+ it_behaves_like :enumerable_include, :member?
end
diff --git a/spec/ruby/core/enumerable/select_spec.rb b/spec/ruby/core/enumerable/select_spec.rb
index b4da35c754..1c3842d372 100644
--- a/spec/ruby/core/enumerable/select_spec.rb
+++ b/spec/ruby/core/enumerable/select_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/find_all', __FILE__)
describe "Enumerable#select" do
- it_behaves_like(:enumerable_find_all , :select)
+ it_behaves_like :enumerable_find_all , :select
end
diff --git a/spec/ruby/core/enumerable/to_a_spec.rb b/spec/ruby/core/enumerable/to_a_spec.rb
index b14a3c7a1a..fb0a9f1c8b 100644
--- a/spec/ruby/core/enumerable/to_a_spec.rb
+++ b/spec/ruby/core/enumerable/to_a_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/entries', __FILE__)
describe "Enumerable#to_a" do
- it_behaves_like(:enumerable_entries , :to_a)
+ it_behaves_like :enumerable_entries , :to_a
end
diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb
index a6ecf2af2d..68ff0436f8 100644
--- a/spec/ruby/core/enumerator/each_spec.rb
+++ b/spec/ruby/core/enumerator/each_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/enumerator/each', __FILE__)
describe "Enumerator#each" do
- it_behaves_like(:enum_each, :each)
+ it_behaves_like :enum_each, :each
end
diff --git a/spec/ruby/core/enumerator/each_with_index_spec.rb b/spec/ruby/core/enumerator/each_with_index_spec.rb
index c8cb0bd496..bc5c425093 100644
--- a/spec/ruby/core/enumerator/each_with_index_spec.rb
+++ b/spec/ruby/core/enumerator/each_with_index_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../../../shared/enumerator/with_index', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "Enumerator#each_with_index" do
- it_behaves_like(:enum_with_index, :each_with_index)
- it_behaves_like(:enumeratorized_with_origin_size, :each_with_index, [1,2,3].select)
+ it_behaves_like :enum_with_index, :each_with_index
+ it_behaves_like :enumeratorized_with_origin_size, :each_with_index, [1,2,3].select
it "returns a new Enumerator when no block is given" do
enum1 = [1,2,3].select
diff --git a/spec/ruby/core/enumerator/inject_spec.rb b/spec/ruby/core/enumerator/inject_spec.rb
index 64085a03c5..ca7786ae04 100644
--- a/spec/ruby/core/enumerator/inject_spec.rb
+++ b/spec/ruby/core/enumerator/inject_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../shared/enumerator/each', __FILE__)
describe "Enumerator#inject" do
- it_behaves_like(:enum_each, :each)
+ it_behaves_like :enum_each, :each
it "works when chained against each_with_index" do
passed_values = []
diff --git a/spec/ruby/core/enumerator/lazy/chunk_spec.rb b/spec/ruby/core/enumerator/lazy/chunk_spec.rb
new file mode 100644
index 0000000000..3e9d9e9dfd
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/chunk_spec.rb
@@ -0,0 +1,71 @@
+# -*- encoding: us-ascii -*-
+
+require File.expand_path('../../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+
+describe "Enumerator::Lazy#chunk" do
+
+ before :each do
+ @yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy
+ @eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy
+ ScratchPad.record []
+ end
+
+ after :each do
+ ScratchPad.clear
+ end
+
+ it "returns a new instance of Enumerator::Lazy" do
+ ret = @yieldsmixed.chunk {}
+ ret.should be_an_instance_of(Enumerator::Lazy)
+ ret.should_not equal(@yieldsmixed)
+ end
+
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.chunk { |v| v }.size.should == nil
+ end
+
+ ruby_version_is ""..."2.4" do
+ it "raises an ArgumentError if called without a block" do
+ lambda do
+ @yieldsmixed.chunk
+ end.should raise_error(ArgumentError)
+ end
+ end
+
+ ruby_version_is "2.4" do
+ it "returns an Enumerator if called without a block" do
+ chunk = @yieldsmixed.chunk
+ chunk.should be_an_instance_of(Enumerator::Lazy)
+
+ res = chunk.each { |v| true }.force
+ res.should == [[true, EnumeratorLazySpecs::YieldsMixed.gathered_yields]]
+ end
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ first_two = (0..Float::INFINITY).lazy.chunk { |n| n.even? }.first(2)
+ first_two.should == [[true, [0]], [false, [1]]]
+ end
+ end
+
+ it "calls the block with gathered values when yield with multiple arguments" do
+ yields = []
+ @yieldsmixed.chunk { |v| yields << v; true }.force
+ yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_yields
+ end
+
+ describe "on a nested Lazy" do
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.take(20).chunk { |v| v }.size.should == nil
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ remains_lazy = (0..Float::INFINITY).lazy.chunk { |n| n }
+ remains_lazy.chunk { |n| n }.first(2).size.should == 2
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/new_spec.rb b/spec/ruby/core/enumerator/new_spec.rb
index e8e0572a40..4960d0c394 100644
--- a/spec/ruby/core/enumerator/new_spec.rb
+++ b/spec/ruby/core/enumerator/new_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/enumerator/new', __FILE__)
describe "Enumerator.new" do
- it_behaves_like(:enum_new, :new)
+ it_behaves_like :enum_new, :new
end
diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb
index 6b3309a2bc..cec0cadfe4 100644
--- a/spec/ruby/core/enumerator/next_spec.rb
+++ b/spec/ruby/core/enumerator/next_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/enumerator/next', __FILE__)
describe "Enumerator#next" do
- it_behaves_like(:enum_next,:next)
+ it_behaves_like :enum_next,:next
end
diff --git a/spec/ruby/core/enumerator/rewind_spec.rb b/spec/ruby/core/enumerator/rewind_spec.rb
index 666136d74a..127e0a0da1 100644
--- a/spec/ruby/core/enumerator/rewind_spec.rb
+++ b/spec/ruby/core/enumerator/rewind_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../../../shared/enumerator/rewind', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Enumerator#rewind" do
- it_behaves_like(:enum_rewind, :rewind)
+ it_behaves_like :enum_rewind, :rewind
it "calls the enclosed object's rewind method if one exists" do
obj = mock('rewinder')
diff --git a/spec/ruby/core/enumerator/with_index_spec.rb b/spec/ruby/core/enumerator/with_index_spec.rb
index 3d0ec0a298..62e4c8b5b9 100644
--- a/spec/ruby/core/enumerator/with_index_spec.rb
+++ b/spec/ruby/core/enumerator/with_index_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../../../shared/enumerator/with_index', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "Enumerator#with_index" do
- it_behaves_like(:enum_with_index, :with_index)
- it_behaves_like(:enumeratorized_with_origin_size, :with_index, [1,2,3].select)
+ it_behaves_like :enum_with_index, :with_index
+ it_behaves_like :enumeratorized_with_origin_size, :with_index, [1,2,3].select
it "returns a new Enumerator when no block is given" do
enum1 = [1,2,3].select
diff --git a/spec/ruby/core/env/each_pair_spec.rb b/spec/ruby/core/env/each_pair_spec.rb
index 255ccd86c5..063d943aff 100644
--- a/spec/ruby/core/env/each_pair_spec.rb
+++ b/spec/ruby/core/env/each_pair_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/each.rb', __FILE__)
describe "ENV.each_pair" do
- it_behaves_like(:env_each, :each_pair)
+ it_behaves_like :env_each, :each_pair
end
diff --git a/spec/ruby/core/env/each_spec.rb b/spec/ruby/core/env/each_spec.rb
index 2424c5e4e0..e930cf4ab9 100644
--- a/spec/ruby/core/env/each_spec.rb
+++ b/spec/ruby/core/env/each_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/each.rb', __FILE__)
describe "ENV.each" do
- it_behaves_like(:env_each, :each)
+ it_behaves_like :env_each, :each
end
diff --git a/spec/ruby/core/env/element_set_spec.rb b/spec/ruby/core/env/element_set_spec.rb
index a80cd0c51e..45eed4b025 100644
--- a/spec/ruby/core/env/element_set_spec.rb
+++ b/spec/ruby/core/env/element_set_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/store.rb', __FILE__)
describe "ENV.[]=" do
- it_behaves_like(:env_store, :[]=)
+ it_behaves_like :env_store, :[]=
end
diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb
index 708ee91c39..cc74e32da3 100644
--- a/spec/ruby/core/env/fetch_spec.rb
+++ b/spec/ruby/core/env/fetch_spec.rb
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../../../shared/hash/key_error', __FILE__)
describe "ENV.fetch" do
it "returns a value" do
@@ -11,8 +12,8 @@ describe "ENV.fetch" do
lambda { ENV.fetch :should_never_be_set }.should raise_error(TypeError)
end
- it "raises a KeyError if the key is not found" do
- lambda { ENV.fetch "should_never_be_set" }.should raise_error(KeyError)
+ context "when the key is not found" do
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, ENV
end
it "provides the given default parameter" do
diff --git a/spec/ruby/core/env/has_key_spec.rb b/spec/ruby/core/env/has_key_spec.rb
index 8da2d94265..3cd1adbd2d 100644
--- a/spec/ruby/core/env/has_key_spec.rb
+++ b/spec/ruby/core/env/has_key_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.has_key?" do
- it_behaves_like(:env_include, :has_key?)
+ it_behaves_like :env_include, :has_key?
end
diff --git a/spec/ruby/core/env/has_value_spec.rb b/spec/ruby/core/env/has_value_spec.rb
index 76980a8df4..bb8c107387 100644
--- a/spec/ruby/core/env/has_value_spec.rb
+++ b/spec/ruby/core/env/has_value_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/value.rb', __FILE__)
describe "ENV.has_value?" do
- it_behaves_like(:env_value, :has_value?)
+ it_behaves_like :env_value, :has_value?
end
diff --git a/spec/ruby/core/env/include_spec.rb b/spec/ruby/core/env/include_spec.rb
index 4a716fee85..2c366a1d45 100644
--- a/spec/ruby/core/env/include_spec.rb
+++ b/spec/ruby/core/env/include_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.include?" do
- it_behaves_like(:env_include, :include?)
+ it_behaves_like :env_include, :include?
end
diff --git a/spec/ruby/core/env/index_spec.rb b/spec/ruby/core/env/index_spec.rb
index 95009b3558..7fd325fc02 100644
--- a/spec/ruby/core/env/index_spec.rb
+++ b/spec/ruby/core/env/index_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/key.rb', __FILE__)
describe "ENV.index" do
- it_behaves_like(:env_key, :index)
+ it_behaves_like :env_key, :index
end
diff --git a/spec/ruby/core/env/key_spec.rb b/spec/ruby/core/env/key_spec.rb
index b653b1b1a5..3f887a5fc5 100644
--- a/spec/ruby/core/env/key_spec.rb
+++ b/spec/ruby/core/env/key_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/include.rb', __FILE__)
require File.expand_path('../shared/key.rb', __FILE__)
describe "ENV.key?" do
- it_behaves_like(:env_include, :key?)
+ it_behaves_like :env_include, :key?
end
describe "ENV.key" do
- it_behaves_like(:env_key, :key)
+ it_behaves_like :env_key, :key
end
diff --git a/spec/ruby/core/env/length_spec.rb b/spec/ruby/core/env/length_spec.rb
index 83d1b58c74..37b98b3f0d 100644
--- a/spec/ruby/core/env/length_spec.rb
+++ b/spec/ruby/core/env/length_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length.rb', __FILE__)
describe "ENV.length" do
- it_behaves_like(:env_length, :length)
+ it_behaves_like :env_length, :length
end
diff --git a/spec/ruby/core/env/member_spec.rb b/spec/ruby/core/env/member_spec.rb
index 25aa71e973..c0f06c70df 100644
--- a/spec/ruby/core/env/member_spec.rb
+++ b/spec/ruby/core/env/member_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/include.rb', __FILE__)
describe "ENV.member?" do
- it_behaves_like(:env_include, :member?)
+ it_behaves_like :env_include, :member?
end
diff --git a/spec/ruby/core/env/size_spec.rb b/spec/ruby/core/env/size_spec.rb
index 882ceac485..466f03fecc 100644
--- a/spec/ruby/core/env/size_spec.rb
+++ b/spec/ruby/core/env/size_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length.rb', __FILE__)
describe "ENV.size" do
- it_behaves_like(:env_length, :size)
+ it_behaves_like :env_length, :size
end
diff --git a/spec/ruby/core/env/store_spec.rb b/spec/ruby/core/env/store_spec.rb
index 1ee5ce020e..af4be3a525 100644
--- a/spec/ruby/core/env/store_spec.rb
+++ b/spec/ruby/core/env/store_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/store.rb', __FILE__)
describe "ENV.store" do
- it_behaves_like(:env_store, :store)
+ it_behaves_like :env_store, :store
end
diff --git a/spec/ruby/core/env/to_h_spec.rb b/spec/ruby/core/env/to_h_spec.rb
index d0fef5382b..0c65700782 100644
--- a/spec/ruby/core/env/to_h_spec.rb
+++ b/spec/ruby/core/env/to_h_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_hash.rb', __FILE__)
describe "ENV.to_hash" do
- it_behaves_like(:env_to_hash, :to_h)
+ it_behaves_like :env_to_hash, :to_h
end
diff --git a/spec/ruby/core/env/to_hash_spec.rb b/spec/ruby/core/env/to_hash_spec.rb
index 3362fa9307..1d923990e1 100644
--- a/spec/ruby/core/env/to_hash_spec.rb
+++ b/spec/ruby/core/env/to_hash_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_hash.rb', __FILE__)
describe "ENV.to_hash" do
- it_behaves_like(:env_to_hash, :to_hash)
+ it_behaves_like :env_to_hash, :to_hash
end
diff --git a/spec/ruby/core/env/value_spec.rb b/spec/ruby/core/env/value_spec.rb
index c7eb7c5376..44e7c73d4f 100644
--- a/spec/ruby/core/env/value_spec.rb
+++ b/spec/ruby/core/env/value_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/value.rb', __FILE__)
describe "ENV.value?" do
- it_behaves_like(:env_value, :value?)
+ it_behaves_like :env_value, :value?
end
diff --git a/spec/ruby/core/exception/exception_spec.rb b/spec/ruby/core/exception/exception_spec.rb
index afa482b9d7..780bfa4831 100644
--- a/spec/ruby/core/exception/exception_spec.rb
+++ b/spec/ruby/core/exception/exception_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../fixtures/common', __FILE__)
require File.expand_path('../shared/new', __FILE__)
describe "Exception.exception" do
- it_behaves_like(:exception_new, :exception)
+ it_behaves_like :exception_new, :exception
end
describe "Exception" do
diff --git a/spec/ruby/core/exception/fixtures/common.rb b/spec/ruby/core/exception/fixtures/common.rb
index 51dd0bf9ed..e1ba102197 100644
--- a/spec/ruby/core/exception/fixtures/common.rb
+++ b/spec/ruby/core/exception/fixtures/common.rb
@@ -53,6 +53,9 @@ module NoMethodErrorSpecs
end
class NoMethodErrorD; end
+
+ class InstanceException < Exception
+ end
end
class NameErrorSpecs
diff --git a/spec/ruby/core/exception/new_spec.rb b/spec/ruby/core/exception/new_spec.rb
index 61d35a1dfa..2fc7ca9f88 100644
--- a/spec/ruby/core/exception/new_spec.rb
+++ b/spec/ruby/core/exception/new_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/common', __FILE__)
require File.expand_path('../shared/new', __FILE__)
describe "Exception.new" do
- it_behaves_like(:exception_new, :new)
+ it_behaves_like :exception_new, :new
end
diff --git a/spec/ruby/core/exception/no_method_error_spec.rb b/spec/ruby/core/exception/no_method_error_spec.rb
index cf3fe58b1d..321b2b4a8f 100644
--- a/spec/ruby/core/exception/no_method_error_spec.rb
+++ b/spec/ruby/core/exception/no_method_error_spec.rb
@@ -56,4 +56,40 @@ describe "NoMethodError#message" do
e.message.match(/private method/).should_not == nil
end
end
+
+ it "calls receiver.inspect only when calling Exception#message" do
+ ScratchPad.record []
+ test_class = Class.new do
+ def inspect
+ ScratchPad << :inspect_called
+ "<inspect>"
+ end
+ end
+ instance = test_class.new
+ begin
+ instance.bar
+ rescue Exception => e
+ e.name.should == :bar
+ ScratchPad.recorded.should == []
+ e.message.should =~ /undefined method.+\bbar\b/
+ ScratchPad.recorded.should == [:inspect_called]
+ end
+ end
+
+ it "fallbacks to a simpler representation of the receiver when receiver.inspect raises an exception" do
+ test_class = Class.new do
+ def inspect
+ raise NoMethodErrorSpecs::InstanceException
+ end
+ end
+ instance = test_class.new
+ begin
+ instance.bar
+ rescue Exception => e
+ e.name.should == :bar
+ message = e.message
+ message.should =~ /undefined method.+\bbar\b/
+ message.should include test_class.inspect
+ end
+ end
end
diff --git a/spec/ruby/core/fiber/resume_spec.rb b/spec/ruby/core/fiber/resume_spec.rb
index 3fd3aed8fa..6c518d914b 100644
--- a/spec/ruby/core/fiber/resume_spec.rb
+++ b/spec/ruby/core/fiber/resume_spec.rb
@@ -7,6 +7,11 @@ with_feature :fiber do
end
describe "Fiber#resume" do
+ it "raises a FiberError if the Fiber tries to resume itself" do
+ fiber = Fiber.new { fiber.resume }
+ -> { fiber.resume }.should raise_error(FiberError, /double resume/)
+ end
+
it "returns control to the calling Fiber if called from one" do
fiber1 = Fiber.new { :fiber1 }
fiber2 = Fiber.new { fiber1.resume; :fiber2 }
diff --git a/spec/ruby/core/file/delete_spec.rb b/spec/ruby/core/file/delete_spec.rb
index 2e903806d7..9c4bf33c48 100644
--- a/spec/ruby/core/file/delete_spec.rb
+++ b/spec/ruby/core/file/delete_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/unlink', __FILE__)
describe "File.delete" do
- it_behaves_like(:file_unlink, :delete)
+ it_behaves_like :file_unlink, :delete
end
diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb
index 29a410c125..0ca6b87ff4 100644
--- a/spec/ruby/core/file/exist_spec.rb
+++ b/spec/ruby/core/file/exist_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/file/exist', __FILE__)
describe "File.exist?" do
- it_behaves_like(:file_exist, :exist?, File)
+ it_behaves_like :file_exist, :exist?, File
end
diff --git a/spec/ruby/core/file/exists_spec.rb b/spec/ruby/core/file/exists_spec.rb
index 70ebd12d86..ee5d564112 100644
--- a/spec/ruby/core/file/exists_spec.rb
+++ b/spec/ruby/core/file/exists_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/file/exist', __FILE__)
describe "File.exists?" do
- it_behaves_like(:file_exist, :exists?, File)
+ it_behaves_like :file_exist, :exists?, File
end
diff --git a/spec/ruby/core/file/fnmatch_spec.rb b/spec/ruby/core/file/fnmatch_spec.rb
index 8a4caacfb8..a2287ffcdb 100644
--- a/spec/ruby/core/file/fnmatch_spec.rb
+++ b/spec/ruby/core/file/fnmatch_spec.rb
@@ -2,9 +2,9 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/fnmatch', __FILE__)
describe "File.fnmatch" do
- it_behaves_like(:file_fnmatch, :fnmatch)
+ it_behaves_like :file_fnmatch, :fnmatch
end
describe "File.fnmatch?" do
- it_behaves_like(:file_fnmatch, :fnmatch?)
+ it_behaves_like :file_fnmatch, :fnmatch?
end
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index 9d0ef62939..3b2ae60489 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -526,7 +526,7 @@ describe "File.open" do
ruby_version_is "2.3" do
platform_is :linux do
- if defined?(File::TMPFILE)
+ guard -> { defined?(File::TMPFILE) } do
it "creates an unnamed temporary file with File::TMPFILE" do
dir = tmp("tmpfilespec")
mkdir_p dir
diff --git a/spec/ruby/core/file/path_spec.rb b/spec/ruby/core/file/path_spec.rb
index 5004e128cd..7a613a757f 100644
--- a/spec/ruby/core/file/path_spec.rb
+++ b/spec/ruby/core/file/path_spec.rb
@@ -1,6 +1,11 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/path', __FILE__)
describe "File#path" do
+ it_behaves_like :file_path, :path
+end
+
+describe "File.path" do
before :each do
@name = tmp("file_path")
end
@@ -9,21 +14,27 @@ describe "File#path" do
rm_r @name
end
- it "returns the pathname used to create file as a string" do
- File.open(@name,'w') { |file| file.path.should == @name }
+ it "returns the string argument without any change" do
+ File.path("abc").should == "abc"
+ File.path("./abc").should == "./abc"
+ File.path("../abc").should == "../abc"
+ File.path("/./a/../bc").should == "/./a/../bc"
end
-end
-describe "File.path" do
- before :each do
- @name = tmp("file_path")
+ it "returns path for File argument" do
+ File.open(@name, "w") do |f|
+ File.path(f).should == @name
+ end
end
- after :each do
- rm_r @name
+ it "returns path for Pathname argument" do
+ require "pathname"
+ File.path(Pathname.new(@name)).should == @name
end
- it "returns the full path for the given file" do
- File.path(@name).should == @name
+ it "calls #to_path for non-string argument and returns result" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return("abc")
+ File.path(path).should == "abc"
end
end
diff --git a/spec/ruby/core/file/shared/path.rb b/spec/ruby/core/file/shared/path.rb
new file mode 100644
index 0000000000..3f2fccafa9
--- /dev/null
+++ b/spec/ruby/core/file/shared/path.rb
@@ -0,0 +1,80 @@
+describe :file_path, shared: true do
+ before :each do
+ @name = "file_to_path"
+ @path = tmp(@name)
+ touch @path
+ end
+
+ after :each do
+ @file.close if @file and !@file.closed?
+ rm_r @path
+ end
+
+ it "returns a String" do
+ @file = File.new @path
+ @file.send(@method).should be_an_instance_of(String)
+ end
+
+ it "calls to_str on argument and returns exact value" do
+ path = mock('path')
+ path.should_receive(:to_str).and_return(@path)
+ @file = File.new path
+ @file.send(@method).should == @path
+ end
+
+ it "does not normalise the path it returns" do
+ Dir.chdir(tmp("")) do
+ unorm = "./#{@name}"
+ @file = File.new unorm
+ @file.send(@method).should == unorm
+ end
+ end
+
+ it "does not canonicalize the path it returns" do
+ dir = File.basename tmp("")
+ path = "#{tmp("")}../#{dir}/#{@name}"
+ @file = File.new path
+ @file.send(@method).should == path
+ end
+
+ it "does not absolute-ise the path it returns" do
+ Dir.chdir(tmp("")) do
+ @file = File.new @name
+ @file.send(@method).should == @name
+ end
+ end
+
+ with_feature :encoding do
+ it "preserves the encoding of the path" do
+ path = @path.force_encoding("euc-jp")
+ @file = File.new path
+ @file.send(@method).encoding.should == Encoding.find("euc-jp")
+ end
+ end
+
+ ruby_version_is "2.5" do
+ platform_is :linux do
+ guard -> { defined?(File::TMPFILE) } do
+ before :each do
+ @dir = tmp("tmpfilespec")
+ mkdir_p @dir
+ end
+
+ after :each do
+ rm_r @dir
+ end
+
+ it "raises IOError if file was opened with File::TMPFILE" do
+ begin
+ File.open(@dir, File::RDWR | File::TMPFILE) do |f|
+ -> { f.send(@method) }.should raise_error(IOError)
+ end
+ rescue Errno::EOPNOTSUPP
+ # EOPNOTSUPP: no support from the filesystem
+ 1.should == 1
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/file/stat/world_readable_spec.rb b/spec/ruby/core/file/stat/world_readable_spec.rb
index 178e39a1ea..e72963c0b8 100644
--- a/spec/ruby/core/file/stat/world_readable_spec.rb
+++ b/spec/ruby/core/file/stat/world_readable_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../../../../shared/file/world_readable', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "File::Stat.world_readable?" do
- it_behaves_like(:file_world_readable, :world_readable?, FileStat)
+ it_behaves_like :file_world_readable, :world_readable?, FileStat
end
describe "File::Stat#world_readable?" do
diff --git a/spec/ruby/core/file/stat/world_writable_spec.rb b/spec/ruby/core/file/stat/world_writable_spec.rb
index 73a7c6d3ed..f532d752dd 100644
--- a/spec/ruby/core/file/stat/world_writable_spec.rb
+++ b/spec/ruby/core/file/stat/world_writable_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../../../../shared/file/world_writable', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "File::Stat.world_writable?" do
- it_behaves_like(:file_world_writable, :world_writable?, FileStat)
+ it_behaves_like :file_world_writable, :world_writable?, FileStat
end
describe "File::Stat#world_writable?" do
diff --git a/spec/ruby/core/file/to_path_spec.rb b/spec/ruby/core/file/to_path_spec.rb
index 3dc801cc27..006011089c 100644
--- a/spec/ruby/core/file/to_path_spec.rb
+++ b/spec/ruby/core/file/to_path_spec.rb
@@ -1,49 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/path', __FILE__)
describe "File#to_path" do
- before :each do
- @name = "file_to_path"
- @path = tmp(@name)
- touch @path
- end
-
- after :each do
- @file.close if @file and !@file.closed?
- rm_r @path
- end
-
- it "returns a String" do
- @file = File.new @path
- @file.to_path.should be_an_instance_of(String)
- end
-
- it "does not normalise the path it returns" do
- Dir.chdir(tmp("")) do
- unorm = "./#{@name}"
- @file = File.new unorm
- @file.to_path.should == unorm
- end
- end
-
- it "does not canonicalize the path it returns" do
- dir = File.basename tmp("")
- path = "#{tmp("")}../#{dir}/#{@name}"
- @file = File.new path
- @file.to_path.should == path
- end
-
- it "does not absolute-ise the path it returns" do
- Dir.chdir(tmp("")) do
- @file = File.new @name
- @file.to_path.should == @name
- end
- end
-
- with_feature :encoding do
- it "preserves the encoding of the path" do
- path = @path.force_encoding("euc-jp")
- @file = File.new path
- @file.to_path.encoding.should == Encoding.find("euc-jp")
- end
- end
+ it_behaves_like :file_path, :to_path
end
diff --git a/spec/ruby/core/file/unlink_spec.rb b/spec/ruby/core/file/unlink_spec.rb
index a1e96aef6a..3e67ebc25d 100644
--- a/spec/ruby/core/file/unlink_spec.rb
+++ b/spec/ruby/core/file/unlink_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/unlink', __FILE__)
describe "File.unlink" do
- it_behaves_like(:file_unlink, :unlink)
+ it_behaves_like :file_unlink, :unlink
end
diff --git a/spec/ruby/core/file/world_readable_spec.rb b/spec/ruby/core/file/world_readable_spec.rb
index a130f0d115..ea0b739fff 100644
--- a/spec/ruby/core/file/world_readable_spec.rb
+++ b/spec/ruby/core/file/world_readable_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/file/world_readable', __FILE__)
describe "File.world_readable?" do
- it_behaves_like(:file_world_readable, :world_readable?, File)
+ it_behaves_like :file_world_readable, :world_readable?, File
it "returns nil if the file does not exist" do
file = rand.to_s + $$.to_s
diff --git a/spec/ruby/core/file/world_writable_spec.rb b/spec/ruby/core/file/world_writable_spec.rb
index 5a39643ef9..57aede397c 100644
--- a/spec/ruby/core/file/world_writable_spec.rb
+++ b/spec/ruby/core/file/world_writable_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/file/world_writable', __FILE__)
describe "File.world_writable?" do
- it_behaves_like(:file_world_writable, :world_writable?, File)
+ it_behaves_like :file_world_writable, :world_writable?, File
it "returns nil if the file does not exist" do
file = rand.to_s + $$.to_s
diff --git a/spec/ruby/core/fixnum/bit_and_spec.rb b/spec/ruby/core/fixnum/bit_and_spec.rb
deleted file mode 100644
index 9586075039..0000000000
--- a/spec/ruby/core/fixnum/bit_and_spec.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#&" do
- it "returns self bitwise AND other" do
- (256 & 16).should == 0
- (2010 & 5).should == 0
- (65535 & 1).should == 1
- (0xffff & bignum_value + 0xffff_ffff).should == 65535
- end
-
- it "returns self bitwise AND other when one operand is negative" do
- ((1 << 33) & -1).should == (1 << 33)
- (-1 & (1 << 33)).should == (1 << 33)
-
- ((-(1<<33)-1) & 5).should == 5
- (5 & (-(1<<33)-1)).should == 5
- end
-
- it "returns self bitwise AND other when both operands are negative" do
- (-5 & -1).should == -5
- (-3 & -4).should == -4
- (-12 & -13).should == -16
- (-13 & -12).should == -16
- end
-
- it "returns self bitwise AND a Bignum" do
- (-1 & 2**64).should == 18446744073709551616
- end
-
- it "coerces the rhs and calls #coerce" do
- obj = mock("fixnum bit and")
- obj.should_receive(:coerce).with(6).and_return([3, 6])
- (6 & obj).should == 2
- end
-
- it "raises a TypeError when passed a Float" do
- lambda { (3 & 3.4) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("fixnum bit and")
- obj.should_not_receive(:to_int)
-
- lambda { 3 & obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/bit_length_spec.rb b/spec/ruby/core/fixnum/bit_length_spec.rb
deleted file mode 100644
index 8c9f69b7d7..0000000000
--- a/spec/ruby/core/fixnum/bit_length_spec.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#bit_length" do
- it "returns the position of the leftmost bit of a positive number" do
- 0.bit_length.should == 0
- 1.bit_length.should == 1
- 2.bit_length.should == 2
- 3.bit_length.should == 2
- 4.bit_length.should == 3
- n = fixnum_max.bit_length
- fixnum_max[n].should == 0
- fixnum_max[n-1].should == 1
-
- 0.bit_length.should == 0
- 1.bit_length.should == 1
- 0xff.bit_length.should == 8
- 0x100.bit_length.should == 9
- (2**12-1).bit_length.should == 12
- (2**12).bit_length.should == 13
- (2**12+1).bit_length.should == 13
- end
-
- it "returns the position of the leftmost 0 bit of a negative number" do
- -1.bit_length.should == 0
- -2.bit_length.should == 1
- -3.bit_length.should == 2
- -4.bit_length.should == 2
- -5.bit_length.should == 3
- n = fixnum_min.bit_length
- fixnum_min[n].should == 1
- fixnum_min[n-1].should == 0
-
- (-2**12-1).bit_length.should == 13
- (-2**12).bit_length.should == 12
- (-2**12+1).bit_length.should == 12
- -0x101.bit_length.should == 9
- -0x100.bit_length.should == 8
- -0xff.bit_length.should == 8
- -2.bit_length.should == 1
- -1.bit_length.should == 0
- end
-end
diff --git a/spec/ruby/core/fixnum/bit_or_spec.rb b/spec/ruby/core/fixnum/bit_or_spec.rb
deleted file mode 100644
index cd1865ffe9..0000000000
--- a/spec/ruby/core/fixnum/bit_or_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#|" do
- it "returns self bitwise OR other" do
- (1 | 0).should == 1
- (5 | 4).should == 5
- (5 | 6).should == 7
- (248 | 4096).should == 4344
- (0xffff | bignum_value + 0xf0f0).should == 0x8000_0000_0000_ffff
- end
-
- it "returns self bitwise OR a Bignum" do
- (-1 | 2**64).should == -1
- end
-
- it "raises a TypeError when passed a Float" do
- lambda { (3 | 3.4) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("fixnum bit or")
- obj.should_not_receive(:to_int)
-
- lambda { 3 | obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/bit_xor_spec.rb b/spec/ruby/core/fixnum/bit_xor_spec.rb
deleted file mode 100644
index 38a90a4dfa..0000000000
--- a/spec/ruby/core/fixnum/bit_xor_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#^" do
- it "returns self bitwise EXCLUSIVE OR other" do
- (3 ^ 5).should == 6
- (-2 ^ -255).should == 255
- (5 ^ bignum_value + 0xffff_ffff).should == 0x8000_0000_ffff_fffa
- end
-
- it "returns self bitwise EXCLUSIVE OR a Bignum" do
- (-1 ^ 2**64).should == -18446744073709551617
- end
-
- it "raises a TypeError when passed a Float" do
- lambda { (3 ^ 3.4) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError and does not call #to_int when defined on an object" do
- obj = mock("fixnum bit xor")
- obj.should_not_receive(:to_int)
-
- lambda { 3 ^ obj }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/coerce_spec.rb b/spec/ruby/core/fixnum/coerce_spec.rb
deleted file mode 100644
index 3ca7cb2df4..0000000000
--- a/spec/ruby/core/fixnum/coerce_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#coerce when given a Fixnum" do
- it "returns an array containing two Fixnums" do
- 1.coerce(2).should == [2, 1]
- 1.coerce(2).map { |i| i.class }.should == [Fixnum, Fixnum]
- end
-end
-
-describe "Fixnum#coerce when given a String" do
- it "raises an ArgumentError when trying to coerce with a non-number String" do
- lambda { 1.coerce(":)") }.should raise_error(ArgumentError)
- end
-
- it "returns an array containing two Floats" do
- 1.coerce("2").should == [2.0, 1.0]
- 1.coerce("-2").should == [-2.0, 1.0]
- end
-end
-
-describe "Fixnum#coerce" do
- it "raises a TypeError when trying to coerce with nil" do
- lambda { 1.coerce(nil) }.should raise_error(TypeError)
- end
-
- it "tries to convert the given Object into a Float by using #to_f" do
- (obj = mock('1.0')).should_receive(:to_f).and_return(1.0)
- 2.coerce(obj).should == [1.0, 2.0]
-
- (obj = mock('0')).should_receive(:to_f).and_return('0')
- lambda { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Object that does not respond to #to_f" do
- lambda { 1.coerce(mock('x')) }.should raise_error(TypeError)
- lambda { 1.coerce(1..4) }.should raise_error(TypeError)
- lambda { 1.coerce(:test) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/comparison_spec.rb b/spec/ruby/core/fixnum/comparison_spec.rb
deleted file mode 100644
index 4c932d213d..0000000000
--- a/spec/ruby/core/fixnum/comparison_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#<=>" do
- it "returns -1 when self is less than the given argument" do
- (-3 <=> -1).should == -1
- (-5 <=> 10).should == -1
- (-5 <=> -4.5).should == -1
- end
-
- it "returns 0 when self is equal to the given argument" do
- (0 <=> 0).should == 0
- (954 <=> 954).should == 0
- (954 <=> 954.0).should == 0
- end
-
- it "returns 1 when self is greater than the given argument" do
- (496 <=> 5).should == 1
- (200 <=> 100).should == 1
- (51 <=> 50.5).should == 1
- end
-
- it "returns nil when the given argument is not an Integer" do
- (3 <=> mock('x')).should == nil
- (3 <=> 'test').should == nil
- end
-end
diff --git a/spec/ruby/core/fixnum/complement_spec.rb b/spec/ruby/core/fixnum/complement_spec.rb
deleted file mode 100644
index 06692579c5..0000000000
--- a/spec/ruby/core/fixnum/complement_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#~" do
- it "returns self with each bit flipped" do
- (~0).should == -1
- (~1221).should == -1222
- (~-2).should == 1
- (~-599).should == 598
- end
-end
diff --git a/spec/ruby/core/fixnum/div_spec.rb b/spec/ruby/core/fixnum/div_spec.rb
deleted file mode 100644
index be9b498508..0000000000
--- a/spec/ruby/core/fixnum/div_spec.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#div with a Fixnum" do
- it "returns self divided by the given argument as an Integer" do
- 2.div(2).should == 1
- 1.div(2).should == 0
- 5.div(2).should == 2
- end
-end
-
-describe "Fixnum#div" do
- it "rounds towards -inf" do
- 8192.div(10).should == 819
- 8192.div(-10).should == -820
- (-8192).div(10).should == -820
- (-8192).div(-10).should == 819
- end
-
- it "coerces self and the given argument to Floats and returns self divided by other as Fixnum" do
- 1.div(0.2).should == 5
- 1.div(0.16).should == 6
- 1.div(0.169).should == 5
- -1.div(50.4).should == -1
- 1.div(bignum_value).should == 0
- end
-
- it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
- lambda { 0.div(0.0) }.should raise_error(ZeroDivisionError)
- lambda { 10.div(0.0) }.should raise_error(ZeroDivisionError)
- lambda { -10.div(0.0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a ZeroDivisionError when the given argument is 0" do
- lambda { 13.div(0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13.div(obj)
- }.should raise_error(TypeError)
- lambda { 5.div("2") }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/divide_spec.rb b/spec/ruby/core/fixnum/divide_spec.rb
deleted file mode 100644
index 1e7c17e58f..0000000000
--- a/spec/ruby/core/fixnum/divide_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#/" do
- it "returns self divided by the given argument" do
- (2 / 2).should == 1
- (3 / 2).should == 1
- end
-
- it "supports dividing negative numbers" do
- (-1 / 10).should == -1
- end
-
- it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
- lambda { 1 / 0 }.should raise_error(ZeroDivisionError)
- end
-
- it "does NOT raise ZeroDivisionError if the given argument is zero and is a Float" do
- (1 / 0.0).to_s.should == 'Infinity'
- (-1 / 0.0).to_s.should == '-Infinity'
- end
-
- it "coerces fixnum and return self divided by other" do
- (-1 / 50.4).should be_close(-0.0198412698412698, TOLERANCE)
- (1 / bignum_value).should == 0
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13 / obj
- }.should raise_error(TypeError)
- lambda { 13 / "10" }.should raise_error(TypeError)
- lambda { 13 / :symbol }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/divmod_spec.rb b/spec/ruby/core/fixnum/divmod_spec.rb
deleted file mode 100644
index 21c9afe315..0000000000
--- a/spec/ruby/core/fixnum/divmod_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#divmod" do
- it "returns an Array containing quotient and modulus obtained from dividing self by the given argument" do
- 13.divmod(4).should == [3, 1]
- 4.divmod(13).should == [0, 4]
-
- 13.divmod(4.0).should == [3, 1]
- 4.divmod(13.0).should == [0, 4]
-
- 1.divmod(2.0).should == [0, 1.0]
- 200.divmod(bignum_value).should == [0, 200]
- end
-
- it "raises a ZeroDivisionError when the given argument is 0" do
- lambda { 13.divmod(0) }.should raise_error(ZeroDivisionError)
- lambda { 0.divmod(0) }.should raise_error(ZeroDivisionError)
- lambda { -10.divmod(0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
- lambda { 0.divmod(0.0) }.should raise_error(ZeroDivisionError)
- lambda { 10.divmod(0.0) }.should raise_error(ZeroDivisionError)
- lambda { -10.divmod(0.0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13.divmod(obj)
- }.should raise_error(TypeError)
- lambda { 13.divmod("10") }.should raise_error(TypeError)
- lambda { 13.divmod(:symbol) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/element_reference_spec.rb b/spec/ruby/core/fixnum/element_reference_spec.rb
deleted file mode 100644
index 736e8a549b..0000000000
--- a/spec/ruby/core/fixnum/element_reference_spec.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#[]" do
- it "behaves like (n >> b) & 1" do
- 0b101[1].should == 0
- 0b101[2].should == 1
- end
-
- it "returns 1 if the nth bit is set" do
- 15[1].should == 1
- end
-
- it "returns 1 if the nth bit is set (in two's-complement representation)" do
- (-1)[1].should == 1
- end
-
- it "returns 0 if the nth bit is not set" do
- 8[2].should == 0
- end
-
- it "returns 0 if the nth bit is not set (in two's-complement representation)" do
- (-2)[0].should == 0
- end
-
- it "returns 0 if the nth bit is greater than the most significant bit" do
- 2[3].should == 0
- end
-
- it "returns 1 if self is negative and the nth bit is greater than the most significant bit" do
- (-1)[3].should == 1
- end
-
- it "returns 0 when passed a negative argument" do
- 3[-1].should == 0
- (-1)[-1].should == 0
- end
-
- it "calls #to_int to convert the argument to an Integer and returns 1 if the nth bit is set" do
- obj = mock('1')
- obj.should_receive(:to_int).and_return(1)
-
- 2[obj].should == 1
- end
-
- it "calls #to_int to convert the argument to an Integer and returns 0 if the nth bit is set" do
- obj = mock('0')
- obj.should_receive(:to_int).and_return(0)
-
- 2[obj].should == 0
- end
-
- it "accepts a Float argument and returns 0 if the bit at the truncated value is not set" do
- 13[1.3].should == 0
- end
-
- it "accepts a Float argument and returns 1 if the bit at the truncated value is set" do
- 13[2.1].should == 1
- end
-
- it "raises a TypeError when passed a String" do
- lambda { 3["3"] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when #to_int does not return an Integer" do
- obj = mock('asdf')
- obj.should_receive(:to_int).and_return("asdf")
- lambda { 3[obj] }.should raise_error(TypeError)
- end
-
- it "calls #to_int to coerce a String to a Bignum and returns 0" do
- obj = mock('bignum value')
- obj.should_receive(:to_int).and_return(bignum_value)
-
- 3[obj].should == 0
- end
-
- it "returns 0 when passed a Float in the range of a Bignum" do
- 3[bignum_value.to_f].should == 0
- end
-end
diff --git a/spec/ruby/core/fixnum/even_spec.rb b/spec/ruby/core/fixnum/even_spec.rb
deleted file mode 100644
index 1cafb7d3a0..0000000000
--- a/spec/ruby/core/fixnum/even_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#even?" do
- it "is true for zero" do
- 0.even?.should be_true
- end
-
- it "is true for even positive Fixnums" do
- 4.even?.should be_true
- end
-
- it "is true for even negative Fixnums" do
- (-4).even?.should be_true
- end
-
- it "is false for odd positive Fixnums" do
- 5.even?.should be_false
- end
-
- it "is false for odd negative Fixnums" do
- (-5).even?.should be_false
- end
-end
diff --git a/spec/ruby/core/fixnum/exponent_spec.rb b/spec/ruby/core/fixnum/exponent_spec.rb
deleted file mode 100644
index f3e7349ace..0000000000
--- a/spec/ruby/core/fixnum/exponent_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#**" do
- it "returns self raised to the given power" do
- (2 ** 0).should eql 1
- (2 ** 1).should eql 2
- (2 ** 2).should eql 4
-
- (9 ** 0.5).should eql 3.0
- (5 ** -1).to_f.to_s.should == '0.2'
-
- (2 ** 40).should eql 1099511627776
- end
-
- it "overflows the answer to a bignum transparantly" do
- (2 ** 29).should eql 536870912
- (2 ** 30).should eql 1073741824
- (2 ** 31).should eql 2147483648
- (2 ** 32).should eql 4294967296
-
- (2 ** 61).should eql 2305843009213693952
- (2 ** 62).should eql 4611686018427387904
- (2 ** 63).should eql 9223372036854775808
- (2 ** 64).should eql 18446744073709551616
- (8 ** 23).should eql 590295810358705651712
- end
-
- it "raises negative numbers to the given power" do
- ((-2) ** 29).should eql(-536870912)
- ((-2) ** 30).should eql(1073741824)
- ((-2) ** 31).should eql(-2147483648)
- ((-2) ** 32).should eql(4294967296)
-
- ((-2) ** 61).should eql(-2305843009213693952)
- ((-2) ** 62).should eql(4611686018427387904)
- ((-2) ** 63).should eql(-9223372036854775808)
- ((-2) ** 64).should eql(18446744073709551616)
- end
-
- it "can raise 1 to a Bignum safely" do
- big = bignum_value(4611686018427387904)
- (1 ** big).should eql 1
- end
-
- it "can raise -1 to a Bignum safely" do
- ((-1) ** bignum_value(0)).should eql(1)
- ((-1) ** bignum_value(1)).should eql(-1)
- end
-
- it "switches to a Float when the number is too big" do
- big = bignum_value(4611686018427387904)
- flt = (2 ** big)
- flt.should be_kind_of(Float)
- flt.infinite?.should == 1
- end
-
- conflicts_with :Rational do
- it "raises a ZeroDivisionError for 0**-1" do
- lambda { (0**-1) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13 ** obj
- }.should raise_error(TypeError)
- lambda { 13 ** "10" }.should raise_error(TypeError)
- lambda { 13 ** :symbol }.should raise_error(TypeError)
- end
- end
-
- it "returns a complex number when negative and raised to a fractional power" do
- ((-8) ** (1.0/3)) .should be_close(Complex(1, 1.73205), TOLERANCE)
- ((-8) ** Rational(1,3)).should be_close(Complex(1, 1.73205), TOLERANCE)
- end
-end
diff --git a/spec/ruby/core/fixnum/fixnum_spec.rb b/spec/ruby/core/fixnum/fixnum_spec.rb
deleted file mode 100644
index 7f72f95e94..0000000000
--- a/spec/ruby/core/fixnum/fixnum_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum" do
- it "includes Comparable" do
- Fixnum.include?(Comparable).should == true
- end
-
- it ".allocate raises a TypeError" do
- lambda do
- Fixnum.allocate
- end.should raise_error(TypeError)
- end
-
- it ".new is undefined" do
- lambda do
- Fixnum.new
- end.should raise_error(NoMethodError)
- end
-
- ruby_version_is '2.4' do
- it "is unified into Integer" do
- Fixnum.should equal(Integer)
- end
-
- it "is deprecated" do
- -> {
- Fixnum
- }.should complain(/constant ::Fixnum is deprecated/)
- end
- end
-end
diff --git a/spec/ruby/core/fixnum/gt_spec.rb b/spec/ruby/core/fixnum/gt_spec.rb
deleted file mode 100644
index 2fe70304ae..0000000000
--- a/spec/ruby/core/fixnum/gt_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#>" do
- it "returns true if self is greater than the given argument" do
- (13 > 2).should == true
- (-500 > -600).should == true
-
- (1 > 5).should == false
- (5 > 5).should == false
-
- (900 > bignum_value).should == false
- (5 > 4.999).should == true
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { 5 > "4" }.should raise_error(ArgumentError)
- lambda { 5 > mock('x') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/fixnum/gte_spec.rb b/spec/ruby/core/fixnum/gte_spec.rb
deleted file mode 100644
index 1d5c2b70f8..0000000000
--- a/spec/ruby/core/fixnum/gte_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#>=" do
- it "returns true if self is greater than or equal to the given argument" do
- (13 >= 2).should == true
- (-500 >= -600).should == true
-
- (1 >= 5).should == false
- (2 >= 2).should == true
- (5 >= 5).should == true
-
- (900 >= bignum_value).should == false
- (5 >= 4.999).should == true
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { 5 >= "4" }.should raise_error(ArgumentError)
- lambda { 5 >= mock('x') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/fixnum/hash_spec.rb b/spec/ruby/core/fixnum/hash_spec.rb
deleted file mode 100644
index de2996a7c6..0000000000
--- a/spec/ruby/core/fixnum/hash_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#hash" do
- it "is provided" do
- 1.respond_to?(:hash).should == true
- end
-
- it "is stable" do
- 1.hash.should == 1.hash
- end
-end
diff --git a/spec/ruby/core/fixnum/left_shift_spec.rb b/spec/ruby/core/fixnum/left_shift_spec.rb
deleted file mode 100644
index 8eb5e424ff..0000000000
--- a/spec/ruby/core/fixnum/left_shift_spec.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#<< with n << m" do
- it "returns n shifted left m bits when n > 0, m > 0" do
- (1 << 1).should == 2
- end
-
- it "returns n shifted left m bits when n < 0, m > 0" do
- (-1 << 1).should == -2
- (-7 << 1).should == -14
- (-42 << 2).should == -168
- end
-
- it "returns n shifted right m bits when n > 0, m < 0" do
- (2 << -1).should == 1
- end
-
- it "returns n shifted right m bits when n < 0, m < 0" do
- (-2 << -1).should == -1
- end
-
- it "returns 0 when n == 0" do
- (0 << 1).should == 0
- end
-
- it "returns n when n > 0, m == 0" do
- (1 << 0).should == 1
- end
-
- it "returns n when n < 0, m == 0" do
- (-1 << 0).should == -1
- end
-
- it "returns 0 when n > 0, m < 0 and n < 2**-m" do
- (3 << -2).should == 0
- (7 << -3).should == 0
- (127 << -7).should == 0
-
- # To make sure the exponent is not truncated
- (7 << -32).should == 0
- (7 << -64).should == 0
- end
-
- it "returns -1 when n < 0, m < 0 and n > -(2**-m)" do
- (-3 << -2).should == -1
- (-7 << -3).should == -1
- (-127 << -7).should == -1
-
- # To make sure the exponent is not truncated
- (-7 << -32).should == -1
- (-7 << -64).should == -1
- end
-
- it "returns 0 when m < 0 and m is a Bignum" do
- (3 << -bignum_value).should == 0
- end
-
- it "returns a Bignum == fixnum_max * 2 when fixnum_max << 1 and n > 0" do
- result = fixnum_max << 1
- result.should be_an_instance_of(Bignum)
- result.should == fixnum_max * 2
- end
-
- it "returns a Bignum == fixnum_min * 2 when fixnum_min << 1 and n < 0" do
- result = fixnum_min << 1
- result.should be_an_instance_of(Bignum)
- result.should == fixnum_min * 2
- end
-
- it "calls #to_int to convert the argument to an Integer" do
- obj = mock("4")
- obj.should_receive(:to_int).and_return(4)
-
- (3 << obj).should == 48
- end
-
- it "raises a TypeError when #to_int does not return an Integer" do
- obj = mock("a string")
- obj.should_receive(:to_int).and_return("asdf")
-
- lambda { 3 << obj }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed nil" do
- lambda { 3 << nil }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a String" do
- lambda { 3 << "4" }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/lt_spec.rb b/spec/ruby/core/fixnum/lt_spec.rb
deleted file mode 100644
index 0bedf428b2..0000000000
--- a/spec/ruby/core/fixnum/lt_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#<" do
- it "returns true if self is less than the given argument" do
- (2 < 13).should == true
- (-600 < -500).should == true
-
- (5 < 1).should == false
- (5 < 5).should == false
-
- (900 < bignum_value).should == true
- (5 < 4.999).should == false
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { 5 < "4" }.should raise_error(ArgumentError)
- lambda { 5 < mock('x') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/fixnum/lte_spec.rb b/spec/ruby/core/fixnum/lte_spec.rb
deleted file mode 100644
index b9e5810d26..0000000000
--- a/spec/ruby/core/fixnum/lte_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#<=" do
- it "returns true if self is less than or equal to other" do
- (2 <= 13).should == true
- (-600 <= -500).should == true
-
- (5 <= 1).should == false
- (5 <= 5).should == true
- (-2 <= -2).should == true
-
- (900 <= bignum_value).should == true
- (5 <= 4.999).should == false
- end
-
- it "raises an ArgumentError when given a non-Integer" do
- lambda { 5 <= "4" }.should raise_error(ArgumentError)
- lambda { 5 <= mock('x') }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/fixnum/magnitude_spec.rb b/spec/ruby/core/fixnum/magnitude_spec.rb
deleted file mode 100644
index dc250eba19..0000000000
--- a/spec/ruby/core/fixnum/magnitude_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/abs', __FILE__)
-
-describe "Fixnum#magnitude" do
- it_behaves_like :fixnum_abs, :magnitude
-end
diff --git a/spec/ruby/core/fixnum/minus_spec.rb b/spec/ruby/core/fixnum/minus_spec.rb
deleted file mode 100644
index de3af05179..0000000000
--- a/spec/ruby/core/fixnum/minus_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#-" do
- it "returns self minus the given Integer" do
- (5 - 10).should == -5
- (9237212 - 5_280).should == 9231932
-
- (781 - 0.5).should == 780.5
- (2_560_496 - bignum_value).should == -9223372036852215312
- end
-
- it "returns a Bignum only if the result is too large to be a Fixnum" do
- (5 - 10).should be_an_instance_of Fixnum
- (-1 - bignum_value).should be_an_instance_of Bignum
-
- bignum_zero = bignum_value.coerce(0).first
- (1 - bignum_zero).should be_an_instance_of Fixnum
- (fixnum_min - 1).should be_an_instance_of(Bignum)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13 - obj
- }.should raise_error(TypeError)
- lambda { 13 - "10" }.should raise_error(TypeError)
- lambda { 13 - :symbol }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/modulo_spec.rb b/spec/ruby/core/fixnum/modulo_spec.rb
deleted file mode 100644
index 19d3291a11..0000000000
--- a/spec/ruby/core/fixnum/modulo_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/modulo', __FILE__)
-
-describe "Fixnum#%" do
- it_behaves_like(:fixnum_modulo, :%)
-end
-
-describe "Fixnum#modulo" do
- it_behaves_like(:fixnum_modulo, :modulo)
-end
diff --git a/spec/ruby/core/fixnum/multiply_spec.rb b/spec/ruby/core/fixnum/multiply_spec.rb
deleted file mode 100644
index 2eabd7b632..0000000000
--- a/spec/ruby/core/fixnum/multiply_spec.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#*" do
- it "returns self multiplied by the given Integer" do
- (4923 * 2).should == 9846
- (1342177 * 800).should == 1073741600
- (65536 * 65536).should == 4294967296
-
- (256 * bignum_value).should == 2361183241434822606848
- (6712 * 0.25).should == 1678.0
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13 * obj
- }.should raise_error(TypeError)
- lambda { 13 * "10" }.should raise_error(TypeError)
- lambda { 13 * :symbol }.should raise_error(TypeError)
- end
-
- it "overflows to Bignum when the result does not fit in Fixnum" do
- (fixnum_max * fixnum_max).should be_kind_of(Bignum)
- (fixnum_max * fixnum_min).should be_kind_of(Bignum)
- end
-
-end
diff --git a/spec/ruby/core/fixnum/odd_spec.rb b/spec/ruby/core/fixnum/odd_spec.rb
deleted file mode 100644
index 3cf6bf45ed..0000000000
--- a/spec/ruby/core/fixnum/odd_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#odd?" do
- it "is false for zero" do
- 0.odd?.should be_false
- end
-
- it "is false for even positive Fixnums" do
- 4.odd?.should be_false
- end
-
- it "is false for even negative Fixnums" do
- (-4).odd?.should be_false
- end
-
- it "is true for odd positive Fixnums" do
- 5.odd?.should be_true
- end
-
- it "is true for odd negative Fixnums" do
- (-5).odd?.should be_true
- end
-end
diff --git a/spec/ruby/core/fixnum/plus_spec.rb b/spec/ruby/core/fixnum/plus_spec.rb
deleted file mode 100644
index 4754bfeaf8..0000000000
--- a/spec/ruby/core/fixnum/plus_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#+" do
- it "returns self plus the given Integer" do
- (491 + 2).should == 493
- (90210 + 10).should == 90220
-
- (9 + bignum_value).should == 9223372036854775817
- (1001 + 5.219).should == 1006.219
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13 + obj
- }.should raise_error(TypeError)
- lambda { 13 + "10" }.should raise_error(TypeError)
- lambda { 13 + :symbol }.should raise_error(TypeError)
- end
-
- it "overflows to Bignum when the result does not fit in Fixnum" do
- (5 + 10).should be_an_instance_of Fixnum
- (1 + bignum_value).should be_an_instance_of Bignum
-
- bignum_zero = bignum_value.coerce(0).first
- (1 + bignum_zero).should be_an_instance_of Fixnum
- (fixnum_max + 1).should be_an_instance_of(Bignum)
- end
-end
diff --git a/spec/ruby/core/fixnum/right_shift_spec.rb b/spec/ruby/core/fixnum/right_shift_spec.rb
deleted file mode 100644
index 9a221ddbe7..0000000000
--- a/spec/ruby/core/fixnum/right_shift_spec.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#>> with n >> m" do
- it "returns n shifted right m bits when n > 0, m > 0" do
- (2 >> 1).should == 1
- end
-
- it "returns n shifted right m bits when n < 0, m > 0" do
- (-2 >> 1).should == -1
- (-7 >> 1).should == -4
- (-42 >> 2).should == -11
- end
-
- it "returns n shifted left m bits when n > 0, m < 0" do
- (1 >> -1).should == 2
- end
-
- it "returns n shifted left m bits when n < 0, m < 0" do
- (-1 >> -1).should == -2
- end
-
- it "returns 0 when n == 0" do
- (0 >> 1).should == 0
- end
-
- it "returns n when n > 0, m == 0" do
- (1 >> 0).should == 1
- end
-
- it "returns n when n < 0, m == 0" do
- (-1 >> 0).should == -1
- end
-
- it "returns 0 when n > 0, m > 0 and n < 2**m" do
- (3 >> 2).should == 0
- (7 >> 3).should == 0
- (127 >> 7).should == 0
-
- # To make sure the exponent is not truncated
- (7 >> 32).should == 0
- (7 >> 64).should == 0
- end
-
- it "returns -1 when n < 0, m > 0 and n > -(2**m)" do
- (-3 >> 2).should == -1
- (-7 >> 3).should == -1
- (-127 >> 7).should == -1
-
- # To make sure the exponent is not truncated
- (-7 >> 32).should == -1
- (-7 >> 64).should == -1
- end
-
- it "returns 0 when m is a Bignum" do
- (3 >> bignum_value).should == 0
- end
-
- it "returns a Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
- result = fixnum_max >> -1
- result.should be_an_instance_of(Bignum)
- result.should == fixnum_max * 2
- end
-
- it "returns a Bignum == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do
- result = fixnum_min >> -1
- result.should be_an_instance_of(Bignum)
- result.should == fixnum_min * 2
- end
-
- it "calls #to_int to convert the argument to an Integer" do
- obj = mock("2")
- obj.should_receive(:to_int).and_return(2)
-
- (8 >> obj).should == 2
- end
-
- it "raises a TypeError when #to_int does not return an Integer" do
- obj = mock("a string")
- obj.should_receive(:to_int).and_return("asdf")
-
- lambda { 3 >> obj }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed nil" do
- lambda { 3 >> nil }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed a String" do
- lambda { 3 >> "4" }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/shared/abs.rb b/spec/ruby/core/fixnum/shared/abs.rb
deleted file mode 100644
index 511ec5221b..0000000000
--- a/spec/ruby/core/fixnum/shared/abs.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :fixnum_abs, shared: true do
- it "returns self's absolute value" do
- { 0 => [0, -0, +0], 2 => [2, -2, +2], 100 => [100, -100, +100] }.each do |key, values|
- values.each do |value|
- value.send(@method).should == key
- end
- end
- end
-end
diff --git a/spec/ruby/core/fixnum/shared/equal.rb b/spec/ruby/core/fixnum/shared/equal.rb
deleted file mode 100644
index 01c763f316..0000000000
--- a/spec/ruby/core/fixnum/shared/equal.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-describe :fixnum_equal, shared: true do
- it "returns true if self has the same value as other" do
- 1.send(@method, 1).should == true
- 9.send(@method, 5).should == false
-
- # Actually, these call Float#==, Bignum#== etc.
- 9.send(@method, 9.0).should == true
- 9.send(@method, 9.01).should == false
-
- 10.send(@method, bignum_value).should == false
- end
-
- it "calls 'other == self' if the given argument is not a Fixnum" do
- 1.send(@method, '*').should == false
-
- obj = mock('one other')
- obj.should_receive(:==).any_number_of_times.and_return(false)
- 1.send(@method, obj).should == false
-
- obj = mock('another')
- obj.should_receive(:==).any_number_of_times.and_return(true)
- 2.send(@method, obj).should == true
- end
-end
diff --git a/spec/ruby/core/fixnum/shared/modulo.rb b/spec/ruby/core/fixnum/shared/modulo.rb
deleted file mode 100644
index a2f9a2691d..0000000000
--- a/spec/ruby/core/fixnum/shared/modulo.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-describe :fixnum_modulo, shared: true do
- it "returns the modulus obtained from dividing self by the given argument" do
- 13.send(@method, 4).should == 1
- 4.send(@method, 13).should == 4
-
- 13.send(@method, 4.0).should == 1
- 4.send(@method, 13.0).should == 4
-
- (-200).send(@method, 256).should == 56
- (-1000).send(@method, 512).should == 24
-
- (-200).send(@method, -256).should == -200
- (-1000).send(@method, -512).should == -488
-
- (200).send(@method, -256).should == -56
- (1000).send(@method, -512).should == -24
-
- 1.send(@method, 2.0).should == 1.0
- 200.send(@method, bignum_value).should == 200
- end
-
- it "raises a ZeroDivisionError when the given argument is 0" do
- lambda { 13.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { 0.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { -10.send(@method, 0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
- lambda { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- lambda { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- lambda { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- end
-
- it "raises a TypeError when given a non-Integer" do
- lambda {
- (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
- 13.send(@method, obj)
- }.should raise_error(TypeError)
- lambda { 13.send(@method, "10") }.should raise_error(TypeError)
- lambda { 13.send(@method, :symbol) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/fixnum/size_spec.rb b/spec/ruby/core/fixnum/size_spec.rb
deleted file mode 100644
index f973d446ed..0000000000
--- a/spec/ruby/core/fixnum/size_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#size" do
- platform_is wordsize: 32 do
- it "returns the number of bytes in the machine representation of self" do
- -1.size.should == 4
- 0.size.should == 4
- 4091.size.should == 4
- end
- end
-
- platform_is wordsize: 64 do
- it "returns the number of bytes in the machine representation of self" do
- -1.size.should == 8
- 0.size.should == 8
- 4091.size.should == 8
- end
- end
-end
diff --git a/spec/ruby/core/fixnum/succ_spec.rb b/spec/ruby/core/fixnum/succ_spec.rb
deleted file mode 100644
index 50dd8c9481..0000000000
--- a/spec/ruby/core/fixnum/succ_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#succ" do
- it "returns the next larger positive Fixnum" do
- 2.succ.should == 3
- end
-
- it "returns the next larger negative Fixnum" do
- (-2).succ.should == -1
- end
-
- it "overflows a Fixnum to a Bignum" do
- fixnum_max.succ.should == (fixnum_max + 1)
- end
-end
diff --git a/spec/ruby/core/fixnum/to_f_spec.rb b/spec/ruby/core/fixnum/to_f_spec.rb
deleted file mode 100644
index 1d66348a5a..0000000000
--- a/spec/ruby/core/fixnum/to_f_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#to_f" do
- it "returns self converted to a Float" do
- 0.to_f.should == 0.0
- -500.to_f.should == -500.0
- 9_641_278.to_f.should == 9641278.0
- end
-end
diff --git a/spec/ruby/core/fixnum/to_s_spec.rb b/spec/ruby/core/fixnum/to_s_spec.rb
deleted file mode 100644
index 4a6649237b..0000000000
--- a/spec/ruby/core/fixnum/to_s_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#to_s when given a base" do
- it "returns self converted to a String in the given base" do
- 12345.to_s(2).should == "11000000111001"
- 12345.to_s(8).should == "30071"
- 12345.to_s(10).should == "12345"
- 12345.to_s(16).should == "3039"
- 95.to_s(16).should == "5f"
- 12345.to_s(36).should == "9ix"
- end
-
- it "raises an ArgumentError if the base is less than 2 or higher than 36" do
- lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
- lambda { 123.to_s(0) }.should raise_error(ArgumentError)
- lambda { 123.to_s(1) }.should raise_error(ArgumentError)
- lambda { 123.to_s(37) }.should raise_error(ArgumentError)
- end
-end
-
-describe "Fixnum#to_s when no base given" do
- it "returns self converted to a String using base 10" do
- 255.to_s.should == '255'
- 3.to_s.should == '3'
- 0.to_s.should == '0'
- -9002.to_s.should == '-9002'
- end
-end
-
-with_feature :encoding do
- describe "Fixnum#to_s" do
- before :each do
- @internal = Encoding.default_internal
- end
-
- after :each do
- Encoding.default_internal = @internal
- end
-
- it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- 1.to_s.encoding.should equal(Encoding::US_ASCII)
- end
-
- it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
- Encoding.default_internal = Encoding::IBM437
- 1.to_s.encoding.should equal(Encoding::US_ASCII)
- end
- end
-end
diff --git a/spec/ruby/core/fixnum/uminus_spec.rb b/spec/ruby/core/fixnum/uminus_spec.rb
deleted file mode 100644
index ac676400d1..0000000000
--- a/spec/ruby/core/fixnum/uminus_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#-@" do
- it "returns self as a negative value" do
- 2.send(:-@).should == -2
- -2.should == -2
- -268435455.should == -268435455
- (--5).should == 5
- -8.send(:-@).should == 8
- end
-
- it "negates self at Fixnum/Bignum boundaries" do
- fixnum_max.send(:-@).should == (0 - fixnum_max)
- fixnum_min.send(:-@).should == (0 - fixnum_min)
- end
-end
diff --git a/spec/ruby/core/fixnum/zero_spec.rb b/spec/ruby/core/fixnum/zero_spec.rb
deleted file mode 100644
index e155f9f5e6..0000000000
--- a/spec/ruby/core/fixnum/zero_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#zero?" do
- it "returns true if self is 0" do
- 0.zero?.should == true
- -1.zero?.should == false
- 1.zero?.should == false
- end
-end
diff --git a/spec/ruby/core/float/abs_spec.rb b/spec/ruby/core/float/abs_spec.rb
index 3ff2e4369b..58e87c7602 100644
--- a/spec/ruby/core/float/abs_spec.rb
+++ b/spec/ruby/core/float/abs_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../shared/abs', __FILE__)
describe "Float#abs" do
- it_behaves_like(:float_abs, :abs)
+ it_behaves_like :float_abs, :abs
end
diff --git a/spec/ruby/core/float/magnitude_spec.rb b/spec/ruby/core/float/magnitude_spec.rb
index 042356f4c4..95b4efc158 100644
--- a/spec/ruby/core/float/magnitude_spec.rb
+++ b/spec/ruby/core/float/magnitude_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../shared/abs', __FILE__)
describe "Float#magnitude" do
- it_behaves_like(:float_abs, :magnitude)
+ it_behaves_like :float_abs, :magnitude
end
diff --git a/spec/ruby/core/float/modulo_spec.rb b/spec/ruby/core/float/modulo_spec.rb
index f29e3870da..fffa6cab67 100644
--- a/spec/ruby/core/float/modulo_spec.rb
+++ b/spec/ruby/core/float/modulo_spec.rb
@@ -2,9 +2,9 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/modulo', __FILE__)
describe "Float#%" do
- it_behaves_like(:float_modulo, :%)
+ it_behaves_like :float_modulo, :%
end
describe "Float#modulo" do
- it_behaves_like(:float_modulo, :modulo)
+ it_behaves_like :float_modulo, :modulo
end
diff --git a/spec/ruby/core/float/to_i_spec.rb b/spec/ruby/core/float/to_i_spec.rb
index 5bf5a1b42a..899e179678 100644
--- a/spec/ruby/core/float/to_i_spec.rb
+++ b/spec/ruby/core/float/to_i_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Float#to_i" do
- it_behaves_like(:float_to_i, :to_i)
+ it_behaves_like :float_to_i, :to_i
end
diff --git a/spec/ruby/core/float/to_int_spec.rb b/spec/ruby/core/float/to_int_spec.rb
index ba31ebc168..c37ccdaa91 100644
--- a/spec/ruby/core/float/to_int_spec.rb
+++ b/spec/ruby/core/float/to_int_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Float#to_int" do
- it_behaves_like(:float_to_i, :to_int)
+ it_behaves_like :float_to_i, :to_int
end
diff --git a/spec/ruby/core/float/truncate_spec.rb b/spec/ruby/core/float/truncate_spec.rb
index 7feeb81735..097aa751a4 100644
--- a/spec/ruby/core/float/truncate_spec.rb
+++ b/spec/ruby/core/float/truncate_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Float#truncate" do
- it_behaves_like(:float_to_i, :truncate)
+ it_behaves_like :float_to_i, :truncate
ruby_version_is "2.4" do
it "returns self truncated to an optionally given precision" do
diff --git a/spec/ruby/core/hash/delete_if_spec.rb b/spec/ruby/core/hash/delete_if_spec.rb
index 2edc88a205..93dab192b5 100644
--- a/spec/ruby/core/hash/delete_if_spec.rb
+++ b/spec/ruby/core/hash/delete_if_spec.rb
@@ -39,6 +39,6 @@ describe "Hash#delete_if" do
lambda { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(frozen_error_class)
end
- it_behaves_like(:hash_iteration_no_block, :delete_if)
- it_behaves_like(:enumeratorized_with_origin_size, :delete_if, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :delete_if
+ it_behaves_like :enumeratorized_with_origin_size, :delete_if, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/each_key_spec.rb b/spec/ruby/core/hash/each_key_spec.rb
index 4a4078a594..9cc31d803c 100644
--- a/spec/ruby/core/hash/each_key_spec.rb
+++ b/spec/ruby/core/hash/each_key_spec.rb
@@ -18,6 +18,6 @@ describe "Hash#each_key" do
keys.should == h.keys
end
- it_behaves_like(:hash_iteration_no_block, :each_key)
- it_behaves_like(:enumeratorized_with_origin_size, :each_key, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :each_key
+ it_behaves_like :enumeratorized_with_origin_size, :each_key, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/each_pair_spec.rb b/spec/ruby/core/hash/each_pair_spec.rb
index 285ca01b26..3fa07c8b67 100644
--- a/spec/ruby/core/hash/each_pair_spec.rb
+++ b/spec/ruby/core/hash/each_pair_spec.rb
@@ -5,7 +5,7 @@ require File.expand_path('../shared/each', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "Hash#each_pair" do
- it_behaves_like(:hash_each, :each_pair)
- it_behaves_like(:hash_iteration_no_block, :each_pair)
- it_behaves_like(:enumeratorized_with_origin_size, :each_pair, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_each, :each_pair
+ it_behaves_like :hash_iteration_no_block, :each_pair
+ it_behaves_like :enumeratorized_with_origin_size, :each_pair, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/each_spec.rb b/spec/ruby/core/hash/each_spec.rb
index 676fd284b9..261d46c5a4 100644
--- a/spec/ruby/core/hash/each_spec.rb
+++ b/spec/ruby/core/hash/each_spec.rb
@@ -5,7 +5,7 @@ require File.expand_path('../shared/each', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
describe "Hash#each" do
- it_behaves_like(:hash_each, :each)
- it_behaves_like(:hash_iteration_no_block, :each)
- it_behaves_like(:enumeratorized_with_origin_size, :each, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_each, :each
+ it_behaves_like :hash_iteration_no_block, :each
+ it_behaves_like :enumeratorized_with_origin_size, :each, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/each_value_spec.rb b/spec/ruby/core/hash/each_value_spec.rb
index d3b2b8692e..f203675386 100644
--- a/spec/ruby/core/hash/each_value_spec.rb
+++ b/spec/ruby/core/hash/each_value_spec.rb
@@ -18,6 +18,6 @@ describe "Hash#each_value" do
values.should == h.values
end
- it_behaves_like(:hash_iteration_no_block, :each_value)
- it_behaves_like(:enumeratorized_with_origin_size, :each_value, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :each_value
+ it_behaves_like :enumeratorized_with_origin_size, :each_value, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/element_set_spec.rb b/spec/ruby/core/hash/element_set_spec.rb
index a2d67c7f22..e12356a1e5 100644
--- a/spec/ruby/core/hash/element_set_spec.rb
+++ b/spec/ruby/core/hash/element_set_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/store', __FILE__)
describe "Hash#[]=" do
- it_behaves_like(:hash_store, :[]=)
+ it_behaves_like :hash_store, :[]=
end
diff --git a/spec/ruby/core/hash/fetch_spec.rb b/spec/ruby/core/hash/fetch_spec.rb
index 5e701b1162..24662c2b0e 100644
--- a/spec/ruby/core/hash/fetch_spec.rb
+++ b/spec/ruby/core/hash/fetch_spec.rb
@@ -1,15 +1,17 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../../../shared/hash/key_error', __FILE__)
describe "Hash#fetch" do
- it "returns the value for key" do
- { a: 1, b: -1 }.fetch(:b).should == -1
+ context "when the key is not found" do
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new(a: 5)
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, {}
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new { 5 }
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch(key) }, Hash.new(5)
end
- it "raises a KeyError if key is not found" do
- lambda { {}.fetch(:a) }.should raise_error(KeyError)
- lambda { Hash.new(5).fetch(:a) }.should raise_error(KeyError)
- lambda { Hash.new { 5 }.fetch(:a) }.should raise_error(KeyError)
+ it "returns the value for key" do
+ { a: 1, b: -1 }.fetch(:b).should == -1
end
it "returns default if key is not found when passed a default" do
diff --git a/spec/ruby/core/hash/fetch_values_spec.rb b/spec/ruby/core/hash/fetch_values_spec.rb
index d6e47d5885..0d7c9599e7 100644
--- a/spec/ruby/core/hash/fetch_values_spec.rb
+++ b/spec/ruby/core/hash/fetch_values_spec.rb
@@ -1,5 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../../../shared/hash/key_error', __FILE__)
ruby_version_is "2.3" do
describe "Hash#fetch_values" do
@@ -15,10 +16,7 @@ ruby_version_is "2.3" do
end
describe "with unmatched keys" do
- it "raises a KeyError" do
- ->{ @hash.fetch_values :z }.should raise_error(KeyError)
- ->{ @hash.fetch_values :a, :z }.should raise_error(KeyError)
- end
+ it_behaves_like :key_error, ->(obj, key) { obj.fetch_values(key) }, Hash.new(a: 5)
it "returns the default value from block" do
@hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"]
diff --git a/spec/ruby/core/hash/has_key_spec.rb b/spec/ruby/core/hash/has_key_spec.rb
index 1d2aa279f1..90762ec4f3 100644
--- a/spec/ruby/core/hash/has_key_spec.rb
+++ b/spec/ruby/core/hash/has_key_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/key', __FILE__)
describe "Hash#has_key?" do
- it_behaves_like(:hash_key_p, :has_key?)
+ it_behaves_like :hash_key_p, :has_key?
end
diff --git a/spec/ruby/core/hash/has_value_spec.rb b/spec/ruby/core/hash/has_value_spec.rb
index dc8fdf9b69..c5fa12c8c3 100644
--- a/spec/ruby/core/hash/has_value_spec.rb
+++ b/spec/ruby/core/hash/has_value_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/value', __FILE__)
describe "Hash#has_value?" do
- it_behaves_like(:hash_value_p, :has_value?)
+ it_behaves_like :hash_value_p, :has_value?
end
diff --git a/spec/ruby/core/hash/include_spec.rb b/spec/ruby/core/hash/include_spec.rb
index 8731673c19..118dff2798 100644
--- a/spec/ruby/core/hash/include_spec.rb
+++ b/spec/ruby/core/hash/include_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/key', __FILE__)
describe "Hash#include?" do
- it_behaves_like(:hash_key_p, :include?)
+ it_behaves_like :hash_key_p, :include?
end
diff --git a/spec/ruby/core/hash/keep_if_spec.rb b/spec/ruby/core/hash/keep_if_spec.rb
index 7a9db092e2..0879d415b8 100644
--- a/spec/ruby/core/hash/keep_if_spec.rb
+++ b/spec/ruby/core/hash/keep_if_spec.rb
@@ -32,6 +32,6 @@ describe "Hash#keep_if" do
lambda { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(frozen_error_class)
end
- it_behaves_like(:hash_iteration_no_block, :keep_if)
- it_behaves_like(:enumeratorized_with_origin_size, :keep_if, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :keep_if
+ it_behaves_like :enumeratorized_with_origin_size, :keep_if, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/key_spec.rb b/spec/ruby/core/hash/key_spec.rb
index dc78174641..da3c5de972 100644
--- a/spec/ruby/core/hash/key_spec.rb
+++ b/spec/ruby/core/hash/key_spec.rb
@@ -4,9 +4,9 @@ require File.expand_path('../shared/key', __FILE__)
require File.expand_path('../shared/index', __FILE__)
describe "Hash#key?" do
- it_behaves_like(:hash_key_p, :key?)
+ it_behaves_like :hash_key_p, :key?
end
describe "Hash#key" do
- it_behaves_like(:hash_index, :key)
+ it_behaves_like :hash_index, :key
end
diff --git a/spec/ruby/core/hash/length_spec.rb b/spec/ruby/core/hash/length_spec.rb
index 90751402eb..da8d0cb811 100644
--- a/spec/ruby/core/hash/length_spec.rb
+++ b/spec/ruby/core/hash/length_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "Hash#length" do
- it_behaves_like(:hash_length, :length)
+ it_behaves_like :hash_length, :length
end
diff --git a/spec/ruby/core/hash/member_spec.rb b/spec/ruby/core/hash/member_spec.rb
index 376bb4c006..154a042010 100644
--- a/spec/ruby/core/hash/member_spec.rb
+++ b/spec/ruby/core/hash/member_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/key', __FILE__)
describe "Hash#member?" do
- it_behaves_like(:hash_key_p, :member?)
+ it_behaves_like :hash_key_p, :member?
end
diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb
index 21401ffd08..24852df303 100644
--- a/spec/ruby/core/hash/merge_spec.rb
+++ b/spec/ruby/core/hash/merge_spec.rb
@@ -66,7 +66,7 @@ describe "Hash#merge" do
end
describe "Hash#merge!" do
- it_behaves_like(:hash_update, :merge!)
+ it_behaves_like :hash_update, :merge!
it "does not raise an exception if changing the value of an existing key during iteration" do
hash = {1 => 2, 3 => 4, 5 => 6}
diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb
index 5b15af923a..f44b42eecf 100644
--- a/spec/ruby/core/hash/rehash_spec.rb
+++ b/spec/ruby/core/hash/rehash_spec.rb
@@ -35,6 +35,21 @@ describe "Hash#rehash" do
h[k2].should == v2
end
+ it "removes duplicate keys" do
+ a = [1,2]
+ b = [1]
+
+ h = {}
+ h[a] = true
+ h[b] = true
+ b << 2
+ h.size.should == 2
+ h.keys.should == [a, b]
+ h.rehash
+ h.size.should == 1
+ h.keys.should == [a]
+ end
+
it "raises a #{frozen_error_class} if called on a frozen instance" do
lambda { HashSpecs.frozen_hash.rehash }.should raise_error(frozen_error_class)
lambda { HashSpecs.empty_frozen_hash.rehash }.should raise_error(frozen_error_class)
diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb
index 557435a019..fe2bec42d7 100644
--- a/spec/ruby/core/hash/reject_spec.rb
+++ b/spec/ruby/core/hash/reject_spec.rb
@@ -49,8 +49,8 @@ describe "Hash#reject" do
reject_pairs.should == reject_bang_pairs
end
- it_behaves_like(:hash_iteration_no_block, :reject)
- it_behaves_like(:enumeratorized_with_origin_size, :reject, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :reject
+ it_behaves_like :enumeratorized_with_origin_size, :reject, { 1 => 2, 3 => 4, 5 => 6 }
end
describe "Hash#reject!" do
@@ -95,6 +95,6 @@ describe "Hash#reject!" do
lambda { HashSpecs.frozen_hash.reject! { false } }.should raise_error(frozen_error_class)
end
- it_behaves_like(:hash_iteration_no_block, :reject!)
- it_behaves_like(:enumeratorized_with_origin_size, :reject!, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :reject!
+ it_behaves_like :enumeratorized_with_origin_size, :reject!, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/replace_spec.rb b/spec/ruby/core/hash/replace_spec.rb
index 61b3164355..642c78d63c 100644
--- a/spec/ruby/core/hash/replace_spec.rb
+++ b/spec/ruby/core/hash/replace_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/replace', __FILE__)
describe "Hash#replace" do
- it_behaves_like(:hash_replace, :replace)
+ it_behaves_like :hash_replace, :replace
end
diff --git a/spec/ruby/core/hash/select_spec.rb b/spec/ruby/core/hash/select_spec.rb
index 8a73116bc1..9348cc4c39 100644
--- a/spec/ruby/core/hash/select_spec.rb
+++ b/spec/ruby/core/hash/select_spec.rb
@@ -40,8 +40,8 @@ describe "Hash#select" do
@empty.select.should be_an_instance_of(Enumerator)
end
- it_behaves_like(:hash_iteration_no_block, :select)
- it_behaves_like(:enumeratorized_with_origin_size, :select, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :select
+ it_behaves_like :enumeratorized_with_origin_size, :select, { 1 => 2, 3 => 4, 5 => 6 }
end
describe "Hash#select!" do
@@ -78,6 +78,6 @@ describe "Hash#select!" do
lambda { HashSpecs.frozen_hash.select! { true } }.should raise_error(frozen_error_class)
end
- it_behaves_like(:hash_iteration_no_block, :select!)
- it_behaves_like(:enumeratorized_with_origin_size, :select!, { 1 => 2, 3 => 4, 5 => 6 })
+ it_behaves_like :hash_iteration_no_block, :select!
+ it_behaves_like :enumeratorized_with_origin_size, :select!, { 1 => 2, 3 => 4, 5 => 6 }
end
diff --git a/spec/ruby/core/hash/size_spec.rb b/spec/ruby/core/hash/size_spec.rb
index 71660af038..7143a1cb82 100644
--- a/spec/ruby/core/hash/size_spec.rb
+++ b/spec/ruby/core/hash/size_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "Hash#size" do
- it_behaves_like(:hash_length, :size)
+ it_behaves_like :hash_length, :size
end
diff --git a/spec/ruby/core/hash/store_spec.rb b/spec/ruby/core/hash/store_spec.rb
index 45ea8da896..847c2f54e3 100644
--- a/spec/ruby/core/hash/store_spec.rb
+++ b/spec/ruby/core/hash/store_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/store', __FILE__)
describe "Hash#store" do
- it_behaves_like(:hash_store, :store)
+ it_behaves_like :hash_store, :store
end
diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb
index 30dde2287b..14d5d98117 100644
--- a/spec/ruby/core/hash/transform_keys_spec.rb
+++ b/spec/ruby/core/hash/transform_keys_spec.rb
@@ -60,17 +60,39 @@ ruby_version_is "2.5" do
@hash.should == { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 }
end
- it "prevents conflicts between new keys and old ones" do
- @hash.transform_keys!(&:succ)
- @hash.should == { b: 1, c: 2, d: 3, e: 4 }
+ # https://bugs.ruby-lang.org/issues/14380
+ ruby_version_is ""..."2.6" do
+ it "does not prevent conflicts between new keys and old ones" do
+ @hash.transform_keys!(&:succ)
+ @hash.should == { e: 1 }
+ end
end
- it "partially modifies the contents if we broke from the block" do
- @hash.transform_keys! do |v|
- break if v == :c
- v.succ
+ ruby_version_is "2.6" do
+ it "prevents conflicts between new keys and old ones" do
+ @hash.transform_keys!(&:succ)
+ @hash.should == { b: 1, c: 2, d: 3, e: 4 }
+ end
+ end
+
+ ruby_version_is ""..."2.6" do
+ it "partially modifies the contents if we broke from the block" do
+ @hash.transform_keys! do |v|
+ break if v == :c
+ v.succ
+ end
+ @hash.should == { c: 1, d: 4 }
+ end
+ end
+
+ ruby_version_is "2.6" do
+ it "returns the processed keys if we broke from the block" do
+ @hash.transform_keys! do |v|
+ break if v == :c
+ v.succ
+ end
+ @hash.should == { b: 1, c: 2 }
end
- @hash.should == { b: 1, c: 2 }
end
it "keeps later pair if new keys conflict" do
diff --git a/spec/ruby/core/hash/update_spec.rb b/spec/ruby/core/hash/update_spec.rb
index 6cfedea271..033e3d35b0 100644
--- a/spec/ruby/core/hash/update_spec.rb
+++ b/spec/ruby/core/hash/update_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/update', __FILE__)
describe "Hash#update" do
- it_behaves_like(:hash_update, :update)
+ it_behaves_like :hash_update, :update
end
diff --git a/spec/ruby/core/hash/value_spec.rb b/spec/ruby/core/hash/value_spec.rb
index acfe1968d5..9681f4d827 100644
--- a/spec/ruby/core/hash/value_spec.rb
+++ b/spec/ruby/core/hash/value_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/value', __FILE__)
describe "Hash#value?" do
- it_behaves_like(:hash_value_p, :value?)
+ it_behaves_like :hash_value_p, :value?
end
diff --git a/spec/ruby/core/hash/values_at_spec.rb b/spec/ruby/core/hash/values_at_spec.rb
index 7c39e9b573..859034ecd2 100644
--- a/spec/ruby/core/hash/values_at_spec.rb
+++ b/spec/ruby/core/hash/values_at_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/values_at', __FILE__)
describe "Hash#values_at" do
- it_behaves_like(:hash_values_at, :values_at)
+ it_behaves_like :hash_values_at, :values_at
end
diff --git a/spec/ruby/core/bignum/abs_spec.rb b/spec/ruby/core/integer/abs_spec.rb
index b551dd95ad..4f16d2c4b3 100644
--- a/spec/ruby/core/bignum/abs_spec.rb
+++ b/spec/ruby/core/integer/abs_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/abs', __FILE__)
-describe "Bignum#abs" do
- it_behaves_like(:bignum_abs, :abs)
+describe "Integer#abs" do
+ it_behaves_like :integer_abs, :abs
end
diff --git a/spec/ruby/core/integer/bit_and_spec.rb b/spec/ruby/core/integer/bit_and_spec.rb
new file mode 100644
index 0000000000..75cd561e42
--- /dev/null
+++ b/spec/ruby/core/integer/bit_and_spec.rb
@@ -0,0 +1,97 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#&" do
+ context "fixnum" do
+ it "returns self bitwise AND other" do
+ (256 & 16).should == 0
+ (2010 & 5).should == 0
+ (65535 & 1).should == 1
+ (0xffff & bignum_value + 0xffff_ffff).should == 65535
+ end
+
+ it "returns self bitwise AND other when one operand is negative" do
+ ((1 << 33) & -1).should == (1 << 33)
+ (-1 & (1 << 33)).should == (1 << 33)
+
+ ((-(1<<33)-1) & 5).should == 5
+ (5 & (-(1<<33)-1)).should == 5
+ end
+
+ it "returns self bitwise AND other when both operands are negative" do
+ (-5 & -1).should == -5
+ (-3 & -4).should == -4
+ (-12 & -13).should == -16
+ (-13 & -12).should == -16
+ end
+
+ it "returns self bitwise AND a bignum" do
+ (-1 & 2**64).should == 18446744073709551616
+ end
+
+ it "coerces the rhs and calls #coerce" do
+ obj = mock("fixnum bit and")
+ obj.should_receive(:coerce).with(6).and_return([3, 6])
+ (6 & obj).should == 2
+ end
+
+ it "raises a TypeError when passed a Float" do
+ lambda { (3 & 3.4) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("fixnum bit and")
+ obj.should_not_receive(:to_int)
+
+ lambda { 3 & obj }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(5)
+ end
+
+ it "returns self bitwise AND other" do
+ @bignum = bignum_value(5)
+ (@bignum & 3).should == 1
+ (@bignum & 52).should == 4
+ (@bignum & bignum_value(9921)).should == 9223372036854775809
+
+ ((2*bignum_value) & 1).should == 0
+ ((2*bignum_value) & (2*bignum_value)).should == 18446744073709551616
+ end
+
+ it "returns self bitwise AND other when one operand is negative" do
+ ((2*bignum_value) & -1).should == (2*bignum_value)
+ ((4*bignum_value) & -1).should == (4*bignum_value)
+ (@bignum & -0xffffffffffffff5).should == 9223372036854775809
+ (@bignum & -@bignum).should == 1
+ (@bignum & -0x8000000000000000).should == 9223372036854775808
+ end
+
+ it "returns self bitwise AND other when both operands are negative" do
+ (-@bignum & -0x4000000000000005).should == -13835058055282163717
+ (-@bignum & -@bignum).should == -9223372036854775813
+ (-@bignum & -0x4000000000000000).should == -13835058055282163712
+ end
+
+ it "returns self bitwise AND other when both are negative and a multiple in bitsize of Fixnum::MIN" do
+ val = - ((1 << 93) - 1)
+ (val & val).should == val
+
+ val = - ((1 << 126) - 1)
+ (val & val).should == val
+ end
+
+ it "raises a TypeError when passed a Float" do
+ lambda { (@bignum & 3.4) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("bignum bit and")
+ obj.should_not_receive(:to_int)
+
+ lambda { @bignum & obj }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/bit_length_spec.rb b/spec/ruby/core/integer/bit_length_spec.rb
new file mode 100644
index 0000000000..9a2065af33
--- /dev/null
+++ b/spec/ruby/core/integer/bit_length_spec.rb
@@ -0,0 +1,76 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#bit_length" do
+ context "fixnum" do
+ it "returns the position of the leftmost bit of a positive number" do
+ 0.bit_length.should == 0
+ 1.bit_length.should == 1
+ 2.bit_length.should == 2
+ 3.bit_length.should == 2
+ 4.bit_length.should == 3
+ n = fixnum_max.bit_length
+ fixnum_max[n].should == 0
+ fixnum_max[n - 1].should == 1
+
+ 0.bit_length.should == 0
+ 1.bit_length.should == 1
+ 0xff.bit_length.should == 8
+ 0x100.bit_length.should == 9
+ (2**12 - 1).bit_length.should == 12
+ (2**12).bit_length.should == 13
+ (2**12 + 1).bit_length.should == 13
+ end
+
+ it "returns the position of the leftmost 0 bit of a negative number" do
+ -1.bit_length.should == 0
+ -2.bit_length.should == 1
+ -3.bit_length.should == 2
+ -4.bit_length.should == 2
+ -5.bit_length.should == 3
+ n = fixnum_min.bit_length
+ fixnum_min[n].should == 1
+ fixnum_min[n - 1].should == 0
+
+ (-2**12 - 1).bit_length.should == 13
+ (-2**12).bit_length.should == 12
+ (-2**12 + 1).bit_length.should == 12
+ -0x101.bit_length.should == 9
+ -0x100.bit_length.should == 8
+ -0xff.bit_length.should == 8
+ -2.bit_length.should == 1
+ -1.bit_length.should == 0
+ end
+ end
+
+ context "bignum" do
+ it "returns the position of the leftmost bit of a positive number" do
+ (2**1000-1).bit_length.should == 1000
+ (2**1000).bit_length.should == 1001
+ (2**1000+1).bit_length.should == 1001
+
+ (2**10000-1).bit_length.should == 10000
+ (2**10000).bit_length.should == 10001
+ (2**10000+1).bit_length.should == 10001
+
+ (1 << 100).bit_length.should == 101
+ (1 << 100).succ.bit_length.should == 101
+ (1 << 100).pred.bit_length.should == 100
+ (1 << 10000).bit_length.should == 10001
+ end
+
+ it "returns the position of the leftmost 0 bit of a negative number" do
+ (-2**10000-1).bit_length.should == 10001
+ (-2**10000).bit_length.should == 10000
+ (-2**10000+1).bit_length.should == 10000
+
+ (-2**1000-1).bit_length.should == 1001
+ (-2**1000).bit_length.should == 1000
+ (-2**1000+1).bit_length.should == 1000
+
+ ((-1 << 100)-1).bit_length.should == 101
+ ((-1 << 100)-1).succ.bit_length.should == 100
+ ((-1 << 100)-1).pred.bit_length.should == 101
+ ((-1 << 10000)-1).bit_length.should == 10001
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/bit_or_spec.rb b/spec/ruby/core/integer/bit_or_spec.rb
new file mode 100644
index 0000000000..61da1676c9
--- /dev/null
+++ b/spec/ruby/core/integer/bit_or_spec.rb
@@ -0,0 +1,68 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#|" do
+ context "fixnum" do
+ it "returns self bitwise OR other" do
+ (1 | 0).should == 1
+ (5 | 4).should == 5
+ (5 | 6).should == 7
+ (248 | 4096).should == 4344
+ (0xffff | bignum_value + 0xf0f0).should == 0x8000_0000_0000_ffff
+ end
+
+ it "returns self bitwise OR a bignum" do
+ (-1 | 2**64).should == -1
+ end
+
+ it "raises a TypeError when passed a Float" do
+ lambda { (3 | 3.4) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("integer bit or")
+ obj.should_not_receive(:to_int)
+
+ lambda { 3 | obj }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(11)
+ end
+
+ it "returns self bitwise OR other" do
+ (@bignum | 2).should == 9223372036854775819
+ (@bignum | 9).should == 9223372036854775819
+ (@bignum | bignum_value).should == 9223372036854775819
+ end
+
+ it "returns self bitwise OR other when one operand is negative" do
+ (@bignum | -0x40000000000000000).should == -64563604257983430645
+ (@bignum | -@bignum).should == -1
+ (@bignum | -0x8000000000000000).should == -9223372036854775797
+ end
+
+ it "returns self bitwise OR other when both operands are negative" do
+ (-@bignum | -0x4000000000000005).should == -1
+ (-@bignum | -@bignum).should == -9223372036854775819
+ (-@bignum | -0x4000000000000000).should == -11
+ end
+
+ it "raises a TypeError when passed a Float" do
+ not_supported_on :opal do
+ lambda {
+ bignum_value | bignum_value(0xffff).to_f
+ }.should raise_error(TypeError)
+ end
+ lambda { @bignum | 9.9 }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("bignum bit or")
+ obj.should_not_receive(:to_int)
+
+ lambda { @bignum | obj }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/bit_xor_spec.rb b/spec/ruby/core/integer/bit_xor_spec.rb
new file mode 100644
index 0000000000..f9e2fd74cb
--- /dev/null
+++ b/spec/ruby/core/integer/bit_xor_spec.rb
@@ -0,0 +1,72 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#^" do
+ context "fixnum" do
+ it "returns self bitwise EXCLUSIVE OR other" do
+ (3 ^ 5).should == 6
+ (-2 ^ -255).should == 255
+ (5 ^ bignum_value + 0xffff_ffff).should == 0x8000_0000_ffff_fffa
+ end
+
+ it "returns self bitwise EXCLUSIVE OR a bignum" do
+ (-1 ^ 2**64).should == -18446744073709551617
+ end
+
+ it "raises a TypeError when passed a Float" do
+ lambda { (3 ^ 3.4) }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("integer bit xor")
+ obj.should_not_receive(:to_int)
+
+ lambda { 3 ^ obj }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(18)
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other" do
+ (@bignum ^ 2).should == 9223372036854775824
+ (@bignum ^ @bignum).should == 0
+ (@bignum ^ 14).should == 9223372036854775836
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other when one operand is negative" do
+ (@bignum ^ -0x40000000000000000).should == -64563604257983430638
+ (@bignum ^ -@bignum).should == -4
+ (@bignum ^ -0x8000000000000000).should == -18446744073709551598
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other when both operands are negative" do
+ (-@bignum ^ -0x40000000000000000).should == 64563604257983430638
+ (-@bignum ^ -@bignum).should == 0
+ (-@bignum ^ -0x4000000000000000).should == 13835058055282163694
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other when all bits are 1 and other value is negative" do
+ (9903520314283042199192993791 ^ -1).should == -9903520314283042199192993792
+ (784637716923335095479473677900958302012794430558004314111 ^ -1).should ==
+ -784637716923335095479473677900958302012794430558004314112
+ end
+
+ it "raises a TypeError when passed a Float" do
+ not_supported_on :opal do
+ lambda {
+ bignum_value ^ bignum_value(0xffff).to_f
+ }.should raise_error(TypeError)
+ end
+ lambda { @bignum ^ 14.5 }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError and does not call #to_int when defined on an object" do
+ obj = mock("bignum bit xor")
+ obj.should_not_receive(:to_int)
+
+ lambda { @bignum ^ obj }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/fixnum/case_compare_spec.rb b/spec/ruby/core/integer/case_compare_spec.rb
index 53bfc38eb8..24f8580823 100644
--- a/spec/ruby/core/fixnum/case_compare_spec.rb
+++ b/spec/ruby/core/integer/case_compare_spec.rb
@@ -1,6 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal', __FILE__)
-describe "Fixnum#===" do
- it_behaves_like :fixnum_equal, :===
+describe "Integer#===" do
+ it_behaves_like :integer_equal, :===
end
diff --git a/spec/ruby/core/integer/ceil_spec.rb b/spec/ruby/core/integer/ceil_spec.rb
index 31c56f378d..8a0754475f 100644
--- a/spec/ruby/core/integer/ceil_spec.rb
+++ b/spec/ruby/core/integer/ceil_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../shared/to_i', __FILE__)
require File.expand_path('../shared/integer_rounding', __FILE__)
describe "Integer#ceil" do
- it_behaves_like(:integer_to_i, :ceil)
- it_behaves_like(:integer_rounding_positive_precision, :ceil)
+ it_behaves_like :integer_to_i, :ceil
+ it_behaves_like :integer_rounding_positive_precision, :ceil
ruby_version_is "2.4" do
context "precision argument specified as part of the ceil method is negative" do
diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb
index 50a678608e..1a3bed5c76 100644
--- a/spec/ruby/core/integer/chr_spec.rb
+++ b/spec/ruby/core/integer/chr_spec.rb
@@ -165,6 +165,10 @@ describe "Integer#chr with an encoding argument" do
lambda { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
end
+ it "raises a RangeError if self is too large" do
+ lambda { 2206368128.chr(Encoding::UTF_8) }.should raise_error(RangeError)
+ end
+
it "returns a String with the specified encoding" do
0x0000.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII
0x007F.chr(Encoding::US_ASCII).encoding.should == Encoding::US_ASCII
diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb
new file mode 100644
index 0000000000..58e0aadc0a
--- /dev/null
+++ b/spec/ruby/core/integer/coerce_spec.rb
@@ -0,0 +1,105 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#coerce" do
+ context "fixnum" do
+ describe "when given a Fixnum" do
+ it "returns an array containing two Fixnums" do
+ 1.coerce(2).should == [2, 1]
+ 1.coerce(2).map { |i| i.class }.should == [Fixnum, Fixnum]
+ end
+ end
+
+ describe "when given a String" do
+ it "raises an ArgumentError when trying to coerce with a non-number String" do
+ lambda { 1.coerce(":)") }.should raise_error(ArgumentError)
+ end
+
+ it "returns an array containing two Floats" do
+ 1.coerce("2").should == [2.0, 1.0]
+ 1.coerce("-2").should == [-2.0, 1.0]
+ end
+ end
+
+ it "raises a TypeError when trying to coerce with nil" do
+ lambda { 1.coerce(nil) }.should raise_error(TypeError)
+ end
+
+ it "tries to convert the given Object into a Float by using #to_f" do
+ (obj = mock('1.0')).should_receive(:to_f).and_return(1.0)
+ 2.coerce(obj).should == [1.0, 2.0]
+
+ (obj = mock('0')).should_receive(:to_f).and_return('0')
+ lambda { 2.coerce(obj).should == [1.0, 2.0] }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when given an Object that does not respond to #to_f" do
+ lambda { 1.coerce(mock('x')) }.should raise_error(TypeError)
+ lambda { 1.coerce(1..4) }.should raise_error(TypeError)
+ lambda { 1.coerce(:test) }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ it "coerces other to a Bignum and returns [other, self] when passed a Fixnum" do
+ a = bignum_value
+ ary = a.coerce(2)
+
+ ary[0].should be_kind_of(Bignum)
+ ary[1].should be_kind_of(Bignum)
+ ary.should == [2, a]
+ end
+
+ it "returns [other, self] when passed a Bignum" do
+ a = bignum_value
+ b = bignum_value
+ ary = a.coerce(b)
+
+ ary[0].should be_kind_of(Bignum)
+ ary[1].should be_kind_of(Bignum)
+ ary.should == [b, a]
+ end
+
+ it "raises a TypeError when not passed a Fixnum or Bignum" do
+ a = bignum_value
+
+ lambda { a.coerce(nil) }.should raise_error(TypeError)
+ lambda { a.coerce(mock('str')) }.should raise_error(TypeError)
+ lambda { a.coerce(1..4) }.should raise_error(TypeError)
+ lambda { a.coerce(:test) }.should raise_error(TypeError)
+ end
+
+ ruby_version_is ""..."2.4" do
+ it "raises a TypeError when passed a String" do
+ a = bignum_value
+ lambda { a.coerce("123") }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a Float" do
+ a = bignum_value
+ lambda { a.coerce(12.3) }.should raise_error(TypeError)
+ end
+ end
+
+ ruby_version_is "2.4" do
+ it "coerces both values to Floats and returns [other, self] when passed a Float" do
+ a = bignum_value
+ a.coerce(1.2).should == [1.2, a.to_f]
+ end
+
+ it "coerces both values to Floats and returns [other, self] when passed a String" do
+ a = bignum_value
+ a.coerce("123").should == [123.0, a.to_f]
+ end
+
+ it "calls #to_f to coerce other to a Float" do
+ b = mock("bignum value")
+ b.should_receive(:to_f).and_return(1.2)
+
+ a = bignum_value
+ ary = a.coerce(b)
+
+ ary.should == [1.2, a.to_f]
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/comparison_spec.rb b/spec/ruby/core/integer/comparison_spec.rb
new file mode 100644
index 0000000000..c54471dd16
--- /dev/null
+++ b/spec/ruby/core/integer/comparison_spec.rb
@@ -0,0 +1,189 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#<=>" do
+ context "fixnum" do
+ it "returns -1 when self is less than the given argument" do
+ (-3 <=> -1).should == -1
+ (-5 <=> 10).should == -1
+ (-5 <=> -4.5).should == -1
+ end
+
+ it "returns 0 when self is equal to the given argument" do
+ (0 <=> 0).should == 0
+ (954 <=> 954).should == 0
+ (954 <=> 954.0).should == 0
+ end
+
+ it "returns 1 when self is greater than the given argument" do
+ (496 <=> 5).should == 1
+ (200 <=> 100).should == 1
+ (51 <=> 50.5).should == 1
+ end
+
+ it "returns nil when the given argument is not an Integer" do
+ (3 <=> mock('x')).should == nil
+ (3 <=> 'test').should == nil
+ end
+ end
+
+ context "bignum" do
+ describe "with a Fixnum" do
+ it "returns -1 when other is larger" do
+ (-bignum_value <=> 2).should == -1
+ end
+
+ it "returns 1 when other is smaller" do
+ (bignum_value <=> 2).should == 1
+ end
+ end
+
+ describe "with a Bignum" do
+ describe "when other is negative" do
+ it "returns -1 when self is negative and other is larger" do
+ (-bignum_value(42) <=> -bignum_value).should == -1
+ end
+
+ it "returns 0 when other is equal" do
+ (-bignum_value <=> -bignum_value).should == 0
+ end
+
+ it "returns 1 when self is negative and other is smaller" do
+ (-bignum_value <=> -bignum_value(94)).should == 1
+ end
+
+ it "returns 1 when self is positive" do
+ (bignum_value <=> -bignum_value).should == 1
+ end
+ end
+
+ describe "when other is positive" do
+ it "returns -1 when self is negative" do
+ (-bignum_value <=> bignum_value).should == -1
+ end
+
+ it "returns -1 when self is positive and other is larger" do
+ (bignum_value <=> bignum_value(38)).should == -1
+ end
+
+ it "returns 0 when other is equal" do
+ (bignum_value <=> bignum_value).should == 0
+ end
+
+ it "returns 1 when other is smaller" do
+ (bignum_value(56) <=> bignum_value).should == 1
+ end
+ end
+ end
+
+ describe "with a Float" do
+ describe "when other is negative" do
+ it "returns -1 when self is negative and other is larger" do
+ (-bignum_value(0xffff) <=> -bignum_value.to_f).should == -1
+ end
+
+ it "returns 0 when other is equal" do
+ (-bignum_value <=> -bignum_value.to_f).should == 0
+ end
+
+ it "returns 1 when self is negative and other is smaller" do
+ (-bignum_value <=> -bignum_value(0xffef).to_f).should == 1
+ end
+
+ it "returns 1 when self is positive" do
+ (bignum_value <=> -bignum_value.to_f).should == 1
+ end
+ end
+
+ describe "when other is positive" do
+ it "returns -1 when self is negative" do
+ (-bignum_value <=> bignum_value.to_f).should == -1
+ end
+
+ it "returns -1 when self is positive and other is larger" do
+ (bignum_value <=> bignum_value(0xfffe).to_f).should == -1
+ end
+
+ it "returns 0 when other is equal" do
+ (bignum_value <=> bignum_value.to_f).should == 0
+ end
+
+ it "returns 1 when other is smaller" do
+ (bignum_value(0xfeff) <=> bignum_value.to_f).should == 1
+ end
+ end
+ end
+
+ describe "with an Object" do
+ before :each do
+ @big = bignum_value
+ @num = mock("value for Bignum#<=>")
+ end
+
+ it "calls #coerce on other" do
+ @num.should_receive(:coerce).with(@big).and_return([@big.to_f, 2.5])
+ @big <=> @num
+ end
+
+ ruby_version_is ""..."2.5" do
+ it "returns nil if #coerce raises an exception" do
+ @num.should_receive(:coerce).with(@big).and_raise(RuntimeError)
+ lambda {
+ @result = (@big <=> @num)
+ }.should complain(/Numerical comparison operators will no more rescue exceptions/)
+ @result.should be_nil
+ end
+ end
+
+ ruby_version_is "2.5" do
+ it "lets the exception go through if #coerce raises an exception" do
+ @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error"))
+ lambda {
+ @big <=> @num
+ }.should raise_error(RuntimeError, "my error")
+ end
+ end
+
+ it "raises an exception if #coerce raises a non-StandardError exception" do
+ @num.should_receive(:coerce).with(@big).and_raise(Exception)
+ lambda { @big <=> @num }.should raise_error(Exception)
+ end
+
+ it "returns nil if #coerce does not return an Array" do
+ @num.should_receive(:coerce).with(@big).and_return(nil)
+ (@big <=> @num).should be_nil
+ end
+
+ it "returns -1 if the coerced value is larger" do
+ @num.should_receive(:coerce).with(@big).and_return([@big, bignum_value(10)])
+ (@big <=> @num).should == -1
+ end
+
+ it "returns 0 if the coerced value is equal" do
+ @num.should_receive(:coerce).with(@big).and_return([@big, bignum_value])
+ (@big <=> @num).should == 0
+ end
+
+ it "returns 1 if the coerced value is smaller" do
+ @num.should_receive(:coerce).with(@big).and_return([@big, 22])
+ (@big <=> @num).should == 1
+ end
+ end
+
+ # The tests below are taken from matz's revision 23730 for Ruby trunk
+ it "returns 1 when self is Infinity and other is a Bignum" do
+ (infinity_value <=> Float::MAX.to_i*2).should == 1
+ end
+
+ it "returns -1 when self is negative and other is Infinty" do
+ (-Float::MAX.to_i*2 <=> infinity_value).should == -1
+ end
+
+ it "returns 1 when self is negative and other is -Infinity" do
+ (-Float::MAX.to_i*2 <=> -infinity_value).should == 1
+ end
+
+ it "returns -1 when self is -Infinity and other is negative" do
+ (-infinity_value <=> -Float::MAX.to_i*2).should == -1
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/complement_spec.rb b/spec/ruby/core/integer/complement_spec.rb
new file mode 100644
index 0000000000..faef88ae21
--- /dev/null
+++ b/spec/ruby/core/integer/complement_spec.rb
@@ -0,0 +1,20 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#~" do
+ context "fixnum" do
+ it "returns self with each bit flipped" do
+ (~0).should == -1
+ (~1221).should == -1222
+ (~-2).should == 1
+ (~-599).should == 598
+ end
+ end
+
+ context "bignum" do
+ it "returns self with each bit flipped" do
+ (~bignum_value(48)).should == -9223372036854775857
+ (~(-bignum_value(21))).should == 9223372036854775828
+ (~bignum_value(1)).should == -9223372036854775810
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/div_spec.rb b/spec/ruby/core/integer/div_spec.rb
new file mode 100644
index 0000000000..99efedd483
--- /dev/null
+++ b/spec/ruby/core/integer/div_spec.rb
@@ -0,0 +1,138 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#div" do
+ context "fixnum" do
+ it "returns self divided by the given argument as an Integer" do
+ 2.div(2).should == 1
+ 1.div(2).should == 0
+ 5.div(2).should == 2
+ end
+
+ it "rounds towards -inf" do
+ 8192.div(10).should == 819
+ 8192.div(-10).should == -820
+ (-8192).div(10).should == -820
+ (-8192).div(-10).should == 819
+ end
+
+ it "means (x / y).floor" do
+ 5.div(2).should == (5 / 2).floor
+ 5.div(2.0).should == (5 / 2.0).floor
+ 5.div(-2).should == (5 / -2).floor
+
+ 5.div(100).should == (5 / 100).floor
+ 5.div(100.0).should == (5 / 100.0).floor
+ 5.div(-100).should == (5 / -100).floor
+ end
+
+ it "calls #coerce and #div if argument responds to #coerce" do
+ x = mock("x")
+ y = mock("y")
+ result = mock("result")
+
+ y.should_receive(:coerce).and_return([x, y])
+ x.should_receive(:div).with(y).and_return(result)
+
+ 10.div(y).should == result
+ end
+
+ it "coerces self and the given argument to Floats and returns self divided by other as Fixnum" do
+ 1.div(0.2).should == 5
+ 1.div(0.16).should == 6
+ 1.div(0.169).should == 5
+ -1.div(50.4).should == -1
+ 1.div(bignum_value).should == 0
+ 1.div(Rational(1, 5)).should == 5
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { 0.div(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { 10.div(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { -10.div(0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and not a Float" do
+ lambda { 13.div(0) }.should raise_error(ZeroDivisionError)
+ lambda { 13.div(-0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-numeric argument" do
+ lambda { 13.div(mock('10')) }.should raise_error(TypeError)
+ lambda { 5.div("2") }.should raise_error(TypeError)
+ lambda { 5.div(:"2") }.should raise_error(TypeError)
+ lambda { 5.div([]) }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(88)
+ end
+
+ it "returns self divided by other" do
+ @bignum.div(4).should == 2305843009213693974
+ @bignum.div(Rational(4, 1)).should == 2305843009213693974
+ @bignum.div(bignum_value(2)).should == 1
+
+ (-(10**50)).div(-(10**40 + 1)).should == 9999999999
+ (10**50).div(10**40 + 1).should == 9999999999
+
+ (-10**50).div(10**40 + 1).should == -10000000000
+ (10**50).div(-(10**40 + 1)).should == -10000000000
+ end
+
+ it "calls #coerce and #div if argument responds to #coerce" do
+ x = mock("x")
+ y = mock("y")
+ result = mock("result")
+
+ y.should_receive(:coerce).and_return([x, y])
+ x.should_receive(:div).with(y).and_return(result)
+
+ @bignum.div(y).should == result
+ end
+
+ it "means (x / y).floor" do
+ @bignum.div(2).should == (@bignum / 2).floor
+ @bignum.div(-2).should == (@bignum / -2).floor
+
+ @bignum.div(@bignum+1).should == (@bignum / (@bignum+1)).floor
+ @bignum.div(-(@bignum+1)).should == (@bignum / -(@bignum+1)).floor
+
+ @bignum.div(2.0).should == (@bignum / 2.0).floor
+ @bignum.div(100.0).should == (@bignum / 100.0).floor
+ end
+
+ it "looses precision if passed Float argument" do
+ @bignum.div(1).should_not == @bignum.div(1.0)
+ @bignum.div(4).should_not == @bignum.div(4.0)
+ @bignum.div(21).should_not == @bignum.div(21.0)
+ end
+
+ it "raises a TypeError when given a non-numeric" do
+ lambda { @bignum.div(mock("10")) }.should raise_error(TypeError)
+ lambda { @bignum.div("2") }.should raise_error(TypeError)
+ lambda { @bignum.div(:symbol) }.should raise_error(TypeError)
+ end
+
+ it "returns a result of integer division of self by a float argument" do
+ @bignum.div(4294967295.5).should eql(2147483648)
+ not_supported_on :opal do
+ @bignum.div(4294967295.0).should eql(2147483648)
+ @bignum.div(bignum_value(88).to_f).should eql(1)
+ @bignum.div(-bignum_value(88).to_f).should eql(-1)
+ end
+ end
+
+ # #5490
+ it "raises ZeroDivisionError if the argument is 0 and is a Float" do
+ lambda { @bignum.div(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { @bignum.div(-0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises ZeroDivisionError if the argument is 0 and is not a Float" do
+ lambda { @bignum.div(0) }.should raise_error(ZeroDivisionError)
+ lambda { @bignum.div(-0) }.should raise_error(ZeroDivisionError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb
index 6c81d5474f..c49b4b0d4a 100644
--- a/spec/ruby/core/integer/divide_spec.rb
+++ b/spec/ruby/core/integer/divide_spec.rb
@@ -1,7 +1,96 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/arithmetic_coerce', __FILE__)
describe "Integer#/" do
- it_behaves_like :integer_arithmetic_exception_in_coerce, :/
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_arithmetic_coerce_rescue, :/
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :/
+ end
+
+ context "fixnum" do
+ it "returns self divided by the given argument" do
+ (2 / 2).should == 1
+ (3 / 2).should == 1
+ end
+
+ it "supports dividing negative numbers" do
+ (-1 / 10).should == -1
+ end
+
+ it "returns result the same class as the argument" do
+ (3 / 2).should == 1
+ (3 / 2.0).should == 1.5
+ (3 / Rational(2, 1)).should == Rational(3, 2)
+ end
+
+ it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
+ lambda { 1 / 0 }.should raise_error(ZeroDivisionError)
+ end
+
+ it "does NOT raise ZeroDivisionError if the given argument is zero and is a Float" do
+ (1 / 0.0).to_s.should == 'Infinity'
+ (-1 / 0.0).to_s.should == '-Infinity'
+ end
+
+ it "coerces fixnum and return self divided by other" do
+ (-1 / 50.4).should be_close(-0.0198412698412698, TOLERANCE)
+ (1 / bignum_value).should == 0
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { 13 / mock('10') }.should raise_error(TypeError)
+ lambda { 13 / "10" }.should raise_error(TypeError)
+ lambda { 13 / :symbol }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(88)
+ end
+
+ it "returns self divided by other" do
+ (@bignum / 4).should == 2305843009213693974
+
+ (@bignum / bignum_value(2)).should == 1
+
+ (-(10**50) / -(10**40 + 1)).should == 9999999999
+ ((10**50) / (10**40 + 1)).should == 9999999999
+
+ ((-10**50) / (10**40 + 1)).should == -10000000000
+ ((10**50) / -(10**40 + 1)).should == -10000000000
+ end
+
+ it "returns self divided by Float" do
+ not_supported_on :opal do
+ (bignum_value(88) / 4294967295.0).should be_close(2147483648.5, TOLERANCE)
+ end
+ (bignum_value(88) / 4294967295.5).should be_close(2147483648.25, TOLERANCE)
+ end
+
+ it "returns result the same class as the argument" do
+ (@bignum / 4).should == 2305843009213693974
+ (@bignum / 4.0).should be_close(2305843009213693974, TOLERANCE)
+ (@bignum / Rational(4, 1)).should == Rational(2305843009213693974, 1)
+ end
+
+ it "does NOT raise ZeroDivisionError if other is zero and is a Float" do
+ (bignum_value / 0.0).to_s.should == 'Infinity'
+ (bignum_value / -0.0).to_s.should == '-Infinity'
+ end
+
+ it "raises a ZeroDivisionError if other is zero and not a Float" do
+ lambda { @bignum / 0 }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-numeric" do
+ lambda { @bignum / mock('10') }.should raise_error(TypeError)
+ lambda { @bignum / "2" }.should raise_error(TypeError)
+ lambda { @bignum / :symbol }.should raise_error(TypeError)
+ end
+ end
end
diff --git a/spec/ruby/core/integer/divmod_spec.rb b/spec/ruby/core/integer/divmod_spec.rb
new file mode 100644
index 0000000000..d52d1d0577
--- /dev/null
+++ b/spec/ruby/core/integer/divmod_spec.rb
@@ -0,0 +1,117 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#divmod" do
+ context "fixnum" do
+ it "returns an Array containing quotient and modulus obtained from dividing self by the given argument" do
+ 13.divmod(4).should == [3, 1]
+ 4.divmod(13).should == [0, 4]
+
+ 13.divmod(4.0).should == [3, 1]
+ 4.divmod(13.0).should == [0, 4]
+
+ 1.divmod(2.0).should == [0, 1.0]
+ 200.divmod(bignum_value).should == [0, 200]
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ lambda { 13.divmod(0) }.should raise_error(ZeroDivisionError)
+ lambda { 0.divmod(0) }.should raise_error(ZeroDivisionError)
+ lambda { -10.divmod(0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { 0.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { 10.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { -10.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13.divmod(obj)
+ }.should raise_error(TypeError)
+ lambda { 13.divmod("10") }.should raise_error(TypeError)
+ lambda { 13.divmod(:symbol) }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(55)
+ end
+
+ # Based on MRI's test/test_integer.rb (test_divmod),
+ # MRI maintains the following property:
+ # if q, r = a.divmod(b) ==>
+ # assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
+ # So, r is always between 0 and b.
+ it "returns an Array containing quotient and modulus obtained from dividing self by the given argument" do
+ @bignum.divmod(4).should == [2305843009213693965, 3]
+ @bignum.divmod(13).should == [709490156681136604, 11]
+
+ @bignum.divmod(4.5).should == [2049638230412172288, 3.5]
+
+ not_supported_on :opal do
+ @bignum.divmod(4.0).should == [2305843009213693952, 0.0]
+ @bignum.divmod(13.0).should == [709490156681136640, 8.0]
+
+ @bignum.divmod(2.0).should == [4611686018427387904, 0.0]
+ end
+
+ @bignum.divmod(bignum_value).should == [1, 55]
+
+ (-(10**50)).divmod(-(10**40 + 1)).should == [9999999999, -9999999999999999999999999999990000000001]
+ (10**50).divmod(10**40 + 1).should == [9999999999, 9999999999999999999999999999990000000001]
+
+ (-10**50).divmod(10**40 + 1).should == [-10000000000, 10000000000]
+ (10**50).divmod(-(10**40 + 1)).should == [-10000000000, -10000000000]
+ end
+
+ describe "with q = floor(x/y), a = q*b + r," do
+ it "returns [q,r] when a < 0, b > 0 and |a| < b" do
+ a = -@bignum + 1
+ b = @bignum
+ a.divmod(b).should == [-1, 1]
+ end
+
+ it "returns [q,r] when a > 0, b < 0 and a > |b|" do
+ b = -@bignum + 1
+ a = @bignum
+ a.divmod(b).should == [-2, -@bignum + 2]
+ end
+
+ it "returns [q,r] when a > 0, b < 0 and a < |b|" do
+ a = @bignum - 1
+ b = -@bignum
+ a.divmod(b).should == [-1, -1]
+ end
+
+ it "returns [q,r] when a < 0, b < 0 and |a| < |b|" do
+ a = -@bignum + 1
+ b = -@bignum
+ a.divmod(b).should == [0, -@bignum + 1]
+ end
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ lambda { @bignum.divmod(0) }.should raise_error(ZeroDivisionError)
+ lambda { (-@bignum).divmod(0) }.should raise_error(ZeroDivisionError)
+ end
+
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if other is NaN" do
+ lambda { @bignum.divmod(nan_value) }.should raise_error(FloatDomainError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { @bignum.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { (-@bignum).divmod(0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when the given argument is not an Integer" do
+ lambda { @bignum.divmod(mock('10')) }.should raise_error(TypeError)
+ lambda { @bignum.divmod("10") }.should raise_error(TypeError)
+ lambda { @bignum.divmod(:symbol) }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/dup_spec.rb b/spec/ruby/core/integer/dup_spec.rb
deleted file mode 100644
index f46bdf89bd..0000000000
--- a/spec/ruby/core/integer/dup_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is '2.4' do
- describe "Integer#dup" do
- it "returns self" do
- int = 2
- int.dup.should equal(int)
- end
- end
-end
diff --git a/spec/ruby/core/integer/element_reference_spec.rb b/spec/ruby/core/integer/element_reference_spec.rb
new file mode 100644
index 0000000000..2a2e8981a3
--- /dev/null
+++ b/spec/ruby/core/integer/element_reference_spec.rb
@@ -0,0 +1,111 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#[]" do
+ context "fixnum" do
+ it "behaves like (n >> b) & 1" do
+ 0b101[1].should == 0
+ 0b101[2].should == 1
+ end
+
+ it "returns 1 if the nth bit is set" do
+ 15[1].should == 1
+ end
+
+ it "returns 1 if the nth bit is set (in two's-complement representation)" do
+ (-1)[1].should == 1
+ end
+
+ it "returns 0 if the nth bit is not set" do
+ 8[2].should == 0
+ end
+
+ it "returns 0 if the nth bit is not set (in two's-complement representation)" do
+ (-2)[0].should == 0
+ end
+
+ it "returns 0 if the nth bit is greater than the most significant bit" do
+ 2[3].should == 0
+ end
+
+ it "returns 1 if self is negative and the nth bit is greater than the most significant bit" do
+ (-1)[3].should == 1
+ end
+
+ it "returns 0 when passed a negative argument" do
+ 3[-1].should == 0
+ (-1)[-1].should == 0
+ end
+
+ it "calls #to_int to convert the argument to an Integer and returns 1 if the nth bit is set" do
+ obj = mock('1')
+ obj.should_receive(:to_int).and_return(1)
+
+ 2[obj].should == 1
+ end
+
+ it "calls #to_int to convert the argument to an Integer and returns 0 if the nth bit is set" do
+ obj = mock('0')
+ obj.should_receive(:to_int).and_return(0)
+
+ 2[obj].should == 0
+ end
+
+ it "accepts a Float argument and returns 0 if the bit at the truncated value is not set" do
+ 13[1.3].should == 0
+ end
+
+ it "accepts a Float argument and returns 1 if the bit at the truncated value is set" do
+ 13[2.1].should == 1
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { 3["3"] }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock('asdf')
+ obj.should_receive(:to_int).and_return("asdf")
+ lambda { 3[obj] }.should raise_error(TypeError)
+ end
+
+ it "calls #to_int to coerce a String to a Bignum and returns 0" do
+ obj = mock('bignum value')
+ obj.should_receive(:to_int).and_return(bignum_value)
+
+ 3[obj].should == 0
+ end
+
+ it "returns 0 when passed a Float in the range of a Bignum" do
+ 3[bignum_value.to_f].should == 0
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(4996)
+ end
+
+ it "returns the nth bit in the binary representation of self" do
+ @bignum[2].should == 1
+ @bignum[9.2].should == 1
+ @bignum[21].should == 0
+ @bignum[0xffffffff].should == 0
+ @bignum[-0xffffffff].should == 0
+ end
+
+ it "tries to convert the given argument to an Integer using #to_int" do
+ @bignum[1.3].should == @bignum[1]
+
+ (obj = mock('2')).should_receive(:to_int).at_least(1).and_return(2)
+ @bignum[obj].should == 1
+ end
+
+ it "raises a TypeError when the given argument can't be converted to Integer" do
+ obj = mock('asdf')
+ lambda { @bignum[obj] }.should raise_error(TypeError)
+
+ obj.should_receive(:to_int).and_return("asdf")
+ lambda { @bignum[obj] }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/fixnum/equal_value_spec.rb b/spec/ruby/core/integer/equal_value_spec.rb
index 3a9ef93d24..102cbb1f26 100644
--- a/spec/ruby/core/fixnum/equal_value_spec.rb
+++ b/spec/ruby/core/integer/equal_value_spec.rb
@@ -1,6 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal', __FILE__)
-describe "Fixnum#==" do
- it_behaves_like :fixnum_equal, :==
+describe "Integer#==" do
+ it_behaves_like :integer_equal, :==
end
+
diff --git a/spec/ruby/core/integer/even_spec.rb b/spec/ruby/core/integer/even_spec.rb
index c14cf84947..edc8b13dd9 100644
--- a/spec/ruby/core/integer/even_spec.rb
+++ b/spec/ruby/core/integer/even_spec.rb
@@ -1,20 +1,40 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Integer#even?" do
- it "returns true for a Fixnum when it is an even number" do
- (-2).even?.should be_true
- (-1).even?.should be_false
+ context "fixnum" do
+ it "returns true for a Fixnum when it is an even number" do
+ (-2).even?.should be_true
+ (-1).even?.should be_false
- 0.even?.should be_true
- 1.even?.should be_false
- 2.even?.should be_true
+ 0.even?.should be_true
+ 1.even?.should be_false
+ 2.even?.should be_true
+ end
+
+ it "returns true for a Bignum when it is an even number" do
+ bignum_value(0).even?.should be_true
+ bignum_value(1).even?.should be_false
+
+ (-bignum_value(0)).even?.should be_true
+ (-bignum_value(1)).even?.should be_false
+ end
end
- it "returns true for a Bignum when it is an even number" do
- bignum_value(0).even?.should be_true
- bignum_value(1).even?.should be_false
+ context "bignum" do
+ it "returns true if self is even and positive" do
+ (10000**10).even?.should be_true
+ end
+
+ it "returns true if self is even and negative" do
+ (-10000**10).even?.should be_true
+ end
+
+ it "returns false if self is odd and positive" do
+ (9879**976).even?.should be_false
+ end
- (-bignum_value(0)).even?.should be_true
- (-bignum_value(1)).even?.should be_false
+ it "returns false if self is odd and negative" do
+ (-9879**976).even?.should be_false
+ end
end
end
diff --git a/spec/ruby/core/integer/exponent_spec.rb b/spec/ruby/core/integer/exponent_spec.rb
new file mode 100644
index 0000000000..a009eaa131
--- /dev/null
+++ b/spec/ruby/core/integer/exponent_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/exponent', __FILE__)
+
+describe "Integer#**" do
+ it_behaves_like :integer_exponent, :**
+end
diff --git a/spec/ruby/core/fixnum/fdiv_spec.rb b/spec/ruby/core/integer/fdiv_spec.rb
index bb5f09c333..7650fa0f52 100644
--- a/spec/ruby/core/fixnum/fdiv_spec.rb
+++ b/spec/ruby/core/integer/fdiv_spec.rb
@@ -1,11 +1,11 @@
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Fixnum#fdiv" do
- it "performs floating-point division between self and a Fixnum" do
+describe "Integer#fdiv" do
+ it "performs floating-point division between self and a fixnum" do
8.fdiv(7).should be_close(1.14285714285714, TOLERANCE)
end
- it "performs floating-point division between self and a Bignum" do
+ it "performs floating-point division between self and a bignum" do
8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE)
end
diff --git a/spec/ruby/core/integer/floor_spec.rb b/spec/ruby/core/integer/floor_spec.rb
index 9babcd9a3e..156b0ba055 100644
--- a/spec/ruby/core/integer/floor_spec.rb
+++ b/spec/ruby/core/integer/floor_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../shared/to_i', __FILE__)
require File.expand_path('../shared/integer_rounding', __FILE__)
describe "Integer#floor" do
- it_behaves_like(:integer_to_i, :floor)
- it_behaves_like(:integer_rounding_positive_precision, :floor)
+ it_behaves_like :integer_to_i, :floor
+ it_behaves_like :integer_rounding_positive_precision, :floor
ruby_version_is "2.4" do
context "precision argument specified as part of the floor method is negative" do
diff --git a/spec/ruby/core/integer/gt_spec.rb b/spec/ruby/core/integer/gt_spec.rb
index ec0834d346..d63ee5e34f 100644
--- a/spec/ruby/core/integer/gt_spec.rb
+++ b/spec/ruby/core/integer/gt_spec.rb
@@ -1,7 +1,50 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/comparison_coerce', __FILE__)
describe "Integer#>" do
- it_behaves_like :integer_comparison_exception_in_coerce, :>
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_comparison_coerce_rescue, :>
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :>
+ end
+
+ context "fixnum" do
+ it "returns true if self is greater than the given argument" do
+ (13 > 2).should == true
+ (-500 > -600).should == true
+
+ (1 > 5).should == false
+ (5 > 5).should == false
+
+ (900 > bignum_value).should == false
+ (5 > 4.999).should == true
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { 5 > "4" }.should raise_error(ArgumentError)
+ lambda { 5 > mock('x') }.should raise_error(ArgumentError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(732)
+ end
+
+ it "returns true if self is greater than the given argument" do
+ (@bignum > (@bignum - 1)).should == true
+ (@bignum > 14.6).should == true
+ (@bignum > 10).should == true
+
+ (@bignum > (@bignum + 500)).should == false
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { @bignum > "4" }.should raise_error(ArgumentError)
+ lambda { @bignum > mock('str') }.should raise_error(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/integer/gte_spec.rb b/spec/ruby/core/integer/gte_spec.rb
index a49535f823..66ca49249c 100644
--- a/spec/ruby/core/integer/gte_spec.rb
+++ b/spec/ruby/core/integer/gte_spec.rb
@@ -1,7 +1,50 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/comparison_coerce', __FILE__)
describe "Integer#>=" do
- it_behaves_like :integer_comparison_exception_in_coerce, :>=
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_comparison_coerce_rescue, :>=
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :>=
+ end
+
+ context "fixnum" do
+ it "returns true if self is greater than or equal to the given argument" do
+ (13 >= 2).should == true
+ (-500 >= -600).should == true
+
+ (1 >= 5).should == false
+ (2 >= 2).should == true
+ (5 >= 5).should == true
+
+ (900 >= bignum_value).should == false
+ (5 >= 4.999).should == true
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { 5 >= "4" }.should raise_error(ArgumentError)
+ lambda { 5 >= mock('x') }.should raise_error(ArgumentError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(14)
+ end
+
+ it "returns true if self is greater than or equal to other" do
+ (@bignum >= @bignum).should == true
+ (@bignum >= (@bignum + 2)).should == false
+ (@bignum >= 5664.2).should == true
+ (@bignum >= 4).should == true
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { @bignum >= "4" }.should raise_error(ArgumentError)
+ lambda { @bignum >= mock('str') }.should raise_error(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/integer/left_shift_spec.rb b/spec/ruby/core/integer/left_shift_spec.rb
new file mode 100644
index 0000000000..c25785b39e
--- /dev/null
+++ b/spec/ruby/core/integer/left_shift_spec.rb
@@ -0,0 +1,165 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#<< (with n << m)" do
+ context "fixnum" do
+ it "returns n shifted left m bits when n > 0, m > 0" do
+ (1 << 1).should == 2
+ end
+
+ it "returns n shifted left m bits when n < 0, m > 0" do
+ (-1 << 1).should == -2
+ (-7 << 1).should == -14
+ (-42 << 2).should == -168
+ end
+
+ it "returns n shifted right m bits when n > 0, m < 0" do
+ (2 << -1).should == 1
+ end
+
+ it "returns n shifted right m bits when n < 0, m < 0" do
+ (-2 << -1).should == -1
+ end
+
+ it "returns 0 when n == 0" do
+ (0 << 1).should == 0
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (1 << 0).should == 1
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (-1 << 0).should == -1
+ end
+
+ it "returns 0 when n > 0, m < 0 and n < 2**-m" do
+ (3 << -2).should == 0
+ (7 << -3).should == 0
+ (127 << -7).should == 0
+
+ # To make sure the exponent is not truncated
+ (7 << -32).should == 0
+ (7 << -64).should == 0
+ end
+
+ it "returns -1 when n < 0, m < 0 and n > -(2**-m)" do
+ (-3 << -2).should == -1
+ (-7 << -3).should == -1
+ (-127 << -7).should == -1
+
+ # To make sure the exponent is not truncated
+ (-7 << -32).should == -1
+ (-7 << -64).should == -1
+ end
+
+ it "returns 0 when m < 0 and m is a Bignum" do
+ (3 << -bignum_value).should == 0
+ end
+
+ it "returns an Bignum == fixnum_max * 2 when fixnum_max << 1 and n > 0" do
+ result = fixnum_max << 1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_max * 2
+ end
+
+ it "returns an Bignum == fixnum_min * 2 when fixnum_min << 1 and n < 0" do
+ result = fixnum_min << 1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_min * 2
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("4")
+ obj.should_receive(:to_int).and_return(4)
+
+ (3 << obj).should == 48
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { 3 << obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { 3 << nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { 3 << "4" }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value * 16
+ end
+
+ it "returns n shifted left m bits when n > 0, m > 0" do
+ (@bignum << 4).should == 2361183241434822606848
+ end
+
+ it "returns n shifted left m bits when n < 0, m > 0" do
+ (-@bignum << 9).should == -75557863725914323419136
+ end
+
+ it "returns n shifted right m bits when n > 0, m < 0" do
+ (@bignum << -1).should == 73786976294838206464
+ end
+
+ it "returns n shifted right m bits when n < 0, m < 0" do
+ (-@bignum << -2).should == -36893488147419103232
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (@bignum << 0).should == @bignum
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (-@bignum << 0).should == -@bignum
+ end
+
+ it "returns 0 when m < 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (@bignum << -68).should == 0
+ end
+
+ it "returns 0 when m < 0 and m is a Bignum" do
+ (@bignum << -bignum_value).should == 0
+ end
+
+ it "returns a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
+ result = (fixnum_max * 2) << -1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_max
+ end
+
+ it "returns a Fixnum == fixnum_min when (fixnum_min * 2) << -1 and n < 0" do
+ result = (fixnum_min * 2) << -1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_min
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("4")
+ obj.should_receive(:to_int).and_return(4)
+
+ (@bignum << obj).should == 2361183241434822606848
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { @bignum << obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { @bignum << nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { @bignum << "4" }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/lt_spec.rb b/spec/ruby/core/integer/lt_spec.rb
index 3b778d7f6c..03ef701a89 100644
--- a/spec/ruby/core/integer/lt_spec.rb
+++ b/spec/ruby/core/integer/lt_spec.rb
@@ -1,6 +1,52 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/comparison_coerce', __FILE__)
describe "Integer#<" do
- it_behaves_like :integer_comparison_exception_in_coerce, :<
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_comparison_coerce_rescue, :<
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :<
+ end
+
+ context "fixnum" do
+ it "returns true if self is less than the given argument" do
+ (2 < 13).should == true
+ (-600 < -500).should == true
+
+ (5 < 1).should == false
+ (5 < 5).should == false
+
+ (900 < bignum_value).should == true
+ (5 < 4.999).should == false
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { 5 < "4" }.should raise_error(ArgumentError)
+ lambda { 5 < mock('x') }.should raise_error(ArgumentError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(32)
+ end
+
+ it "returns true if self is less than the given argument" do
+ (@bignum < @bignum + 1).should == true
+ (-@bignum < -(@bignum - 1)).should == true
+
+ (@bignum < 1).should == false
+ (@bignum < 5).should == false
+
+ (@bignum < 4.999).should == false
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { @bignum < "4" }.should raise_error(ArgumentError)
+ lambda { @bignum < mock('str') }.should raise_error(ArgumentError)
+ end
+ end
end
+
diff --git a/spec/ruby/core/integer/lte_spec.rb b/spec/ruby/core/integer/lte_spec.rb
index d62780c78c..592e72116c 100644
--- a/spec/ruby/core/integer/lte_spec.rb
+++ b/spec/ruby/core/integer/lte_spec.rb
@@ -1,6 +1,55 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/comparison_coerce', __FILE__)
describe "Integer#<=" do
- it_behaves_like :integer_comparison_exception_in_coerce, :<=
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_comparison_coerce_rescue, :<=
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :<=
+ end
+
+ context "fixnum" do
+ it "returns true if self is less than or equal to other" do
+ (2 <= 13).should == true
+ (-600 <= -500).should == true
+
+ (5 <= 1).should == false
+ (5 <= 5).should == true
+ (-2 <= -2).should == true
+
+ (900 <= bignum_value).should == true
+ (5 <= 4.999).should == false
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { 5 <= "4" }.should raise_error(ArgumentError)
+ lambda { 5 <= mock('x') }.should raise_error(ArgumentError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(39)
+ end
+
+ it "returns true if self is less than or equal to other" do
+ (@bignum <= @bignum).should == true
+ (-@bignum <= -(@bignum - 1)).should == true
+
+ (@bignum <= 4.999).should == false
+ end
+
+ it "returns false if compares with near float" do
+ (@bignum <= (@bignum + 0.0)).should == false
+ (@bignum <= (@bignum + 0.5)).should == false
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ lambda { @bignum <= "4" }.should raise_error(ArgumentError)
+ lambda { @bignum <= mock('str') }.should raise_error(ArgumentError)
+ end
+ end
end
+
diff --git a/spec/ruby/core/fixnum/abs_spec.rb b/spec/ruby/core/integer/magnitude_spec.rb
index 5e6a7de891..72929b827e 100644
--- a/spec/ruby/core/fixnum/abs_spec.rb
+++ b/spec/ruby/core/integer/magnitude_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/abs', __FILE__)
-describe "Fixnum#abs" do
- it_behaves_like :fixnum_abs, :abs
+describe "Integer#magnitude" do
+ it_behaves_like :integer_abs, :magnitude
end
diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb
index 6e8fa69759..6a84bca429 100644
--- a/spec/ruby/core/integer/minus_spec.rb
+++ b/spec/ruby/core/integer/minus_spec.rb
@@ -1,7 +1,50 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/arithmetic_coerce', __FILE__)
describe "Integer#-" do
- it_behaves_like :integer_arithmetic_exception_in_coerce, :-
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_arithmetic_coerce_rescue, :-
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :-
+ end
+
+ context "fixnum" do
+ it "returns self minus the given Integer" do
+ (5 - 10).should == -5
+ (9237212 - 5_280).should == 9231932
+
+ (781 - 0.5).should == 780.5
+ (2_560_496 - bignum_value).should == -9223372036852215312
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 - obj
+ }.should raise_error(TypeError)
+ lambda { 13 - "10" }.should raise_error(TypeError)
+ lambda { 13 - :symbol }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(314)
+ end
+
+ it "returns self minus the given Integer" do
+ (@bignum - 9).should == 9223372036854776113
+ (@bignum - 12.57).should be_close(9223372036854776109.43, TOLERANCE)
+ (@bignum - bignum_value(42)).should == 272
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { @bignum - mock('10') }.should raise_error(TypeError)
+ lambda { @bignum - "10" }.should raise_error(TypeError)
+ lambda { @bignum - :symbol }.should raise_error(TypeError)
+ end
+ end
end
diff --git a/spec/ruby/core/integer/modulo_spec.rb b/spec/ruby/core/integer/modulo_spec.rb
new file mode 100644
index 0000000000..34649f0d01
--- /dev/null
+++ b/spec/ruby/core/integer/modulo_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/modulo', __FILE__)
+
+describe "Integer#%" do
+ it_behaves_like :integer_modulo, :%
+end
+
+describe "Integer#modulo" do
+ it_behaves_like :integer_modulo, :modulo
+end
diff --git a/spec/ruby/core/integer/multiply_spec.rb b/spec/ruby/core/integer/multiply_spec.rb
index cfce2418a4..e5872e6fa0 100644
--- a/spec/ruby/core/integer/multiply_spec.rb
+++ b/spec/ruby/core/integer/multiply_spec.rb
@@ -1,6 +1,52 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/arithmetic_coerce', __FILE__)
describe "Integer#*" do
- it_behaves_like :integer_arithmetic_exception_in_coerce, :*
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_arithmetic_coerce_rescue, :*
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :*
+ end
+
+ context "fixnum" do
+ it "returns self multiplied by the given Integer" do
+ (4923 * 2).should == 9846
+ (1342177 * 800).should == 1073741600
+ (65536 * 65536).should == 4294967296
+
+ (256 * bignum_value).should == 2361183241434822606848
+ (6712 * 0.25).should == 1678.0
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 * obj
+ }.should raise_error(TypeError)
+ lambda { 13 * "10" }.should raise_error(TypeError)
+ lambda { 13 * :symbol }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(772)
+ end
+
+ it "returns self multiplied by the given Integer" do
+ (@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
+ (@bignum * (1/bignum_value(0xffff).to_f)).should be_close(1.0, TOLERANCE)
+ (@bignum * 10).should == 92233720368547765800
+ (@bignum * (@bignum - 40)).should == 85070591730234629737795195287525433200
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { @bignum * mock('10') }.should raise_error(TypeError)
+ lambda { @bignum * "10" }.should raise_error(TypeError)
+ lambda { @bignum * :symbol }.should raise_error(TypeError)
+ end
+ end
end
+
diff --git a/spec/ruby/core/integer/next_spec.rb b/spec/ruby/core/integer/next_spec.rb
index a34db0a6f6..bc3a9b797f 100644
--- a/spec/ruby/core/integer/next_spec.rb
+++ b/spec/ruby/core/integer/next_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/next', __FILE__)
describe "Integer#next" do
- it_behaves_like(:integer_next, :next)
+ it_behaves_like :integer_next, :next
end
diff --git a/spec/ruby/core/integer/odd_spec.rb b/spec/ruby/core/integer/odd_spec.rb
index 2aa76d054a..c0c907a906 100644
--- a/spec/ruby/core/integer/odd_spec.rb
+++ b/spec/ruby/core/integer/odd_spec.rb
@@ -1,18 +1,38 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Integer#odd?" do
- it "returns true when self is an odd number" do
- (-2).odd?.should be_false
- (-1).odd?.should be_true
+ context "fixnum" do
+ it "returns true when self is an odd number" do
+ (-2).odd?.should be_false
+ (-1).odd?.should be_true
- 0.odd?.should be_false
- 1.odd?.should be_true
- 2.odd?.should be_false
+ 0.odd?.should be_false
+ 1.odd?.should be_true
+ 2.odd?.should be_false
- bignum_value(0).odd?.should be_false
- bignum_value(1).odd?.should be_true
+ bignum_value(0).odd?.should be_false
+ bignum_value(1).odd?.should be_true
- (-bignum_value(0)).odd?.should be_false
- (-bignum_value(1)).odd?.should be_true
+ (-bignum_value(0)).odd?.should be_false
+ (-bignum_value(1)).odd?.should be_true
+ end
+ end
+
+ context "bignum" do
+ it "returns true if self is odd and positive" do
+ (987279**19).odd?.should be_true
+ end
+
+ it "returns true if self is odd and negative" do
+ (-9873389**97).odd?.should be_true
+ end
+
+ it "returns false if self is even and positive" do
+ (10000000**10).odd?.should be_false
+ end
+
+ it "returns false if self is even and negative" do
+ (-1000000**100).odd?.should be_false
+ end
end
end
diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb
index c292943d06..5d1169c7da 100644
--- a/spec/ruby/core/integer/plus_spec.rb
+++ b/spec/ruby/core/integer/plus_spec.rb
@@ -1,6 +1,50 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/arithmetic_exception_in_coerce', __FILE__)
+require File.expand_path('../shared/arithmetic_coerce', __FILE__)
describe "Integer#+" do
- it_behaves_like :integer_arithmetic_exception_in_coerce, :+
+ ruby_version_is "2.4"..."2.5" do
+ it_behaves_like :integer_arithmetic_coerce_rescue, :+
+ end
+
+ ruby_version_is "2.5" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :+
+ end
+
+ context "fixnum" do
+ it "returns self plus the given Integer" do
+ (491 + 2).should == 493
+ (90210 + 10).should == 90220
+
+ (9 + bignum_value).should == 9223372036854775817
+ (1001 + 5.219).should == 1006.219
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 + obj
+ }.should raise_error(TypeError)
+ lambda { 13 + "10" }.should raise_error(TypeError)
+ lambda { 13 + :symbol }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(76)
+ end
+
+ it "returns self plus the given Integer" do
+ (@bignum + 4).should == 9223372036854775888
+ (@bignum + 4.2).should be_close(9223372036854775888.2, TOLERANCE)
+ (@bignum + bignum_value(3)).should == 18446744073709551695
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { @bignum + mock('10') }.should raise_error(TypeError)
+ lambda { @bignum + "10" }.should raise_error(TypeError)
+ lambda { @bignum + :symbol}.should raise_error(TypeError)
+ end
+ end
end
+
diff --git a/spec/ruby/core/integer/pow_spec.rb b/spec/ruby/core/integer/pow_spec.rb
new file mode 100644
index 0000000000..5811576d92
--- /dev/null
+++ b/spec/ruby/core/integer/pow_spec.rb
@@ -0,0 +1,51 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
+require File.expand_path('../shared/exponent', __FILE__)
+
+ruby_version_is "2.5" do
+ describe "Integer#pow" do
+ context "one argument is passed" do
+ it_behaves_like :integer_exponent, :pow
+ end
+
+ context "two arguments are passed" do
+ it "returns modulo of self raised to the given power" do
+ 2.pow(5, 12).should == 8
+ 2.pow(6, 13).should == 12
+ 2.pow(7, 14).should == 2
+ 2.pow(8, 15).should == 1
+ end
+
+ ruby_bug '#13669', '2.5'...'2.5.1' do
+ it "works well with bignums" do
+ 2.pow(61, 5843009213693951).should eql 3697379018277258
+ 2.pow(62, 5843009213693952).should eql 1551748822859776
+ 2.pow(63, 5843009213693953).should eql 3103497645717974
+ 2.pow(64, 5843009213693954).should eql 363986077738838
+ end
+ end
+
+ it "handles sign like #divmod does" do
+ 2.pow(5, 12).should == 8
+ 2.pow(5, -12).should == -4
+ -2.pow(5, 12).should == 4
+ -2.pow(5, -12).should == -8
+ end
+
+ it "ensures all arguments are integers" do
+ -> { 2.pow(5, 12.0) }.should raise_error(TypeError, /2nd argument not allowed unless all arguments are integers/)
+ -> { 2.pow(5, Rational(12, 1)) }.should raise_error(TypeError, /2nd argument not allowed unless all arguments are integers/)
+ end
+
+ it "raises TypeError for non-numeric value" do
+ -> { 2.pow(5, "12") }.should raise_error(TypeError)
+ -> { 2.pow(5, []) }.should raise_error(TypeError)
+ -> { 2.pow(5, nil) }.should raise_error(TypeError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ -> { 2.pow(5, 0) }.should raise_error(ZeroDivisionError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/remainder_spec.rb b/spec/ruby/core/integer/remainder_spec.rb
new file mode 100644
index 0000000000..926b86135b
--- /dev/null
+++ b/spec/ruby/core/integer/remainder_spec.rb
@@ -0,0 +1,51 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#remainder" do
+ context "fixnum" do
+ it "returns the remainder of dividing self by other" do
+ 5.remainder(3).should == 2
+ 5.remainder(3.0).should == 2.0
+ 5.remainder(Rational(3, 1)).should == Rational(2, 1)
+ end
+
+ it "means x-y*(x/y).truncate" do
+ 5.remainder(3).should == 2
+ 5.remainder(3.3).should be_close(1.7, TOLERANCE)
+ 5.remainder(3.7).should be_close(1.3, TOLERANCE)
+ end
+
+ it "keeps sign of self" do
+ 5.remainder( 3).should == 2
+ 5.remainder(-3).should == 2
+ -5.remainder( 3).should == -2
+ -5.remainder(-3).should == -2
+ end
+
+ it "raises TypeError if passed non-numeric argument" do
+ -> { 5.remainder("3") }.should raise_error(TypeError)
+ -> { 5.remainder(:"3") }.should raise_error(TypeError)
+ -> { 5.remainder([]) }.should raise_error(TypeError)
+ -> { 5.remainder(nil) }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ it "returns the remainder of dividing self by other" do
+ a = bignum_value(79)
+ a.remainder(2).should == 1
+ a.remainder(97.345).should be_close(46.5674996147722, TOLERANCE)
+ a.remainder(bignum_value).should == 79
+ end
+
+ it "raises a ZeroDivisionError if other is zero and not a Float" do
+ lambda { bignum_value(66).remainder(0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "does raises ZeroDivisionError if other is zero and a Float" do
+ a = bignum_value(7)
+ b = bignum_value(32)
+ lambda { a.remainder(0.0) }.should raise_error(ZeroDivisionError)
+ lambda { b.remainder(-0.0) }.should raise_error(ZeroDivisionError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/right_shift_spec.rb b/spec/ruby/core/integer/right_shift_spec.rb
new file mode 100644
index 0000000000..7a82df6ba9
--- /dev/null
+++ b/spec/ruby/core/integer/right_shift_spec.rb
@@ -0,0 +1,191 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#>> (with n >> m)" do
+ context "fixnum" do
+ it "returns n shifted right m bits when n > 0, m > 0" do
+ (2 >> 1).should == 1
+ end
+
+ it "returns n shifted right m bits when n < 0, m > 0" do
+ (-2 >> 1).should == -1
+ (-7 >> 1).should == -4
+ (-42 >> 2).should == -11
+ end
+
+ it "returns n shifted left m bits when n > 0, m < 0" do
+ (1 >> -1).should == 2
+ end
+
+ it "returns n shifted left m bits when n < 0, m < 0" do
+ (-1 >> -1).should == -2
+ end
+
+ it "returns 0 when n == 0" do
+ (0 >> 1).should == 0
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (1 >> 0).should == 1
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (-1 >> 0).should == -1
+ end
+
+ it "returns 0 when n > 0, m > 0 and n < 2**m" do
+ (3 >> 2).should == 0
+ (7 >> 3).should == 0
+ (127 >> 7).should == 0
+
+ # To make sure the exponent is not truncated
+ (7 >> 32).should == 0
+ (7 >> 64).should == 0
+ end
+
+ it "returns -1 when n < 0, m > 0 and n > -(2**m)" do
+ (-3 >> 2).should == -1
+ (-7 >> 3).should == -1
+ (-127 >> 7).should == -1
+
+ # To make sure the exponent is not truncated
+ (-7 >> 32).should == -1
+ (-7 >> 64).should == -1
+ end
+
+ it "returns 0 when m is a bignum" do
+ (3 >> bignum_value).should == 0
+ end
+
+ it "returns an Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
+ result = fixnum_max >> -1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_max * 2
+ end
+
+ it "returns an Bignum == fixnum_min * 2 when fixnum_min >> -1 and n < 0" do
+ result = fixnum_min >> -1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_min * 2
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("2")
+ obj.should_receive(:to_int).and_return(2)
+
+ (8 >> obj).should == 2
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { 3 >> obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { 3 >> nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { 3 >> "4" }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value * 16
+ end
+
+ it "returns n shifted right m bits when n > 0, m > 0" do
+ (@bignum >> 1).should == 73786976294838206464
+ end
+
+ it "returns n shifted right m bits when n < 0, m > 0" do
+ (-@bignum >> 2).should == -36893488147419103232
+ end
+
+ it "respects twos complement signed shifting" do
+ # This explicit left hand value is important because it is the
+ # exact bit pattern that matters, so it's important it's right
+ # here to show the significance.
+ #
+
+ (-42949672980000000000000 >> 14).should == -2621440001220703125
+ (-42949672980000000000001 >> 14).should == -2621440001220703126
+ # Note the off by one -------------------- ^^^^^^^^^^^^^^^^^^^^
+ # This is because even though we discard the lowest bit, in twos
+ # complement it would influence the bits to the left of it.
+
+ (-42949672980000000000000 >> 15).should == -1310720000610351563
+ (-42949672980000000000001 >> 15).should == -1310720000610351563
+
+ (-0xfffffffffffffffff >> 32).should == -68719476736
+ end
+
+ it "respects twos complement signed shifting for very large values" do
+ giant = 42949672980000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ neg = -giant
+
+ (giant >> 84).should == 2220446050284288846538547929770901490087453566957265138626098632812
+ (neg >> 84).should == -2220446050284288846538547929770901490087453566957265138626098632813
+ end
+
+ it "returns n shifted left m bits when n > 0, m < 0" do
+ (@bignum >> -2).should == 590295810358705651712
+ end
+
+ it "returns n shifted left m bits when n < 0, m < 0" do
+ (-@bignum >> -3).should == -1180591620717411303424
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (@bignum >> 0).should == @bignum
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (-@bignum >> 0).should == -@bignum
+ end
+
+ it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (@bignum >> 68).should == 0
+ end
+
+ it "returns 0 when m is a Bignum" do
+ (@bignum >> bignum_value).should == 0
+ end
+
+ it "returns a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
+ result = (fixnum_max * 2) >> 1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_max
+ end
+
+ it "returns a Fixnum == fixnum_min when (fixnum_min * 2) >> 1 and n < 0" do
+ result = (fixnum_min * 2) >> 1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_min
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("2")
+ obj.should_receive(:to_int).and_return(2)
+
+ (@bignum >> obj).should == 36893488147419103232
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { @bignum >> obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { @bignum >> nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { @bignum >> "4" }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/round_spec.rb b/spec/ruby/core/integer/round_spec.rb
index 5a46e6cba6..061b33c933 100644
--- a/spec/ruby/core/integer/round_spec.rb
+++ b/spec/ruby/core/integer/round_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../shared/to_i', __FILE__)
require File.expand_path('../shared/integer_rounding', __FILE__)
describe "Integer#round" do
- it_behaves_like(:integer_to_i, :round)
- it_behaves_like(:integer_rounding_positive_precision, :round)
+ it_behaves_like :integer_to_i, :round
+ it_behaves_like :integer_rounding_positive_precision, :round
ruby_version_is ""..."2.5" do # Not just since 2.4
it "rounds itself as a float if passed a positive precision" do
diff --git a/spec/ruby/core/integer/shared/abs.rb b/spec/ruby/core/integer/shared/abs.rb
new file mode 100644
index 0000000000..946aa21864
--- /dev/null
+++ b/spec/ruby/core/integer/shared/abs.rb
@@ -0,0 +1,18 @@
+describe :integer_abs, shared: true do
+ context "fixnum" do
+ it "returns self's absolute fixnum value" do
+ { 0 => [0, -0, +0], 2 => [2, -2, +2], 100 => [100, -100, +100] }.each do |key, values|
+ values.each do |value|
+ value.send(@method).should == key
+ end
+ end
+ end
+ end
+
+ context "bignum" do
+ it "returns the absolute bignum value" do
+ bignum_value(39).send(@method).should == 9223372036854775847
+ (-bignum_value(18)).send(@method).should == 9223372036854775826
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/arithmetic_coerce.rb b/spec/ruby/core/integer/shared/arithmetic_coerce.rb
new file mode 100644
index 0000000000..e33c5ff0f4
--- /dev/null
+++ b/spec/ruby/core/integer/shared/arithmetic_coerce.rb
@@ -0,0 +1,31 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+describe :integer_arithmetic_coerce_rescue, shared: true do
+ it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
+
+ # e.g. 1 + b
+ -> { 1.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into Integer/)
+ end
+
+ it "does not rescue Exception and StandardError siblings raised in other#coerce" do
+ [Exception, NoMemoryError].each do |exception|
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(exception)
+
+ # e.g. 1 + b
+ -> { 1.send(@method, b) }.should raise_error(exception)
+ end
+ end
+end
+
+describe :integer_arithmetic_coerce_not_rescue, shared: true do
+ it "does not rescue exception raised in other#coerce" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
+
+ # e.g. 1 + b
+ -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError)
+ end
+end
diff --git a/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb
deleted file mode 100644
index dd3f55d444..0000000000
--- a/spec/ruby/core/integer/shared/arithmetic_exception_in_coerce.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :integer_arithmetic_exception_in_coerce, shared: true do
- ruby_version_is ""..."2.5" do
- it "rescues exception (StandardError and subclasses) raised in other#coerce and raises TypeError" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
-
- # e.g. 1 + b
- -> { 1.send(@method, b) }.should raise_error(TypeError, /MockObject can't be coerced into #{1.class}/)
- end
-
- it "does not rescue Exception and StandardError siblings raised in other#coerce" do
- [Exception, NoMemoryError].each do |exception|
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(exception)
-
- # e.g. 1 + b
- -> { 1.send(@method, b) }.should raise_error(exception)
- end
- end
- end
-
- ruby_version_is "2.5" do
- it "does not rescue exception raised in other#coerce" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
-
- # e.g. 1 + b
- -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError)
- end
- end
-end
diff --git a/spec/ruby/core/integer/shared/comparison_coerce.rb b/spec/ruby/core/integer/shared/comparison_coerce.rb
new file mode 100644
index 0000000000..6d5e69b774
--- /dev/null
+++ b/spec/ruby/core/integer/shared/comparison_coerce.rb
@@ -0,0 +1,33 @@
+require File.expand_path('../../fixtures/classes', __FILE__)
+
+describe :integer_comparison_coerce_rescue, shared: true do
+ it "rescues exception (StandardError and subclasses) raised in other#coerce and raises ArgumentError" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
+
+ # e.g. 1 > b
+ -> {
+ -> { 1.send(@method, b) }.should raise_error(ArgumentError, /comparison of Integer with MockObject failed/)
+ }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/)
+ end
+
+ it "does not rescue Exception and StandardError siblings raised in other#coerce" do
+ [Exception, NoMemoryError].each do |exception|
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(exception)
+
+ # e.g. 1 > b
+ -> { 1.send(@method, b) }.should raise_error(exception)
+ end
+ end
+end
+
+describe :integer_comparison_coerce_not_rescue, shared: true do
+ it "does not rescue exception raised in other#coerce" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
+
+ # e.g. 1 > b
+ -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError)
+ end
+end
diff --git a/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb
deleted file mode 100644
index f99d680d6d..0000000000
--- a/spec/ruby/core/integer/shared/comparison_exception_in_coerce.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :integer_comparison_exception_in_coerce, shared: true do
- ruby_version_is ""..."2.5" do
- it "rescues exception (StandardError and subclasses) raised in other#coerce and raises ArgumentError" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
-
- # e.g. 1 > b
- -> {
- -> { 1.send(@method, b) }.should raise_error(ArgumentError, /comparison of #{1.class} with MockObject failed/)
- }.should complain(/Numerical comparison operators will no more rescue exceptions of #coerce/)
- end
-
- it "does not rescue Exception and StandardError siblings raised in other#coerce" do
- [Exception, NoMemoryError].each do |exception|
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(exception)
-
- # e.g. 1 > b
- -> { 1.send(@method, b) }.should raise_error(exception)
- end
- end
- end
-
- ruby_version_is "2.5" do
- it "does not rescue exception raised in other#coerce" do
- b = mock("numeric with failed #coerce")
- b.should_receive(:coerce).and_raise(IntegerSpecs::CoerceError)
-
- # e.g. 1 > b
- -> { 1.send(@method, b) }.should raise_error(IntegerSpecs::CoerceError)
- end
- end
-end
diff --git a/spec/ruby/core/integer/shared/equal.rb b/spec/ruby/core/integer/shared/equal.rb
new file mode 100644
index 0000000000..03416b60f5
--- /dev/null
+++ b/spec/ruby/core/integer/shared/equal.rb
@@ -0,0 +1,58 @@
+describe :integer_equal, shared: true do
+ context "fixnum" do
+ it "returns true if self has the same value as other" do
+ 1.send(@method, 1).should == true
+ 9.send(@method, 5).should == false
+
+ # Actually, these call Float#==, Bignum#== etc.
+ 9.send(@method, 9.0).should == true
+ 9.send(@method, 9.01).should == false
+
+ 10.send(@method, bignum_value).should == false
+ end
+
+ it "calls 'other == self' if the given argument is not a Integer" do
+ 1.send(@method, '*').should == false
+
+ obj = mock('one other')
+ obj.should_receive(:==).any_number_of_times.and_return(false)
+ 1.send(@method, obj).should == false
+
+ obj = mock('another')
+ obj.should_receive(:==).any_number_of_times.and_return(true)
+ 2.send(@method, obj).should == true
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value
+ end
+
+ it "returns true if self has the same value as the given argument" do
+ @bignum.send(@method, @bignum).should == true
+ @bignum.send(@method, @bignum.to_f).should == true
+
+ @bignum.send(@method, @bignum + 1).should == false
+ (@bignum + 1).send(@method, @bignum).should == false
+
+ @bignum.send(@method, 9).should == false
+ @bignum.send(@method, 9.01).should == false
+
+ @bignum.send(@method, bignum_value(10)).should == false
+ end
+
+ it "calls 'other == self' if the given argument is not an Integer" do
+ obj = mock('not integer')
+ obj.should_receive(:==).and_return(true)
+ @bignum.send(@method, obj).should == true
+ end
+
+ it "returns the result of 'other == self' as a boolean" do
+ obj = mock('not integer')
+ obj.should_receive(:==).exactly(2).times.and_return("woot", nil)
+ @bignum.send(@method, obj).should == true
+ @bignum.send(@method, obj).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/exponent.rb b/spec/ruby/core/integer/shared/exponent.rb
new file mode 100644
index 0000000000..810e2a7101
--- /dev/null
+++ b/spec/ruby/core/integer/shared/exponent.rb
@@ -0,0 +1,118 @@
+describe :integer_exponent, shared: true do
+ context "fixnum" do
+ it "returns self raised to the given power" do
+ 2.send(@method, 0).should eql 1
+ 2.send(@method, 1).should eql 2
+ 2.send(@method, 2).should eql 4
+
+ 9.send(@method, 0.5).should eql 3.0
+ 9.send(@method, Rational(1, 2)).should eql 3.0
+ 5.send(@method, -1).to_f.to_s.should == '0.2'
+
+ 2.send(@method, 40).should eql 1099511627776
+ end
+
+ it "overflows the answer to a bignum transparently" do
+ 2.send(@method, 29).should eql 536870912
+ 2.send(@method, 30).should eql 1073741824
+ 2.send(@method, 31).should eql 2147483648
+ 2.send(@method, 32).should eql 4294967296
+
+ 2.send(@method, 61).should eql 2305843009213693952
+ 2.send(@method, 62).should eql 4611686018427387904
+ 2.send(@method, 63).should eql 9223372036854775808
+ 2.send(@method, 64).should eql 18446744073709551616
+ 8.send(@method, 23).should eql 590295810358705651712
+ end
+
+ it "raises negative numbers to the given power" do
+ (-2).send(@method, 29).should eql(-536870912)
+ (-2).send(@method, 30).should eql(1073741824)
+ (-2).send(@method, 31).should eql(-2147483648)
+ (-2).send(@method, 32).should eql(4294967296)
+
+ (-2).send(@method, 61).should eql(-2305843009213693952)
+ (-2).send(@method, 62).should eql(4611686018427387904)
+ (-2).send(@method, 63).should eql(-9223372036854775808)
+ (-2).send(@method, 64).should eql(18446744073709551616)
+ end
+
+ it "can raise 1 to a bignum safely" do
+ 1.send(@method, 4611686018427387904).should eql 1
+ end
+
+ it "can raise -1 to a bignum safely" do
+ (-1).send(@method, 4611686018427387904).should eql(1)
+ (-1).send(@method, 4611686018427387905).should eql(-1)
+ end
+
+ it "returns Float::INFINITY when the number is too big" do
+ 2.send(@method, 427387904).should == Float::INFINITY
+ end
+
+ it "raises a ZeroDivisionError for 0 ** -1" do
+ -> { 0.send(@method, -1) }.should raise_error(ZeroDivisionError)
+ -> { 0.send(@method, Rational(-1, 1)) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "returns Float::INFINITY for 0 ** -1.0" do
+ 0.send(@method, -1.0).should == Float::INFINITY
+ end
+
+ it "raises a TypeError when given a non-numeric power" do
+ -> { 13.send(@method, "10") }.should raise_error(TypeError)
+ -> { 13.send(@method, :symbol) }.should raise_error(TypeError)
+ -> { 13.send(@method, nil) }.should raise_error(TypeError)
+ end
+
+ it "coerces power and calls #**" do
+ num_2 = mock("2")
+ num_13 = mock("13")
+ num_2.should_receive(:coerce).with(13).and_return([num_13, num_2])
+ num_13.should_receive(:**).with(num_2).and_return(169)
+
+ 13.send(@method, num_2).should == 169
+ end
+
+ it "returns Float when power is Float" do
+ 2.send(@method, 2.0).should == 4.0
+ end
+
+ it "returns Rational when power is Rational" do
+ 2.send(@method, Rational(2, 1)).should == Rational(4, 1)
+ end
+
+ it "returns a complex number when negative and raised to a fractional power" do
+ (-8).send(@method, 1.0/3) .should be_close(Complex(1, 1.73205), TOLERANCE)
+ (-8).send(@method, Rational(1, 3)).should be_close(Complex(1, 1.73205), TOLERANCE)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(47)
+ end
+
+ it "returns self raised to other power" do
+ (@bignum.send(@method, 4)).should == 7237005577332262361485077344629993318496048279512298547155833600056910050625
+ (@bignum.send(@method, 1.2)).should be_close(57262152889751597425762.57804, TOLERANCE)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
+ lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
+ lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
+ end
+
+ it "switch to a Float when the values is too big" do
+ flt = @bignum.send(@method, @bignum)
+ flt.should be_kind_of(Float)
+ flt.infinite?.should == 1
+ end
+
+ it "returns a complex number when negative and raised to a fractional power" do
+ ((-@bignum).send(@method, (1.0/3))) .should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
+ ((-@bignum).send(@method, Rational(1,3))).should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/modulo.rb b/spec/ruby/core/integer/shared/modulo.rb
new file mode 100644
index 0000000000..d545a9af55
--- /dev/null
+++ b/spec/ruby/core/integer/shared/modulo.rb
@@ -0,0 +1,74 @@
+describe :integer_modulo, shared: true do
+ context "fixnum" do
+ it "returns the modulus obtained from dividing self by the given argument" do
+ 13.send(@method, 4).should == 1
+ 4.send(@method, 13).should == 4
+
+ 13.send(@method, 4.0).should == 1
+ 4.send(@method, 13.0).should == 4
+
+ (-200).send(@method, 256).should == 56
+ (-1000).send(@method, 512).should == 24
+
+ (-200).send(@method, -256).should == -200
+ (-1000).send(@method, -512).should == -488
+
+ (200).send(@method, -256).should == -56
+ (1000).send(@method, -512).should == -24
+
+ 1.send(@method, 2.0).should == 1.0
+ 200.send(@method, bignum_value).should == 200
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ lambda { 13.send(@method, 0) }.should raise_error(ZeroDivisionError)
+ lambda { 0.send(@method, 0) }.should raise_error(ZeroDivisionError)
+ lambda { -10.send(@method, 0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { 0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
+ lambda { 10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
+ lambda { -10.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13.send(@method, obj)
+ }.should raise_error(TypeError)
+ lambda { 13.send(@method, "10") }.should raise_error(TypeError)
+ lambda { 13.send(@method, :symbol) }.should raise_error(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value
+ end
+
+ it "returns the modulus obtained from dividing self by the given argument" do
+ @bignum.send(@method, 5).should == 3
+ @bignum.send(@method, -5).should == -2
+ @bignum.send(@method, -100).should == -92
+ @bignum.send(@method, 2.22).should be_close(0.780180180180252, TOLERANCE)
+ @bignum.send(@method, bignum_value(10)).should == 9223372036854775808
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ lambda { @bignum.send(@method, 0) }.should raise_error(ZeroDivisionError)
+ lambda { (-@bignum).send(@method, 0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ lambda { @bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
+ lambda { -@bignum.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ lambda { @bignum.send(@method, mock('10')) }.should raise_error(TypeError)
+ lambda { @bignum.send(@method, "10") }.should raise_error(TypeError)
+ lambda { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/size_spec.rb b/spec/ruby/core/integer/size_spec.rb
new file mode 100644
index 0000000000..dc0519d6b9
--- /dev/null
+++ b/spec/ruby/core/integer/size_spec.rb
@@ -0,0 +1,34 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#size" do
+ platform_is wordsize: 32 do
+ it "returns the number of bytes in the machine representation of self" do
+ -1.size.should == 4
+ 0.size.should == 4
+ 4091.size.should == 4
+ end
+ end
+
+ platform_is wordsize: 64 do
+ it "returns the number of bytes in the machine representation of self" do
+ -1.size.should == 8
+ 0.size.should == 8
+ 4091.size.should == 8
+ end
+ end
+
+ context "bignum" do
+ it "returns the number of bytes required to hold the unsigned bignum data" do
+ # that is, n such that 256 * n <= val.abs < 256 * (n+1)
+ (256**7).size.should == 8
+ (256**8).size.should == 9
+ (256**9).size.should == 10
+ (256**10).size.should == 11
+ (256**10-1).size.should == 10
+ (256**11).size.should == 12
+ (256**12).size.should == 13
+ (256**20-1).size.should == 20
+ (256**40-1).size.should == 40
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/succ_spec.rb b/spec/ruby/core/integer/succ_spec.rb
index a1405684fc..fc6bd84093 100644
--- a/spec/ruby/core/integer/succ_spec.rb
+++ b/spec/ruby/core/integer/succ_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/next', __FILE__)
describe "Integer#succ" do
- it_behaves_like(:integer_next, :succ)
+ it_behaves_like :integer_next, :succ
end
diff --git a/spec/ruby/core/integer/to_f_spec.rb b/spec/ruby/core/integer/to_f_spec.rb
new file mode 100644
index 0000000000..5a4ca18128
--- /dev/null
+++ b/spec/ruby/core/integer/to_f_spec.rb
@@ -0,0 +1,23 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#to_f" do
+ context "fixnum" do
+ it "returns self converted to a Float" do
+ 0.to_f.should == 0.0
+ -500.to_f.should == -500.0
+ 9_641_278.to_f.should == 9641278.0
+ end
+ end
+
+ context "bignum" do
+ it "returns self converted to a Float" do
+ bignum_value(0x4000_0aa0_0bb0_0000).to_f.should eql(13_835_069_737_789_292_544.00)
+ bignum_value(0x8000_0000_0000_0ccc).to_f.should eql(18_446_744_073_709_555_712.00)
+ (-bignum_value(99)).to_f.should eql(-9_223_372_036_854_775_808.00)
+ end
+
+ it "converts number close to Float::MAX without exceeding MAX or producing NaN" do
+ (10**308).to_f.should == 10.0 ** 308
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/to_i_spec.rb b/spec/ruby/core/integer/to_i_spec.rb
index 1e6f21f191..8134048b5d 100644
--- a/spec/ruby/core/integer/to_i_spec.rb
+++ b/spec/ruby/core/integer/to_i_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Integer#to_i" do
- it_behaves_like(:integer_to_i, :to_i)
+ it_behaves_like :integer_to_i, :to_i
end
diff --git a/spec/ruby/core/integer/to_int_spec.rb b/spec/ruby/core/integer/to_int_spec.rb
index 5e87c86ccd..349cb2e4e7 100644
--- a/spec/ruby/core/integer/to_int_spec.rb
+++ b/spec/ruby/core/integer/to_int_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Integer#to_int" do
- it_behaves_like(:integer_to_i, :to_int)
+ it_behaves_like :integer_to_i, :to_int
end
diff --git a/spec/ruby/core/integer/to_s_spec.rb b/spec/ruby/core/integer/to_s_spec.rb
new file mode 100644
index 0000000000..63f5995457
--- /dev/null
+++ b/spec/ruby/core/integer/to_s_spec.rb
@@ -0,0 +1,99 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#to_s" do
+ context "fixnum" do
+ context "when given a base" do
+ it "returns self converted to a String in the given base" do
+ 12345.to_s(2).should == "11000000111001"
+ 12345.to_s(8).should == "30071"
+ 12345.to_s(10).should == "12345"
+ 12345.to_s(16).should == "3039"
+ 95.to_s(16).should == "5f"
+ 12345.to_s(36).should == "9ix"
+ end
+
+ it "raises an ArgumentError if the base is less than 2 or higher than 36" do
+ lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(0) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(1) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(37) }.should raise_error(ArgumentError)
+ end
+ end
+
+ context "when no base given" do
+ it "returns self converted to a String using base 10" do
+ 255.to_s.should == '255'
+ 3.to_s.should == '3'
+ 0.to_s.should == '0'
+ -9002.to_s.should == '-9002'
+ end
+ end
+
+ with_feature :encoding do
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ end
+
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ 1.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
+
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
+ Encoding.default_internal = Encoding::IBM437
+ 1.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
+ end
+ end
+
+ context "bignum" do
+ describe "when given a base" do
+ it "returns self converted to a String using the given base" do
+ a = 2**64
+ a.to_s(2).should == "10000000000000000000000000000000000000000000000000000000000000000"
+ a.to_s(8).should == "2000000000000000000000"
+ a.to_s(16).should == "10000000000000000"
+ a.to_s(32).should == "g000000000000"
+ end
+
+ it "raises an ArgumentError if the base is less than 2 or higher than 36" do
+ lambda { 123.to_s(-1) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(0) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(1) }.should raise_error(ArgumentError)
+ lambda { 123.to_s(37) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "when given no base" do
+ it "returns self converted to a String using base 10" do
+ bignum_value(9).to_s.should == "9223372036854775817"
+ bignum_value.to_s.should == "9223372036854775808"
+ (-bignum_value(675)).to_s.should == "-9223372036854776483"
+ end
+ end
+
+ with_feature :encoding do
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ end
+
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
+
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is not nil" do
+ Encoding.default_internal = Encoding::IBM437
+ bignum_value.to_s.encoding.should equal(Encoding::US_ASCII)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/truncate_spec.rb b/spec/ruby/core/integer/truncate_spec.rb
index 429ab1a312..98d40b3026 100644
--- a/spec/ruby/core/integer/truncate_spec.rb
+++ b/spec/ruby/core/integer/truncate_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../shared/to_i', __FILE__)
require File.expand_path('../shared/integer_rounding', __FILE__)
describe "Integer#truncate" do
- it_behaves_like(:integer_to_i, :truncate)
- it_behaves_like(:integer_rounding_positive_precision, :truncate)
+ it_behaves_like :integer_to_i, :truncate
+ it_behaves_like :integer_rounding_positive_precision, :truncate
ruby_version_is "2.4" do
context "precision argument specified as part of the truncate method is negative" do
diff --git a/spec/ruby/core/integer/uminus_spec.rb b/spec/ruby/core/integer/uminus_spec.rb
new file mode 100644
index 0000000000..ad7cd194e3
--- /dev/null
+++ b/spec/ruby/core/integer/uminus_spec.rb
@@ -0,0 +1,28 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe "Integer#-@" do
+ context "fixnum" do
+ it "returns self as a negative value" do
+ 2.send(:-@).should == -2
+ -2.should == -2
+ -268435455.should == -268435455
+ (--5).should == 5
+ -8.send(:-@).should == 8
+ end
+
+ it "negates self at Fixnum/Bignum boundaries" do
+ fixnum_max.send(:-@).should == (0 - fixnum_max)
+ fixnum_min.send(:-@).should == (0 - fixnum_min)
+ end
+ end
+
+ context "bignum" do
+ it "returns self as a negative value" do
+ bignum_value.send(:-@).should == -9223372036854775808
+ (-bignum_value).send(:-@).should == 9223372036854775808
+
+ bignum_value(921).send(:-@).should == -9223372036854776729
+ (-bignum_value(921).send(:-@)).should == 9223372036854776729
+ end
+ end
+end
diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb
index 0e51ec23d2..77a8748e7c 100644
--- a/spec/ruby/core/io/close_spec.rb
+++ b/spec/ruby/core/io/close_spec.rb
@@ -31,6 +31,13 @@ describe "IO#close" do
lambda { @io.write "data" }.should raise_error(IOError)
end
+ it 'does not close the stream if autoclose is false' do
+ other_io = IO.new(@io.fileno)
+ other_io.autoclose = false
+ other_io.close
+ lambda { @io.write "data" }.should_not raise_error(IOError)
+ end
+
ruby_version_is ''...'2.3' do
it "raises an IOError if closed" do
@io.close
@@ -45,6 +52,24 @@ describe "IO#close" do
@io.close.should be_nil
end
end
+
+ ruby_version_is '2.5' do
+ it 'raises an IOError with a clear message' do
+ read_io, write_io = IO.pipe
+ going_to_read = false
+ thread = Thread.new do
+ lambda do
+ going_to_read = true
+ read_io.read
+ end.should raise_error(IOError, 'stream closed in another thread')
+ end
+
+ Thread.pass until going_to_read && thread.stop?
+ read_io.close
+ thread.join
+ write_io.close
+ end
+ end
end
describe "IO#close on an IO.popen stream" do
@@ -79,4 +104,3 @@ describe "IO#close on an IO.popen stream" do
end
end
-
diff --git a/spec/ruby/core/io/codepoints_spec.rb b/spec/ruby/core/io/codepoints_spec.rb
index 6e6b9613b5..b232a9c598 100644
--- a/spec/ruby/core/io/codepoints_spec.rb
+++ b/spec/ruby/core/io/codepoints_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path('../shared/codepoints', __FILE__)
# See redmine #1667
describe "IO#codepoints" do
- it_behaves_like(:io_codepoints, :codepoints)
+ it_behaves_like :io_codepoints, :codepoints
end
describe "IO#codepoints" do
diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb
index eb16e004fa..2bcf898c89 100644
--- a/spec/ruby/core/io/each_codepoint_spec.rb
+++ b/spec/ruby/core/io/each_codepoint_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path('../shared/codepoints', __FILE__)
# See redmine #1667
describe "IO#each_codepoint" do
- it_behaves_like(:io_codepoints, :codepoints)
+ it_behaves_like :io_codepoints, :codepoints
end
describe "IO#each_codepoint" do
diff --git a/spec/ruby/core/io/tell_spec.rb b/spec/ruby/core/io/tell_spec.rb
index d2f523cf10..cc54012a37 100644
--- a/spec/ruby/core/io/tell_spec.rb
+++ b/spec/ruby/core/io/tell_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/pos', __FILE__)
describe "IO#tell" do
- it_behaves_like(:io_pos, :tell)
+ it_behaves_like :io_pos, :tell
end
diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb
index ce4cc9d346..488e587f5a 100644
--- a/spec/ruby/core/io/ungetc_spec.rb
+++ b/spec/ruby/core/io/ungetc_spec.rb
@@ -31,6 +31,22 @@ describe "IO#ungetc" do
@io.getc.should == ?c
end
+ it "interprets the codepoint in the external encoding" do
+ @io.set_encoding(Encoding::UTF_8)
+ @io.ungetc(233)
+ c = @io.getc
+ c.encoding.should == Encoding::UTF_8
+ c.should == "é"
+ c.bytes.should == [195, 169]
+
+ @io.set_encoding(Encoding::IBM437)
+ @io.ungetc(130)
+ c = @io.getc
+ c.encoding.should == Encoding::IBM437
+ c.bytes.should == [130]
+ c.encode(Encoding::UTF_8).should == "é"
+ end
+
it "pushes back one character when invoked at the end of the stream" do
# read entire content
@io.read
diff --git a/spec/ruby/core/kernel/Hash_spec.rb b/spec/ruby/core/kernel/Hash_spec.rb
index 8d51316c75..049987758e 100644
--- a/spec/ruby/core/kernel/Hash_spec.rb
+++ b/spec/ruby/core/kernel/Hash_spec.rb
@@ -2,7 +2,13 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "Kernel#hash" do
- it "needs to be reviewed for spec completeness"
+ it "is provided" do
+ 1.respond_to?(:hash).should == true
+ end
+
+ it "is stable" do
+ 1.hash.should == 1.hash
+ end
end
describe "Kernel" do
diff --git a/spec/ruby/core/kernel/is_a_spec.rb b/spec/ruby/core/kernel/is_a_spec.rb
index c67c6552a0..529de300e1 100644
--- a/spec/ruby/core/kernel/is_a_spec.rb
+++ b/spec/ruby/core/kernel/is_a_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/kind_of', __FILE__)
describe "Kernel#is_a?" do
- it_behaves_like(:kernel_kind_of , :is_a?)
+ it_behaves_like :kernel_kind_of , :is_a?
end
diff --git a/spec/ruby/core/kernel/kind_of_spec.rb b/spec/ruby/core/kernel/kind_of_spec.rb
index 56a54ec859..820245e0ee 100644
--- a/spec/ruby/core/kernel/kind_of_spec.rb
+++ b/spec/ruby/core/kernel/kind_of_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/kind_of', __FILE__)
describe "Kernel#kind_of?" do
- it_behaves_like(:kernel_kind_of , :kind_of?)
+ it_behaves_like :kernel_kind_of , :kind_of?
end
diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb
index 8fa0075675..d959539757 100644
--- a/spec/ruby/core/kernel/lambda_spec.rb
+++ b/spec/ruby/core/kernel/lambda_spec.rb
@@ -5,7 +5,7 @@ require File.expand_path('../shared/lambda', __FILE__)
# The functionality of lambdas is specified in core/proc
describe "Kernel.lambda" do
- it_behaves_like(:kernel_lambda, :lambda)
+ it_behaves_like :kernel_lambda, :lambda
it "is a private method" do
Kernel.should have_private_instance_method(:lambda)
diff --git a/spec/ruby/core/kernel/method_spec.rb b/spec/ruby/core/kernel/method_spec.rb
index 09a3f940ca..89ef026ac3 100644
--- a/spec/ruby/core/kernel/method_spec.rb
+++ b/spec/ruby/core/kernel/method_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/method', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "Kernel#method" do
- it_behaves_like(:kernel_method, :method)
+ it_behaves_like :kernel_method, :method
before :each do
@obj = KernelSpecs::A.new
diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb
index 4e4854f97d..f60dcfedb6 100644
--- a/spec/ruby/core/kernel/proc_spec.rb
+++ b/spec/ruby/core/kernel/proc_spec.rb
@@ -22,7 +22,7 @@ describe "Kernel.proc" do
l.lambda?.should be_true
end
- it_behaves_like(:kernel_lambda, :proc)
+ it_behaves_like :kernel_lambda, :proc
it "returns from the creation site of the proc, not just the proc itself" do
@reached_end_of_method = nil
diff --git a/spec/ruby/core/kernel/public_method_spec.rb b/spec/ruby/core/kernel/public_method_spec.rb
index f1cc168420..eabc6ab22e 100644
--- a/spec/ruby/core/kernel/public_method_spec.rb
+++ b/spec/ruby/core/kernel/public_method_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/method', __FILE__)
describe "Kernel#public_method" do
- it_behaves_like(:kernel_method, :public_method)
+ it_behaves_like :kernel_method, :public_method
before :each do
@obj = KernelSpecs::A.new
diff --git a/spec/ruby/core/kernel/public_send_spec.rb b/spec/ruby/core/kernel/public_send_spec.rb
index 2eabbc7dc9..346673d8a4 100644
--- a/spec/ruby/core/kernel/public_send_spec.rb
+++ b/spec/ruby/core/kernel/public_send_spec.rb
@@ -104,5 +104,5 @@ describe "Kernel#public_send" do
}.should raise_error(NoMethodError)
end
- it_behaves_like(:basicobject_send, :public_send)
+ it_behaves_like :basicobject_send, :public_send
end
diff --git a/spec/ruby/core/kernel/send_spec.rb b/spec/ruby/core/kernel/send_spec.rb
index 8afd16e97c..e7eed6b265 100644
--- a/spec/ruby/core/kernel/send_spec.rb
+++ b/spec/ruby/core/kernel/send_spec.rb
@@ -64,5 +64,5 @@ describe "Kernel#send" do
KernelSpecs::Foo.new.send(:aka).should == 'done2'
end
- it_behaves_like(:basicobject_send, :send)
+ it_behaves_like :basicobject_send, :send
end
diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb
index e595a06640..9935d27db9 100644
--- a/spec/ruby/core/kernel/shared/sprintf.rb
+++ b/spec/ruby/core/kernel/shared/sprintf.rb
@@ -1,3 +1,5 @@
+require File.expand_path('../../../../shared/hash/key_error', __FILE__)
+
describe :kernel_sprintf, shared: true do
def format(*args)
@method.call(*args)
@@ -823,12 +825,6 @@ describe :kernel_sprintf, shared: true do
format("%d %<foo>d", 1, foo: "123")
}.should raise_error(ArgumentError)
end
-
- it "raises KeyError when there is no matching key" do
- -> () {
- format("%<foo>s", {})
- }.should raise_error(KeyError)
- end
end
describe "%{name} style" do
@@ -868,4 +864,14 @@ describe :kernel_sprintf, shared: true do
end
end
end
+
+ describe "faulty key" do
+ before :all do
+ @base_method = @method
+ end
+
+ it_behaves_like :key_error, -> (obj, key) {
+ @base_method.call("%<#{key}>s", obj)
+ }, { foooo: 1 }
+ end
end
diff --git a/spec/ruby/core/kernel/system_spec.rb b/spec/ruby/core/kernel/system_spec.rb
index a3dfbeba05..c6bc4416e7 100644
--- a/spec/ruby/core/kernel/system_spec.rb
+++ b/spec/ruby/core/kernel/system_spec.rb
@@ -25,12 +25,14 @@ describe :kernel_system, shared: true do
$?.exitstatus.should == 1
end
- it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do
- lambda { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError)
- end
+ ruby_version_is "2.6" do
+ it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do
+ lambda { @object.system(ruby_cmd('exit 1'), exception: true) }.should raise_error(RuntimeError)
+ end
- it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do
- lambda { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT)
+ it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do
+ lambda { @object.system('feature_14386', exception: true) }.should raise_error(Errno::ENOENT)
+ end
end
it "returns nil when command execution fails" do
diff --git a/spec/ruby/core/kernel/yield_self_spec.rb b/spec/ruby/core/kernel/yield_self_spec.rb
index 817c01f288..9c81be463d 100644
--- a/spec/ruby/core/kernel/yield_self_spec.rb
+++ b/spec/ruby/core/kernel/yield_self_spec.rb
@@ -1,8 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
-has_yield_self = VersionGuard.new("2.5").match? || PlatformGuard.implementation?(:truffleruby)
-
-if has_yield_self
+ruby_version_is "2.5" do
describe "Kernel#yield_self" do
it "yields self" do
object = Object.new
diff --git a/spec/ruby/core/matchdata/eql_spec.rb b/spec/ruby/core/matchdata/eql_spec.rb
index 192acbcd13..d141fee97f 100644
--- a/spec/ruby/core/matchdata/eql_spec.rb
+++ b/spec/ruby/core/matchdata/eql_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql', __FILE__)
describe "MatchData#eql?" do
- it_behaves_like(:matchdata_eql, :eql?)
+ it_behaves_like :matchdata_eql, :eql?
end
diff --git a/spec/ruby/core/matchdata/equal_value_spec.rb b/spec/ruby/core/matchdata/equal_value_spec.rb
index 0d33d0acf2..1fd471d3de 100644
--- a/spec/ruby/core/matchdata/equal_value_spec.rb
+++ b/spec/ruby/core/matchdata/equal_value_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql', __FILE__)
describe "MatchData#==" do
- it_behaves_like(:matchdata_eql, :==)
+ it_behaves_like :matchdata_eql, :==
end
diff --git a/spec/ruby/core/matchdata/length_spec.rb b/spec/ruby/core/matchdata/length_spec.rb
index 75cf607598..adbe81902a 100644
--- a/spec/ruby/core/matchdata/length_spec.rb
+++ b/spec/ruby/core/matchdata/length_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "MatchData#length" do
- it_behaves_like(:matchdata_length, :length)
+ it_behaves_like :matchdata_length, :length
end
diff --git a/spec/ruby/core/matchdata/size_spec.rb b/spec/ruby/core/matchdata/size_spec.rb
index e043f51870..8c990a8a77 100644
--- a/spec/ruby/core/matchdata/size_spec.rb
+++ b/spec/ruby/core/matchdata/size_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "MatchData#size" do
- it_behaves_like(:matchdata_length, :size)
+ it_behaves_like :matchdata_length, :size
end
diff --git a/spec/ruby/core/method/call_spec.rb b/spec/ruby/core/method/call_spec.rb
index 1a90028176..1c2735de21 100644
--- a/spec/ruby/core/method/call_spec.rb
+++ b/spec/ruby/core/method/call_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/call', __FILE__)
describe "Method#call" do
- it_behaves_like(:method_call, :call)
+ it_behaves_like :method_call, :call
end
diff --git a/spec/ruby/core/method/case_compare_spec.rb b/spec/ruby/core/method/case_compare_spec.rb
index f75eff873c..a80e4b1782 100644
--- a/spec/ruby/core/method/case_compare_spec.rb
+++ b/spec/ruby/core/method/case_compare_spec.rb
@@ -4,6 +4,6 @@ require File.expand_path('../shared/call', __FILE__)
ruby_version_is "2.5" do
describe "Method#===" do
- it_behaves_like(:method_call, :===)
+ it_behaves_like :method_call, :===
end
end
diff --git a/spec/ruby/core/method/element_reference_spec.rb b/spec/ruby/core/method/element_reference_spec.rb
index 0be47afede..1e5efc0dd3 100644
--- a/spec/ruby/core/method/element_reference_spec.rb
+++ b/spec/ruby/core/method/element_reference_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/call', __FILE__)
describe "Method#[]" do
- it_behaves_like(:method_call, :[])
+ it_behaves_like :method_call, :[]
end
diff --git a/spec/ruby/core/method/eql_spec.rb b/spec/ruby/core/method/eql_spec.rb
index f8914e1d12..da43c6d770 100644
--- a/spec/ruby/core/method/eql_spec.rb
+++ b/spec/ruby/core/method/eql_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql', __FILE__)
describe "Method#eql?" do
- it_behaves_like(:method_equal, :eql?)
+ it_behaves_like :method_equal, :eql?
end
diff --git a/spec/ruby/core/method/equal_value_spec.rb b/spec/ruby/core/method/equal_value_spec.rb
index 365e0ac424..aba0c9f256 100644
--- a/spec/ruby/core/method/equal_value_spec.rb
+++ b/spec/ruby/core/method/equal_value_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql', __FILE__)
describe "Method#==" do
- it_behaves_like(:method_equal, :==)
+ it_behaves_like :method_equal, :==
end
diff --git a/spec/ruby/core/method/inspect_spec.rb b/spec/ruby/core/method/inspect_spec.rb
index bfb61daf53..70aab95434 100644
--- a/spec/ruby/core/method/inspect_spec.rb
+++ b/spec/ruby/core/method/inspect_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_s', __FILE__)
describe "Method#inspect" do
- it_behaves_like(:method_to_s, :inspect)
+ it_behaves_like :method_to_s, :inspect
end
diff --git a/spec/ruby/core/method/to_proc_spec.rb b/spec/ruby/core/method/to_proc_spec.rb
index 5a754f8597..87593108ff 100644
--- a/spec/ruby/core/method/to_proc_spec.rb
+++ b/spec/ruby/core/method/to_proc_spec.rb
@@ -55,6 +55,10 @@ describe "Method#to_proc" do
x.baz(1,2,3,&m).should == [1,2,3]
end
+ it "returns a proc whose binding has the same receiver as the method" do
+ @meth.receiver.should == @meth.to_proc.binding.receiver
+ end
+
# #5926
it "returns a proc that can receive a block" do
x = Object.new
diff --git a/spec/ruby/core/method/to_s_spec.rb b/spec/ruby/core/method/to_s_spec.rb
index 1bf341f2a6..8234871855 100644
--- a/spec/ruby/core/method/to_s_spec.rb
+++ b/spec/ruby/core/method/to_s_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_s', __FILE__)
describe "Method#to_s" do
- it_behaves_like(:method_to_s, :to_s)
+ it_behaves_like :method_to_s, :to_s
end
diff --git a/spec/ruby/core/module/const_missing_spec.rb b/spec/ruby/core/module/const_missing_spec.rb
index 24f2b49edc..c6143f2b4c 100644
--- a/spec/ruby/core/module/const_missing_spec.rb
+++ b/spec/ruby/core/module/const_missing_spec.rb
@@ -24,4 +24,13 @@ describe "Module#const_missing" do
end
end
+ it "is called regardless of visibility" do
+ klass = Class.new do
+ def self.const_missing(name)
+ "Found:#{name}"
+ end
+ private_class_method :const_missing
+ end
+ klass::Hello.should == 'Found:Hello'
+ end
end
diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb
index be0e2f0a0b..94995414b7 100644
--- a/spec/ruby/core/module/define_method_spec.rb
+++ b/spec/ruby/core/module/define_method_spec.rb
@@ -631,3 +631,28 @@ describe "Method#define_method when passed an UnboundMethod object" do
@obj.method(:n).parameters.should == @obj.method(:m).parameters
end
end
+
+describe "Method#define_method when passed a Proc object" do
+ describe "and a method is defined inside" do
+ it "defines the nested method in the default definee where the Proc was created" do
+ prc = nil
+ t = Class.new do
+ prc = -> {
+ def nested_method_in_proc_for_define_method
+ 42
+ end
+ }
+ end
+
+ c = Class.new do
+ define_method(:test, prc)
+ end
+
+ o = c.new
+ o.test
+ o.should_not have_method :nested_method_in_proc_for_define_method
+
+ t.new.nested_method_in_proc_for_define_method.should == 42
+ end
+ end
+end
diff --git a/spec/ruby/core/module/eql_spec.rb b/spec/ruby/core/module/eql_spec.rb
index f8878d7f4e..9cb7bd1d24 100644
--- a/spec/ruby/core/module/eql_spec.rb
+++ b/spec/ruby/core/module/eql_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Module#eql?" do
- it_behaves_like(:module_equal, :eql?)
+ it_behaves_like :module_equal, :eql?
end
diff --git a/spec/ruby/core/module/equal_spec.rb b/spec/ruby/core/module/equal_spec.rb
index bc70a6277a..f5d12c541a 100644
--- a/spec/ruby/core/module/equal_spec.rb
+++ b/spec/ruby/core/module/equal_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Module#equal?" do
- it_behaves_like(:module_equal, :equal?)
+ it_behaves_like :module_equal, :equal?
end
diff --git a/spec/ruby/core/module/equal_value_spec.rb b/spec/ruby/core/module/equal_value_spec.rb
index 12494477f9..f8ecede3d8 100644
--- a/spec/ruby/core/module/equal_value_spec.rb
+++ b/spec/ruby/core/module/equal_value_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Module#==" do
- it_behaves_like(:module_equal, :==)
+ it_behaves_like :module_equal, :==
end
diff --git a/spec/ruby/core/numeric/abs_spec.rb b/spec/ruby/core/numeric/abs_spec.rb
index 4aa25359a2..ac431d65d1 100644
--- a/spec/ruby/core/numeric/abs_spec.rb
+++ b/spec/ruby/core/numeric/abs_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../shared/abs', __FILE__)
describe "Numeric#abs" do
- it_behaves_like(:numeric_abs, :abs)
+ it_behaves_like :numeric_abs, :abs
end
diff --git a/spec/ruby/core/numeric/angle_spec.rb b/spec/ruby/core/numeric/angle_spec.rb
index d7134168b3..933cba9d6e 100644
--- a/spec/ruby/core/numeric/angle_spec.rb
+++ b/spec/ruby/core/numeric/angle_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
describe "Numeric#angle" do
- it_behaves_like(:numeric_arg, :angle)
+ it_behaves_like :numeric_arg, :angle
end
diff --git a/spec/ruby/core/numeric/arg_spec.rb b/spec/ruby/core/numeric/arg_spec.rb
index 0729a29226..aa43023942 100644
--- a/spec/ruby/core/numeric/arg_spec.rb
+++ b/spec/ruby/core/numeric/arg_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
describe "Numeric#arg" do
- it_behaves_like(:numeric_arg, :arg)
+ it_behaves_like :numeric_arg, :arg
end
diff --git a/spec/ruby/core/numeric/coerce_spec.rb b/spec/ruby/core/numeric/coerce_spec.rb
index 820d900dd5..63cec4a9b4 100644
--- a/spec/ruby/core/numeric/coerce_spec.rb
+++ b/spec/ruby/core/numeric/coerce_spec.rb
@@ -29,33 +29,16 @@ describe "Numeric#coerce" do
end
end
- it "calls #to_f to convert other if self responds to #to_f" do
- # Do not use NumericSpecs::Subclass here, because coerce checks the classes of the receiver
- # and arguments before calling #to_f.
- other = mock("numeric")
- lambda { @obj.coerce(other) }.should raise_error(TypeError)
- end
-
it "returns [other.to_f, self.to_f] if self and other are instances of different classes" do
- result = @obj.coerce(2.5)
- result.should == [2.5, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
-
- result = @obj.coerce(3)
- result.should == [3.0, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
-
- result = @obj.coerce("4.4")
- result.should == [4.4, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
+ @obj.coerce(2.5).should == [2.5, 10.5]
+ @obj.coerce(3).should == [3.0, 10.5]
+ @obj.coerce("4.4").should == [4.4, 10.5]
+ @obj.coerce(bignum_value).should == [bignum_value.to_f, 10.5]
+ end
- result = @obj.coerce(bignum_value)
- result.should == [bignum_value.to_f, 10.5]
- result.first.should be_kind_of(Float)
- result.last.should be_kind_of(Float)
+ it "raise TypeError if they are instances of different classes and other does not respond to #to_f" do
+ other = mock("numeric")
+ lambda { @obj.coerce(other) }.should raise_error(TypeError)
end
it "raises a TypeError when passed nil" do
@@ -70,7 +53,7 @@ describe "Numeric#coerce" do
lambda { @obj.coerce(:symbol) }.should raise_error(TypeError)
end
- it "raises an ArgumentError when passed a String" do
+ it "raises an ArgumentError when passed a non-numeric String" do
lambda { @obj.coerce("test") }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/numeric/conj_spec.rb b/spec/ruby/core/numeric/conj_spec.rb
index 8fa0fd9457..190bbf1a73 100644
--- a/spec/ruby/core/numeric/conj_spec.rb
+++ b/spec/ruby/core/numeric/conj_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
describe "Numeric#conj" do
- it_behaves_like(:numeric_conj, :conj)
+ it_behaves_like :numeric_conj, :conj
end
diff --git a/spec/ruby/core/numeric/conjugate_spec.rb b/spec/ruby/core/numeric/conjugate_spec.rb
index f7e095514e..7a9a50476a 100644
--- a/spec/ruby/core/numeric/conjugate_spec.rb
+++ b/spec/ruby/core/numeric/conjugate_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
describe "Numeric#conjugate" do
- it_behaves_like(:numeric_conj, :conjugate)
+ it_behaves_like :numeric_conj, :conjugate
end
diff --git a/spec/ruby/core/numeric/imag_spec.rb b/spec/ruby/core/numeric/imag_spec.rb
index a80e42d265..821753184f 100644
--- a/spec/ruby/core/numeric/imag_spec.rb
+++ b/spec/ruby/core/numeric/imag_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
describe "Numeric#imag" do
- it_behaves_like(:numeric_imag, :imag)
+ it_behaves_like :numeric_imag, :imag
end
diff --git a/spec/ruby/core/numeric/imaginary_spec.rb b/spec/ruby/core/numeric/imaginary_spec.rb
index 41226569b3..b9d1701840 100644
--- a/spec/ruby/core/numeric/imaginary_spec.rb
+++ b/spec/ruby/core/numeric/imaginary_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
describe "Numeric#imaginary" do
- it_behaves_like(:numeric_imag, :imaginary)
+ it_behaves_like :numeric_imag, :imaginary
end
diff --git a/spec/ruby/core/numeric/magnitude_spec.rb b/spec/ruby/core/numeric/magnitude_spec.rb
index 947ee69730..1da082cbcd 100644
--- a/spec/ruby/core/numeric/magnitude_spec.rb
+++ b/spec/ruby/core/numeric/magnitude_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../shared/abs', __FILE__)
describe "Numeric#magnitude" do
- it_behaves_like(:numeric_abs, :magnitude)
+ it_behaves_like :numeric_abs, :magnitude
end
diff --git a/spec/ruby/core/numeric/phase_spec.rb b/spec/ruby/core/numeric/phase_spec.rb
index 7c408db83b..b3bcefb09b 100644
--- a/spec/ruby/core/numeric/phase_spec.rb
+++ b/spec/ruby/core/numeric/phase_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
describe "Numeric#phase" do
- it_behaves_like(:numeric_arg, :phase)
+ it_behaves_like :numeric_arg, :phase
end
diff --git a/spec/ruby/core/numeric/polar_spec.rb b/spec/ruby/core/numeric/polar_spec.rb
index 5492483215..4d3b8c04d1 100644
--- a/spec/ruby/core/numeric/polar_spec.rb
+++ b/spec/ruby/core/numeric/polar_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../shared/complex/numeric/polar', __FILE__)
describe "Numeric#polar" do
- it_behaves_like(:numeric_polar, :polar)
+ it_behaves_like :numeric_polar, :polar
end
diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb
index 3e34410155..6f6b4922b4 100644
--- a/spec/ruby/core/numeric/real_spec.rb
+++ b/spec/ruby/core/numeric/real_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../../../shared/complex/numeric/real', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "Numeric#real" do
- it_behaves_like(:numeric_real, :real)
+ it_behaves_like :numeric_real, :real
end
describe "Numeric#real?" do
diff --git a/spec/ruby/core/numeric/rect_spec.rb b/spec/ruby/core/numeric/rect_spec.rb
index 88d5ee3881..f5bee4c082 100644
--- a/spec/ruby/core/numeric/rect_spec.rb
+++ b/spec/ruby/core/numeric/rect_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/rect', __FILE__)
describe "Numeric#rect" do
- it_behaves_like(:numeric_rect, :rect)
+ it_behaves_like :numeric_rect, :rect
end
diff --git a/spec/ruby/core/numeric/rectangular_spec.rb b/spec/ruby/core/numeric/rectangular_spec.rb
index b34100ca74..9037cb6e60 100644
--- a/spec/ruby/core/numeric/rectangular_spec.rb
+++ b/spec/ruby/core/numeric/rectangular_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/rect', __FILE__)
describe "Numeric#rectangular" do
- it_behaves_like(:numeric_rect, :rectangular)
+ it_behaves_like :numeric_rect, :rectangular
end
diff --git a/spec/ruby/core/proc/clone_spec.rb b/spec/ruby/core/proc/clone_spec.rb
index 0f0806645b..6f1c293a65 100644
--- a/spec/ruby/core/proc/clone_spec.rb
+++ b/spec/ruby/core/proc/clone_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/dup', __FILE__)
describe "Proc#clone" do
- it_behaves_like(:proc_dup, :clone)
+ it_behaves_like :proc_dup, :clone
end
diff --git a/spec/ruby/core/proc/dup_spec.rb b/spec/ruby/core/proc/dup_spec.rb
index ea3fe8aac9..e956fe77f8 100644
--- a/spec/ruby/core/proc/dup_spec.rb
+++ b/spec/ruby/core/proc/dup_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/dup', __FILE__)
describe "Proc#dup" do
- it_behaves_like(:proc_dup, :dup)
+ it_behaves_like :proc_dup, :dup
end
diff --git a/spec/ruby/core/proc/eql_spec.rb b/spec/ruby/core/proc/eql_spec.rb
index e0cc80bb48..9614e4dbbb 100644
--- a/spec/ruby/core/proc/eql_spec.rb
+++ b/spec/ruby/core/proc/eql_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal', __FILE__)
describe "Proc#eql?" do
- it_behaves_like(:proc_equal_undefined, :eql?)
+ it_behaves_like :proc_equal_undefined, :eql?
end
diff --git a/spec/ruby/core/proc/equal_value_spec.rb b/spec/ruby/core/proc/equal_value_spec.rb
index e50ea1a53b..b6126a073a 100644
--- a/spec/ruby/core/proc/equal_value_spec.rb
+++ b/spec/ruby/core/proc/equal_value_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal', __FILE__)
describe "Proc#==" do
- it_behaves_like(:proc_equal_undefined, :==)
+ it_behaves_like :proc_equal_undefined, :==
end
diff --git a/spec/ruby/core/process/last_status_spec.rb b/spec/ruby/core/process/last_status_spec.rb
new file mode 100644
index 0000000000..d49674d8ec
--- /dev/null
+++ b/spec/ruby/core/process/last_status_spec.rb
@@ -0,0 +1,20 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+ruby_version_is '2.5' do
+ describe 'Process#last_status' do
+ it 'returns the status of the last executed child process in the current thread' do
+ pid = Process.wait Process.spawn("exit 0")
+ Process.last_status.pid.should == pid
+ end
+
+ it 'returns nil if no child process has been ever executed in the current thread' do
+ Thread.new do
+ Process.last_status.should == nil
+ end.join
+ end
+
+ it 'raises an ArgumentError if any arguments are provided' do
+ -> { Process.last_status(1) }.should raise_error(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/core/process/setrlimit_spec.rb b/spec/ruby/core/process/setrlimit_spec.rb
index 5d137ca6c1..b721cc5098 100644
--- a/spec/ruby/core/process/setrlimit_spec.rb
+++ b/spec/ruby/core/process/setrlimit_spec.rb
@@ -100,7 +100,7 @@ platform_is_not :windows do
Process.setrlimit(:RTPRIO, *Process.getrlimit(Process::RLIMIT_RTPRIO)).should be_nil
end
- if defined?(Process::RLIMIT_RTTIME)
+ guard -> { defined?(Process::RLIMIT_RTTIME) } do
it "coerces :RTTIME into RLIMIT_RTTIME" do
Process.setrlimit(:RTTIME, *Process.getrlimit(Process::RLIMIT_RTTIME)).should be_nil
end
@@ -182,7 +182,7 @@ platform_is_not :windows do
Process.setrlimit("RTPRIO", *Process.getrlimit(Process::RLIMIT_RTPRIO)).should be_nil
end
- if defined?(Process::RLIMIT_RTTIME)
+ guard -> { defined?(Process::RLIMIT_RTTIME) } do
it "coerces 'RTTIME' into RLIMIT_RTTIME" do
Process.setrlimit("RTTIME", *Process.getrlimit(Process::RLIMIT_RTTIME)).should be_nil
end
diff --git a/spec/ruby/core/range/begin_spec.rb b/spec/ruby/core/range/begin_spec.rb
index 090ae0a24b..64a5cbe157 100644
--- a/spec/ruby/core/range/begin_spec.rb
+++ b/spec/ruby/core/range/begin_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/begin', __FILE__)
describe "Range#begin" do
- it_behaves_like(:range_begin, :begin)
+ it_behaves_like :range_begin, :begin
end
diff --git a/spec/ruby/core/range/end_spec.rb b/spec/ruby/core/range/end_spec.rb
index 128f44c309..f5ad8560bb 100644
--- a/spec/ruby/core/range/end_spec.rb
+++ b/spec/ruby/core/range/end_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/end', __FILE__)
describe "Range#end" do
- it_behaves_like(:range_end, :end)
+ it_behaves_like :range_end, :end
end
diff --git a/spec/ruby/core/range/eql_spec.rb b/spec/ruby/core/range/eql_spec.rb
index 2d495ee175..80f5bc4160 100644
--- a/spec/ruby/core/range/eql_spec.rb
+++ b/spec/ruby/core/range/eql_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Range#eql?" do
- it_behaves_like(:range_eql, :eql?)
+ it_behaves_like :range_eql, :eql?
it "returns false if the endpoints are not eql?" do
(0..1).send(@method, 0..1.0).should == false
diff --git a/spec/ruby/core/range/equal_value_spec.rb b/spec/ruby/core/range/equal_value_spec.rb
index 488fe73c55..c0e5258990 100644
--- a/spec/ruby/core/range/equal_value_spec.rb
+++ b/spec/ruby/core/range/equal_value_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Range#==" do
- it_behaves_like(:range_eql, :==)
+ it_behaves_like :range_eql, :==
it "returns true if the endpoints are ==" do
(0..1).send(@method, 0..1.0).should == true
diff --git a/spec/ruby/core/range/first_spec.rb b/spec/ruby/core/range/first_spec.rb
index 7cd3781d34..59ef02ed74 100644
--- a/spec/ruby/core/range/first_spec.rb
+++ b/spec/ruby/core/range/first_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/begin', __FILE__)
describe "Range#first" do
- it_behaves_like(:range_begin, :first)
+ it_behaves_like :range_begin, :first
it "returns the specified number of elements from the beginning" do
(0..2).first(2).should == [0, 1]
diff --git a/spec/ruby/core/range/last_spec.rb b/spec/ruby/core/range/last_spec.rb
index 581e04f785..c3b3c73e98 100644
--- a/spec/ruby/core/range/last_spec.rb
+++ b/spec/ruby/core/range/last_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/end', __FILE__)
describe "Range#last" do
- it_behaves_like(:range_end, :last)
+ it_behaves_like :range_end, :last
it "returns the specified number of elements from the end" do
(1..5).last(3).should == [3, 4, 5]
diff --git a/spec/ruby/core/rational/abs_spec.rb b/spec/ruby/core/rational/abs_spec.rb
index b04cbd2020..f2fd5b5378 100644
--- a/spec/ruby/core/rational/abs_spec.rb
+++ b/spec/ruby/core/rational/abs_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/abs', __FILE__)
describe "Rational#abs" do
- it_behaves_like(:rational_abs, :abs)
+ it_behaves_like :rational_abs, :abs
end
diff --git a/spec/ruby/core/rational/ceil_spec.rb b/spec/ruby/core/rational/ceil_spec.rb
index e7aca07d33..cd125cc2e2 100644
--- a/spec/ruby/core/rational/ceil_spec.rb
+++ b/spec/ruby/core/rational/ceil_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/ceil', __FILE__)
describe "Rational#ceil" do
- it_behaves_like(:rational_ceil, :ceil)
+ it_behaves_like :rational_ceil, :ceil
end
diff --git a/spec/ruby/core/rational/coerce_spec.rb b/spec/ruby/core/rational/coerce_spec.rb
index 2cfe1db415..6710e5d401 100644
--- a/spec/ruby/core/rational/coerce_spec.rb
+++ b/spec/ruby/core/rational/coerce_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/coerce', __FILE__)
describe "Rational#coerce" do
- it_behaves_like(:rational_coerce, :coerce)
+ it_behaves_like :rational_coerce, :coerce
end
diff --git a/spec/ruby/core/rational/comparison_spec.rb b/spec/ruby/core/rational/comparison_spec.rb
index 3c11abe4a4..1529f12d67 100644
--- a/spec/ruby/core/rational/comparison_spec.rb
+++ b/spec/ruby/core/rational/comparison_spec.rb
@@ -1,22 +1,22 @@
require File.expand_path('../../../shared/rational/comparison', __FILE__)
describe "Rational#<=> when passed a Rational object" do
- it_behaves_like(:rational_cmp_rat, :<=>)
+ it_behaves_like :rational_cmp_rat, :<=>
end
describe "Rational#<=> when passed a Integer object" do
- it_behaves_like(:rational_cmp_int, :<=>)
+ it_behaves_like :rational_cmp_int, :<=>
end
describe "Rational#<=> when passed a Float object" do
- it_behaves_like(:rational_cmp_float, :<=>)
+ it_behaves_like :rational_cmp_float, :<=>
end
describe "Rational#<=> when passed an Object that responds to #coerce" do
- it_behaves_like(:rational_cmp_coerce, :<=>)
- it_behaves_like(:rational_cmp_coerce_exception, :<=>)
+ it_behaves_like :rational_cmp_coerce, :<=>
+ it_behaves_like :rational_cmp_coerce_exception, :<=>
end
describe "Rational#<=> when passed a non-Numeric Object that doesn't respond to #coerce" do
- it_behaves_like(:rational_cmp_other, :<=>)
+ it_behaves_like :rational_cmp_other, :<=>
end
diff --git a/spec/ruby/core/rational/denominator_spec.rb b/spec/ruby/core/rational/denominator_spec.rb
index ac2795ded1..cc249ec4ce 100644
--- a/spec/ruby/core/rational/denominator_spec.rb
+++ b/spec/ruby/core/rational/denominator_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/denominator', __FILE__)
describe "Rational#denominator" do
- it_behaves_like(:rational_denominator, :denominator)
+ it_behaves_like :rational_denominator, :denominator
end
diff --git a/spec/ruby/core/rational/div_spec.rb b/spec/ruby/core/rational/div_spec.rb
index 1fd304b646..58c4a8711b 100644
--- a/spec/ruby/core/rational/div_spec.rb
+++ b/spec/ruby/core/rational/div_spec.rb
@@ -1,17 +1,17 @@
require File.expand_path('../../../shared/rational/div', __FILE__)
describe "Rational#div" do
- it_behaves_like(:rational_div, :div)
+ it_behaves_like :rational_div, :div
end
describe "Rational#div passed a Rational" do
- it_behaves_like(:rational_div_rat, :div)
+ it_behaves_like :rational_div_rat, :div
end
describe "Rational#div passed an Integer" do
- it_behaves_like(:rational_div_int, :div)
+ it_behaves_like :rational_div_int, :div
end
describe "Rational#div passed a Float" do
- it_behaves_like(:rational_div_float, :div)
+ it_behaves_like :rational_div_float, :div
end
diff --git a/spec/ruby/core/rational/divide_spec.rb b/spec/ruby/core/rational/divide_spec.rb
index 8e38513440..12c923a367 100644
--- a/spec/ruby/core/rational/divide_spec.rb
+++ b/spec/ruby/core/rational/divide_spec.rb
@@ -2,18 +2,18 @@ require File.expand_path('../../../shared/rational/divide', __FILE__)
require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__)
describe "Rational#/" do
- it_behaves_like(:rational_divide, :/)
+ it_behaves_like :rational_divide, :/
it_behaves_like :rational_arithmetic_exception_in_coerce, :/
end
describe "Rational#/ when passed an Integer" do
- it_behaves_like(:rational_divide_int, :/)
+ it_behaves_like :rational_divide_int, :/
end
describe "Rational#/ when passed a Rational" do
- it_behaves_like(:rational_divide_rat, :/)
+ it_behaves_like :rational_divide_rat, :/
end
describe "Rational#/ when passed a Float" do
- it_behaves_like(:rational_divide_float, :/)
+ it_behaves_like :rational_divide_float, :/
end
diff --git a/spec/ruby/core/rational/divmod_spec.rb b/spec/ruby/core/rational/divmod_spec.rb
index ee03c9498a..300fe3bd10 100644
--- a/spec/ruby/core/rational/divmod_spec.rb
+++ b/spec/ruby/core/rational/divmod_spec.rb
@@ -1,13 +1,13 @@
require File.expand_path('../../../shared/rational/divmod', __FILE__)
describe "Rational#divmod when passed a Rational" do
- it_behaves_like(:rational_divmod_rat, :divmod)
+ it_behaves_like :rational_divmod_rat, :divmod
end
describe "Rational#divmod when passed an Integer" do
- it_behaves_like(:rational_divmod_int, :divmod)
+ it_behaves_like :rational_divmod_int, :divmod
end
describe "Rational#divmod when passed a Float" do
- it_behaves_like(:rational_divmod_float, :divmod)
+ it_behaves_like :rational_divmod_float, :divmod
end
diff --git a/spec/ruby/core/rational/equal_value_spec.rb b/spec/ruby/core/rational/equal_value_spec.rb
index 708eccf6d1..90ec3d83a9 100644
--- a/spec/ruby/core/rational/equal_value_spec.rb
+++ b/spec/ruby/core/rational/equal_value_spec.rb
@@ -1,17 +1,17 @@
require File.expand_path('../../../shared/rational/equal_value', __FILE__)
describe "Rational#==" do
- it_behaves_like(:rational_equal_value, :==)
+ it_behaves_like :rational_equal_value, :==
end
describe "Rational#== when passed a Rational" do
- it_behaves_like(:rational_equal_value_rat, :==)
+ it_behaves_like :rational_equal_value_rat, :==
end
describe "Rational#== when passed a Float" do
- it_behaves_like(:rational_equal_value_float, :==)
+ it_behaves_like :rational_equal_value_float, :==
end
describe "Rational#== when passed an Integer" do
- it_behaves_like(:rational_equal_value_int, :==)
+ it_behaves_like :rational_equal_value_int, :==
end
diff --git a/spec/ruby/core/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb
index e4810d1b41..a992d36a7e 100644
--- a/spec/ruby/core/rational/exponent_spec.rb
+++ b/spec/ruby/core/rational/exponent_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/exponent', __FILE__)
describe "Rational#**" do
- it_behaves_like(:rational_exponent, :**)
+ it_behaves_like :rational_exponent, :**
end
diff --git a/spec/ruby/core/rational/fdiv_spec.rb b/spec/ruby/core/rational/fdiv_spec.rb
index 15b4ed0619..23caf2cb9f 100644
--- a/spec/ruby/core/rational/fdiv_spec.rb
+++ b/spec/ruby/core/rational/fdiv_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/fdiv', __FILE__)
describe "Rational#fdiv" do
- it_behaves_like(:rational_fdiv, :fdiv)
+ it_behaves_like :rational_fdiv, :fdiv
end
diff --git a/spec/ruby/core/rational/floor_spec.rb b/spec/ruby/core/rational/floor_spec.rb
index 485abcf58f..f46a2221c4 100644
--- a/spec/ruby/core/rational/floor_spec.rb
+++ b/spec/ruby/core/rational/floor_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/floor', __FILE__)
describe "Rational#floor" do
- it_behaves_like(:rational_floor, :floor)
+ it_behaves_like :rational_floor, :floor
end
diff --git a/spec/ruby/core/rational/hash_spec.rb b/spec/ruby/core/rational/hash_spec.rb
index a17572d57e..e0e5d892ab 100644
--- a/spec/ruby/core/rational/hash_spec.rb
+++ b/spec/ruby/core/rational/hash_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/hash', __FILE__)
describe "Rational#hash" do
- it_behaves_like(:rational_hash, :hash)
+ it_behaves_like :rational_hash, :hash
end
diff --git a/spec/ruby/core/rational/inspect_spec.rb b/spec/ruby/core/rational/inspect_spec.rb
index 452cf9c5ae..0c11633dc2 100644
--- a/spec/ruby/core/rational/inspect_spec.rb
+++ b/spec/ruby/core/rational/inspect_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/inspect', __FILE__)
describe "Rational#inspect" do
- it_behaves_like(:rational_inspect, :inspect)
+ it_behaves_like :rational_inspect, :inspect
end
diff --git a/spec/ruby/core/rational/magnitude_spec.rb b/spec/ruby/core/rational/magnitude_spec.rb
index 288b9a3fa3..4df1d920ea 100644
--- a/spec/ruby/core/rational/magnitude_spec.rb
+++ b/spec/ruby/core/rational/magnitude_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/abs', __FILE__)
describe "Rational#abs" do
- it_behaves_like(:rational_abs, :magnitude)
+ it_behaves_like :rational_abs, :magnitude
end
diff --git a/spec/ruby/core/rational/minus_spec.rb b/spec/ruby/core/rational/minus_spec.rb
index 9d14b25c47..f4caad58ed 100644
--- a/spec/ruby/core/rational/minus_spec.rb
+++ b/spec/ruby/core/rational/minus_spec.rb
@@ -2,6 +2,6 @@ require File.expand_path('../../../shared/rational/minus', __FILE__)
require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__)
describe "Rational#-" do
- it_behaves_like(:rational_minus, :-)
+ it_behaves_like :rational_minus, :-
it_behaves_like :rational_arithmetic_exception_in_coerce, :-
end
diff --git a/spec/ruby/core/rational/modulo_spec.rb b/spec/ruby/core/rational/modulo_spec.rb
index 81e7c13797..16820f7604 100644
--- a/spec/ruby/core/rational/modulo_spec.rb
+++ b/spec/ruby/core/rational/modulo_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/modulo', __FILE__)
describe "Rational#%" do
- it_behaves_like(:rational_modulo, :%)
+ it_behaves_like :rational_modulo, :%
end
diff --git a/spec/ruby/core/rational/multiply_spec.rb b/spec/ruby/core/rational/multiply_spec.rb
index 1245908c89..331c0e3d32 100644
--- a/spec/ruby/core/rational/multiply_spec.rb
+++ b/spec/ruby/core/rational/multiply_spec.rb
@@ -2,18 +2,18 @@ require File.expand_path('../../../shared/rational/multiply', __FILE__)
require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__)
describe "Rational#*" do
- it_behaves_like(:rational_multiply, :*)
+ it_behaves_like :rational_multiply, :*
it_behaves_like :rational_arithmetic_exception_in_coerce, :*
end
describe "Rational#* passed a Rational" do
- it_behaves_like(:rational_multiply_rat, :*)
+ it_behaves_like :rational_multiply_rat, :*
end
describe "Rational#* passed a Float" do
- it_behaves_like(:rational_multiply_float, :*)
+ it_behaves_like :rational_multiply_float, :*
end
describe "Rational#* passed an Integer" do
- it_behaves_like(:rational_multiply_int, :*)
+ it_behaves_like :rational_multiply_int, :*
end
diff --git a/spec/ruby/core/rational/numerator_spec.rb b/spec/ruby/core/rational/numerator_spec.rb
index ac6591291d..da1a680b6d 100644
--- a/spec/ruby/core/rational/numerator_spec.rb
+++ b/spec/ruby/core/rational/numerator_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/numerator', __FILE__)
describe "Rational#numerator" do
- it_behaves_like(:rational_numerator, :numerator)
+ it_behaves_like :rational_numerator, :numerator
end
diff --git a/spec/ruby/core/rational/plus_spec.rb b/spec/ruby/core/rational/plus_spec.rb
index 2564e1161b..fbedb4498c 100644
--- a/spec/ruby/core/rational/plus_spec.rb
+++ b/spec/ruby/core/rational/plus_spec.rb
@@ -2,17 +2,17 @@ require File.expand_path('../../../shared/rational/plus', __FILE__)
require File.expand_path('../../../shared/rational/arithmetic_exception_in_coerce', __FILE__)
describe "Rational#+" do
- it_behaves_like(:rational_plus, :+)
+ it_behaves_like :rational_plus, :+
it_behaves_like :rational_arithmetic_exception_in_coerce, :+
end
describe "Rational#+ with a Rational" do
- it_behaves_like(:rational_plus_rat, :+)
+ it_behaves_like :rational_plus_rat, :+
end
describe "Rational#+ with a Float" do
- it_behaves_like(:rational_plus_float, :+)
+ it_behaves_like :rational_plus_float, :+
end
describe "Rational#+ with an Integer" do
- it_behaves_like(:rational_plus_int, :+)
+ it_behaves_like :rational_plus_int, :+
end
diff --git a/spec/ruby/core/rational/quo_spec.rb b/spec/ruby/core/rational/quo_spec.rb
index f4d04d5f6f..f115d38765 100644
--- a/spec/ruby/core/rational/quo_spec.rb
+++ b/spec/ruby/core/rational/quo_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/divide', __FILE__)
describe "Rational#quo" do
- it_behaves_like(:rational_divide, :quo)
+ it_behaves_like :rational_divide, :quo
end
diff --git a/spec/ruby/core/rational/remainder_spec.rb b/spec/ruby/core/rational/remainder_spec.rb
index 1de276548f..2545071e30 100644
--- a/spec/ruby/core/rational/remainder_spec.rb
+++ b/spec/ruby/core/rational/remainder_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/remainder', __FILE__)
describe "Rational#remainder" do
- it_behaves_like(:rational_remainder, :remainder)
+ it_behaves_like :rational_remainder, :remainder
end
diff --git a/spec/ruby/core/rational/round_spec.rb b/spec/ruby/core/rational/round_spec.rb
index 2b432f3234..efdd44d24c 100644
--- a/spec/ruby/core/rational/round_spec.rb
+++ b/spec/ruby/core/rational/round_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/round', __FILE__)
describe "Rational#round" do
- it_behaves_like(:rational_round, :round)
+ it_behaves_like :rational_round, :round
end
diff --git a/spec/ruby/core/rational/to_f_spec.rb b/spec/ruby/core/rational/to_f_spec.rb
index 92ff2444b4..b67884dd03 100644
--- a/spec/ruby/core/rational/to_f_spec.rb
+++ b/spec/ruby/core/rational/to_f_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/to_f', __FILE__)
describe "Rational#to_f" do
- it_behaves_like(:rational_to_f, :to_f)
+ it_behaves_like :rational_to_f, :to_f
end
diff --git a/spec/ruby/core/rational/to_i_spec.rb b/spec/ruby/core/rational/to_i_spec.rb
index fda6b06e96..d14c211799 100644
--- a/spec/ruby/core/rational/to_i_spec.rb
+++ b/spec/ruby/core/rational/to_i_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/to_i', __FILE__)
describe "Rational#to_i" do
- it_behaves_like(:rational_to_i, :to_i)
+ it_behaves_like :rational_to_i, :to_i
end
diff --git a/spec/ruby/core/rational/to_r_spec.rb b/spec/ruby/core/rational/to_r_spec.rb
index 6e44cf1b23..b2aaa1bc8b 100644
--- a/spec/ruby/core/rational/to_r_spec.rb
+++ b/spec/ruby/core/rational/to_r_spec.rb
@@ -1,7 +1,7 @@
require File.expand_path('../../../shared/rational/to_r', __FILE__)
describe "Rational#to_r" do
- it_behaves_like(:rational_to_r, :to_r)
+ it_behaves_like :rational_to_r, :to_r
it "raises TypeError trying to convert BasicObject" do
obj = BasicObject.new
diff --git a/spec/ruby/core/rational/to_s_spec.rb b/spec/ruby/core/rational/to_s_spec.rb
index 7d1702b8fa..4ecb481467 100644
--- a/spec/ruby/core/rational/to_s_spec.rb
+++ b/spec/ruby/core/rational/to_s_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/to_s', __FILE__)
describe "Rational#to_s" do
- it_behaves_like(:rational_to_s, :to_s)
+ it_behaves_like :rational_to_s, :to_s
end
diff --git a/spec/ruby/core/rational/truncate_spec.rb b/spec/ruby/core/rational/truncate_spec.rb
index 000db73357..0339b77570 100644
--- a/spec/ruby/core/rational/truncate_spec.rb
+++ b/spec/ruby/core/rational/truncate_spec.rb
@@ -1,5 +1,5 @@
require File.expand_path('../../../shared/rational/truncate', __FILE__)
describe "Rational#truncate" do
- it_behaves_like(:rational_truncate, :truncate)
+ it_behaves_like :rational_truncate, :truncate
end
diff --git a/spec/ruby/core/regexp/match_spec.rb b/spec/ruby/core/regexp/match_spec.rb
index 872c3ff59e..e2b6b241e8 100644
--- a/spec/ruby/core/regexp/match_spec.rb
+++ b/spec/ruby/core/regexp/match_spec.rb
@@ -12,7 +12,7 @@ describe :regexp_match, shared: true do
end
describe "Regexp#=~" do
- it_behaves_like(:regexp_match, :=~)
+ it_behaves_like :regexp_match, :=~
it "returns the index of the first character of the matching region" do
(/(.)(.)(.)/ =~ "abc").should == 0
@@ -24,7 +24,7 @@ describe "Regexp#=~" do
end
describe "Regexp#match" do
- it_behaves_like(:regexp_match, :match)
+ it_behaves_like :regexp_match, :match
it "returns a MatchData object" do
/(.)(.)(.)/.match("abc").should be_kind_of(MatchData)
diff --git a/spec/ruby/core/signal/signame_spec.rb b/spec/ruby/core/signal/signame_spec.rb
index 1874a67933..503e6af64b 100644
--- a/spec/ruby/core/signal/signame_spec.rb
+++ b/spec/ruby/core/signal/signame_spec.rb
@@ -20,4 +20,11 @@ describe "Signal.signame" do
it "raises a TypeError when the passed argument can't be coerced to Integer" do
lambda { Signal.signame("hello") }.should raise_error(TypeError)
end
+
+ platform_is_not :windows do
+ it "the original should take precendence over alias when looked up by number" do
+ Signal.signame(Signal.list["ABRT"]).should == "ABRT"
+ Signal.signame(Signal.list["CHLD"]).should == "CHLD"
+ end
+ end
end
diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb
index 787de1735c..0b6ea55c81 100644
--- a/spec/ruby/core/signal/trap_spec.rb
+++ b/spec/ruby/core/signal/trap_spec.rb
@@ -113,6 +113,12 @@ platform_is_not :windows do
Signal.trap(:HUP, "IGNORE").should == "IGNORE"
end
end
+
+ describe "Signal.trap" do
+ it "returns SYSTEM_DEFAULT if passed DEFAULT and no handler was ever set" do
+ Signal.trap("PROF", "DEFAULT").should == "SYSTEM_DEFAULT"
+ end
+ end
end
describe "Signal.trap" do
diff --git a/spec/ruby/core/string/case_compare_spec.rb b/spec/ruby/core/string/case_compare_spec.rb
index 930f5bea90..a4f2d7960e 100644
--- a/spec/ruby/core/string/case_compare_spec.rb
+++ b/spec/ruby/core/string/case_compare_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../shared/eql', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "String#===" do
- it_behaves_like(:string_eql_value, :===)
- it_behaves_like(:string_equal_value, :===)
+ it_behaves_like :string_eql_value, :===
+ it_behaves_like :string_equal_value, :===
end
diff --git a/spec/ruby/core/string/chars_spec.rb b/spec/ruby/core/string/chars_spec.rb
index 75cef89be1..7f764a3e43 100644
--- a/spec/ruby/core/string/chars_spec.rb
+++ b/spec/ruby/core/string/chars_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../shared/chars', __FILE__)
require File.expand_path('../shared/each_char_without_block', __FILE__)
describe "String#chars" do
- it_behaves_like(:string_chars, :chars)
+ it_behaves_like :string_chars, :chars
it "returns an array when no block given" do
ary = "hello".send(@method)
diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb
index 6304513583..bae83ba86d 100644
--- a/spec/ruby/core/string/codepoints_spec.rb
+++ b/spec/ruby/core/string/codepoints_spec.rb
@@ -5,7 +5,7 @@ require File.expand_path('../shared/each_codepoint_without_block', __FILE__)
with_feature :encoding do
describe "String#codepoints" do
- it_behaves_like(:string_codepoints, :codepoints)
+ it_behaves_like :string_codepoints, :codepoints
it "returns an Array when no block is given" do
"abc".send(@method).should == [?a.ord, ?b.ord, ?c.ord]
diff --git a/spec/ruby/core/string/each_char_spec.rb b/spec/ruby/core/string/each_char_spec.rb
index 3233c7609d..4894c745c7 100644
--- a/spec/ruby/core/string/each_char_spec.rb
+++ b/spec/ruby/core/string/each_char_spec.rb
@@ -2,6 +2,6 @@ require File.expand_path('../shared/chars', __FILE__)
require File.expand_path('../shared/each_char_without_block', __FILE__)
describe "String#each_char" do
- it_behaves_like(:string_chars, :each_char)
- it_behaves_like(:string_each_char_without_block, :each_char)
+ it_behaves_like :string_chars, :each_char
+ it_behaves_like :string_each_char_without_block, :each_char
end
diff --git a/spec/ruby/core/string/each_codepoint_spec.rb b/spec/ruby/core/string/each_codepoint_spec.rb
index 4e910f44b5..3ad4b719fc 100644
--- a/spec/ruby/core/string/each_codepoint_spec.rb
+++ b/spec/ruby/core/string/each_codepoint_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path('../shared/each_codepoint_without_block', __FILE__)
with_feature :encoding do
describe "String#each_codepoint" do
- it_behaves_like(:string_codepoints, :each_codepoint)
- it_behaves_like(:string_each_codepoint_without_block, :each_codepoint)
+ it_behaves_like :string_codepoints, :each_codepoint
+ it_behaves_like :string_each_codepoint_without_block, :each_codepoint
end
end
diff --git a/spec/ruby/core/string/each_line_spec.rb b/spec/ruby/core/string/each_line_spec.rb
index 865ae264d6..ede272a0a0 100644
--- a/spec/ruby/core/string/each_line_spec.rb
+++ b/spec/ruby/core/string/each_line_spec.rb
@@ -4,6 +4,6 @@ require File.expand_path('../shared/each_line', __FILE__)
require File.expand_path('../shared/each_line_without_block', __FILE__)
describe "String#each_line" do
- it_behaves_like(:string_each_line, :each_line)
- it_behaves_like(:string_each_line_without_block, :each_line)
+ it_behaves_like :string_each_line, :each_line
+ it_behaves_like :string_each_line_without_block, :each_line
end
diff --git a/spec/ruby/core/string/eql_spec.rb b/spec/ruby/core/string/eql_spec.rb
index df094e122f..ccc0bcbaa8 100644
--- a/spec/ruby/core/string/eql_spec.rb
+++ b/spec/ruby/core/string/eql_spec.rb
@@ -2,7 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql', __FILE__)
describe "String#eql?" do
- it_behaves_like(:string_eql_value, :eql?)
+ it_behaves_like :string_eql_value, :eql?
describe "when given a non-String" do
it "returns false" do
diff --git a/spec/ruby/core/string/equal_value_spec.rb b/spec/ruby/core/string/equal_value_spec.rb
index bf252d6d30..cec6843fe6 100644
--- a/spec/ruby/core/string/equal_value_spec.rb
+++ b/spec/ruby/core/string/equal_value_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../shared/eql', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "String#==" do
- it_behaves_like(:string_eql_value, :==)
- it_behaves_like(:string_equal_value, :==)
+ it_behaves_like :string_eql_value, :==
+ it_behaves_like :string_equal_value, :==
end
diff --git a/spec/ruby/core/string/intern_spec.rb b/spec/ruby/core/string/intern_spec.rb
index 71f3633920..c0196f7e2c 100644
--- a/spec/ruby/core/string/intern_spec.rb
+++ b/spec/ruby/core/string/intern_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/to_sym.rb', __FILE__)
describe "String#intern" do
- it_behaves_like(:string_to_sym, :intern)
+ it_behaves_like :string_to_sym, :intern
end
diff --git a/spec/ruby/core/string/length_spec.rb b/spec/ruby/core/string/length_spec.rb
index 5f51f6bc01..215b5ec854 100644
--- a/spec/ruby/core/string/length_spec.rb
+++ b/spec/ruby/core/string/length_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "String#length" do
- it_behaves_like(:string_length, :length)
+ it_behaves_like :string_length, :length
end
diff --git a/spec/ruby/core/string/lines_spec.rb b/spec/ruby/core/string/lines_spec.rb
index e5f24816af..111cc14508 100644
--- a/spec/ruby/core/string/lines_spec.rb
+++ b/spec/ruby/core/string/lines_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path('../shared/each_line', __FILE__)
require File.expand_path('../shared/each_line_without_block', __FILE__)
describe "String#lines" do
- it_behaves_like(:string_each_line, :lines)
+ it_behaves_like :string_each_line, :lines
it "returns an array when no block given" do
ary = "hello world".send(@method, ' ')
diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb
index 4f26ac5033..7cb3561b17 100644
--- a/spec/ruby/core/string/modulo_spec.rb
+++ b/spec/ruby/core/string/modulo_spec.rb
@@ -1,7 +1,12 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes.rb', __FILE__)
+require File.expand_path('../../../shared/hash/key_error', __FILE__)
describe "String#%" do
+ context "when key is missing from passed-in hash" do
+ it_behaves_like :key_error, -> (obj, key) { "%{#{key}}" % obj }, { a: 5 }
+ end
+
it "formats multiple expressions" do
("%b %x %d %s" % [10, 10, 10, 10]).should == "1010 a 10 10"
end
@@ -764,10 +769,6 @@ describe "String#%" do
("%{foo}bar" % {foo: 'oof'}).should == "oofbar"
end
- it "raises KeyError if key is missing from passed-in hash" do
- lambda {"%{foo}" % {}}.should raise_error(KeyError)
- end
-
it "should raise ArgumentError if no hash given" do
lambda {"%{foo}" % []}.should raise_error(ArgumentError)
end
diff --git a/spec/ruby/core/string/next_spec.rb b/spec/ruby/core/string/next_spec.rb
index 6b4a98d993..185f857cf0 100644
--- a/spec/ruby/core/string/next_spec.rb
+++ b/spec/ruby/core/string/next_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/succ.rb', __FILE__)
describe "String#next" do
- it_behaves_like(:string_succ, :next)
+ it_behaves_like :string_succ, :next
end
describe "String#next!" do
- it_behaves_like(:string_succ_bang, :"next!")
+ it_behaves_like :string_succ_bang, :"next!"
end
diff --git a/spec/ruby/core/string/size_spec.rb b/spec/ruby/core/string/size_spec.rb
index b3172453ea..7e1afd9c54 100644
--- a/spec/ruby/core/string/size_spec.rb
+++ b/spec/ruby/core/string/size_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/length', __FILE__)
describe "String#size" do
- it_behaves_like(:string_length, :size)
+ it_behaves_like :string_length, :size
end
diff --git a/spec/ruby/core/string/start_with_spec.rb b/spec/ruby/core/string/start_with_spec.rb
index 1b27fdaed7..cba40d70f1 100644
--- a/spec/ruby/core/string/start_with_spec.rb
+++ b/spec/ruby/core/string/start_with_spec.rb
@@ -42,4 +42,35 @@ describe "String#start_with?" do
it "works for multibyte strings" do
"céréale".start_with?("cér").should be_true
end
+
+ ruby_version_is "2.5" do
+ it "supports regexps" do
+ regexp = /[h1]/
+ "hello".start_with?(regexp).should be_true
+ "1337".start_with?(regexp).should be_true
+ "foxes are 1337".start_with?(regexp).should be_false
+ "chunky\n12bacon".start_with?(/12/).should be_false
+ end
+
+ it "supports regexps with ^ and $ modifiers" do
+ regexp1 = /^\d{2}/
+ regexp2 = /\d{2}$/
+ "12test".start_with?(regexp1).should be_true
+ "test12".start_with?(regexp1).should be_false
+ "12test".start_with?(regexp2).should be_false
+ "test12".start_with?(regexp2).should be_false
+ end
+
+ it "sets Regexp.last_match if it returns true" do
+ regexp = /test-(\d+)/
+ "test-1337".start_with?(regexp).should be_true
+ Regexp.last_match.should_not be_nil
+ Regexp.last_match[1].should == "1337"
+ $1.should == "1337"
+
+ "test-asdf".start_with?(regexp).should be_false
+ Regexp.last_match.should be_nil
+ $1.should be_nil
+ end
+ end
end
diff --git a/spec/ruby/core/string/succ_spec.rb b/spec/ruby/core/string/succ_spec.rb
index 311453702d..52b5a6c1ee 100644
--- a/spec/ruby/core/string/succ_spec.rb
+++ b/spec/ruby/core/string/succ_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/succ.rb', __FILE__)
describe "String#succ" do
- it_behaves_like(:string_succ, :succ)
+ it_behaves_like :string_succ, :succ
end
describe "String#succ!" do
- it_behaves_like(:string_succ_bang, :"succ!")
+ it_behaves_like :string_succ_bang, :"succ!"
end
diff --git a/spec/ruby/core/string/to_s_spec.rb b/spec/ruby/core/string/to_s_spec.rb
index b483b1b138..8551b080a6 100644
--- a/spec/ruby/core/string/to_s_spec.rb
+++ b/spec/ruby/core/string/to_s_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/to_s.rb', __FILE__)
describe "String#to_s" do
- it_behaves_like(:string_to_s, :to_s)
+ it_behaves_like :string_to_s, :to_s
end
diff --git a/spec/ruby/core/string/to_str_spec.rb b/spec/ruby/core/string/to_str_spec.rb
index fb1260a687..a326b52bca 100644
--- a/spec/ruby/core/string/to_str_spec.rb
+++ b/spec/ruby/core/string/to_str_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/to_s.rb', __FILE__)
describe "String#to_str" do
- it_behaves_like(:string_to_s, :to_str)
+ it_behaves_like :string_to_s, :to_str
end
diff --git a/spec/ruby/core/string/to_sym_spec.rb b/spec/ruby/core/string/to_sym_spec.rb
index 7659f266cd..cb41afc636 100644
--- a/spec/ruby/core/string/to_sym_spec.rb
+++ b/spec/ruby/core/string/to_sym_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes.rb', __FILE__)
require File.expand_path('../shared/to_sym.rb', __FILE__)
describe "String#to_sym" do
- it_behaves_like(:string_to_sym, :to_sym)
+ it_behaves_like :string_to_sym, :to_sym
end
diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb
index 53e73b7e67..f18e6b1234 100644
--- a/spec/ruby/core/string/uminus_spec.rb
+++ b/spec/ruby/core/string/uminus_spec.rb
@@ -17,5 +17,30 @@ ruby_version_is "2.3" do
output.frozen?.should == true
output.should == 'foo'
end
+
+ ruby_version_is "2.5" do
+ it "returns the same object for equal unfrozen strings" do
+ origin = "this is a string"
+ dynamic = %w(this is a string).join(' ')
+
+ origin.should_not equal(dynamic)
+ (-origin).should equal(-dynamic)
+ end
+
+ it "returns the same object when it's called on the same String literal" do
+ (-"unfrozen string").should equal(-"unfrozen string")
+ (-"unfrozen string").should_not equal(-"another unfrozen string")
+ end
+
+ it "is an identity function if the string is frozen" do
+ dynamic = %w(this string is frozen).join(' ').freeze
+
+ (-dynamic).should equal(dynamic)
+
+ dynamic.should_not equal("this string is frozen".freeze)
+ (-dynamic).should_not equal("this string is frozen".freeze)
+ (-dynamic).should_not equal(-"this string is frozen".freeze)
+ end
+ end
end
end
diff --git a/spec/ruby/core/struct/eql_spec.rb b/spec/ruby/core/struct/eql_spec.rb
index dfa97811c6..0caba5ef0e 100644
--- a/spec/ruby/core/struct/eql_spec.rb
+++ b/spec/ruby/core/struct/eql_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Struct#eql?" do
- it_behaves_like(:struct_equal_value, :eql?)
+ it_behaves_like :struct_equal_value, :eql?
it "returns false if any corresponding elements are not #eql?" do
car = StructClasses::Car.new("Honda", "Accord", 1998)
diff --git a/spec/ruby/core/struct/equal_value_spec.rb b/spec/ruby/core/struct/equal_value_spec.rb
index a343213417..6ba476dfd0 100644
--- a/spec/ruby/core/struct/equal_value_spec.rb
+++ b/spec/ruby/core/struct/equal_value_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/equal_value', __FILE__)
describe "Struct#==" do
- it_behaves_like(:struct_equal_value, :==)
+ it_behaves_like :struct_equal_value, :==
end
diff --git a/spec/ruby/core/struct/inspect_spec.rb b/spec/ruby/core/struct/inspect_spec.rb
index 94fb71a5f1..45b69c6133 100644
--- a/spec/ruby/core/struct/inspect_spec.rb
+++ b/spec/ruby/core/struct/inspect_spec.rb
@@ -11,5 +11,5 @@ describe "Struct#inspect" do
Whiskey.new('Jack', 100).inspect.should == '#<struct Whiskey name="Jack", ounces=100>'
end
- it_behaves_like(:struct_inspect, :inspect)
+ it_behaves_like :struct_inspect, :inspect
end
diff --git a/spec/ruby/core/struct/to_s_spec.rb b/spec/ruby/core/struct/to_s_spec.rb
index b9fd413093..671c046b84 100644
--- a/spec/ruby/core/struct/to_s_spec.rb
+++ b/spec/ruby/core/struct/to_s_spec.rb
@@ -8,5 +8,5 @@ describe "Struct#to_s" do
car.inspect.should == car.to_s
end
- it_behaves_like(:struct_inspect, :to_s)
+ it_behaves_like :struct_inspect, :to_s
end
diff --git a/spec/ruby/core/symbol/element_reference_spec.rb b/spec/ruby/core/symbol/element_reference_spec.rb
index 4116274ee0..77d737e4f9 100644
--- a/spec/ruby/core/symbol/element_reference_spec.rb
+++ b/spec/ruby/core/symbol/element_reference_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/slice.rb', __FILE__)
describe "Symbol#[]" do
- it_behaves_like(:symbol_slice, :[])
+ it_behaves_like :symbol_slice, :[]
end
diff --git a/spec/ruby/core/symbol/id2name_spec.rb b/spec/ruby/core/symbol/id2name_spec.rb
index 932dd7171d..a95ef0dcab 100644
--- a/spec/ruby/core/symbol/id2name_spec.rb
+++ b/spec/ruby/core/symbol/id2name_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/id2name', __FILE__)
describe "Symbol#id2name" do
- it_behaves_like(:symbol_id2name, :id2name)
+ it_behaves_like :symbol_id2name, :id2name
end
diff --git a/spec/ruby/core/symbol/slice_spec.rb b/spec/ruby/core/symbol/slice_spec.rb
index 3c535ac4b0..a93a2a753e 100644
--- a/spec/ruby/core/symbol/slice_spec.rb
+++ b/spec/ruby/core/symbol/slice_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/slice.rb', __FILE__)
describe "Symbol#slice" do
- it_behaves_like(:symbol_slice, :slice)
+ it_behaves_like :symbol_slice, :slice
end
diff --git a/spec/ruby/core/symbol/to_s_spec.rb b/spec/ruby/core/symbol/to_s_spec.rb
index 40c13675b3..837eb129ce 100644
--- a/spec/ruby/core/symbol/to_s_spec.rb
+++ b/spec/ruby/core/symbol/to_s_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/id2name', __FILE__)
describe "Symbol#to_s" do
- it_behaves_like(:symbol_id2name, :to_s)
+ it_behaves_like :symbol_id2name, :to_s
end
diff --git a/spec/ruby/core/thread/backtrace_spec.rb b/spec/ruby/core/thread/backtrace_spec.rb
index a20fdee956..532d7a8f4e 100644
--- a/spec/ruby/core/thread/backtrace_spec.rb
+++ b/spec/ruby/core/thread/backtrace_spec.rb
@@ -24,4 +24,12 @@ describe "Thread#backtrace" do
t.join
t.backtrace.should == nil
end
+
+ it "returns an array (which may be empty) immediately after the thread is created" do
+ t = Thread.new { sleep }
+ backtrace = t.backtrace
+ t.kill
+ t.join
+ backtrace.should be_kind_of(Array)
+ end
end
diff --git a/spec/ruby/core/thread/current_spec.rb b/spec/ruby/core/thread/current_spec.rb
index cc969b71c4..6c4dcfae43 100644
--- a/spec/ruby/core/thread/current_spec.rb
+++ b/spec/ruby/core/thread/current_spec.rb
@@ -12,4 +12,20 @@ describe "Thread.current" do
t.value.should equal(t)
Thread.current.should_not equal(t.value)
end
+
+ it "returns the correct thread in a Fiber" do
+ # This catches a bug where Fibers are running on a thread-pool
+ # and Fibers from a different Ruby Thread reuse the same native thread.
+ # Caching the Ruby Thread based on the native thread is not correct in that case.
+ 2.times do
+ t = Thread.new {
+ cur = Thread.current
+ Fiber.new {
+ Thread.current
+ }.resume.should equal cur
+ cur
+ }
+ t.value.should equal t
+ end
+ end
end
diff --git a/spec/ruby/core/thread/fetch_spec.rb b/spec/ruby/core/thread/fetch_spec.rb
new file mode 100644
index 0000000000..33ac3e0433
--- /dev/null
+++ b/spec/ruby/core/thread/fetch_spec.rb
@@ -0,0 +1,38 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+ruby_version_is '2.5' do
+ describe 'Thread#fetch' do
+ describe 'with 2 arguments' do
+ it 'returns the value of the fiber-local variable if value has been assigned' do
+ th = Thread.new { Thread.current[:cat] = 'meow' }
+ th.join
+ th.fetch(:cat, true).should == 'meow'
+ end
+
+ it "returns the default value if fiber-local variable hasn't been assigned" do
+ th = Thread.new {}
+ th.join
+ th.fetch(:cat, true).should == true
+ end
+ end
+
+ describe 'with 1 argument' do
+ it 'raises a KeyError when the Thread does not have a fiber-local variable of the same name' do
+ th = Thread.new {}
+ th.join
+ -> { th.fetch(:cat) }.should raise_error(KeyError)
+ end
+
+ it 'returns the value of the fiber-local variable if value has been assigned' do
+ th = Thread.new { Thread.current[:cat] = 'meow' }
+ th.join
+ th.fetch(:cat).should == 'meow'
+ end
+ end
+
+ it 'raises an ArgumentError when not passed one or two arguments' do
+ -> { Thread.current.fetch() }.should raise_error(ArgumentError)
+ -> { Thread.current.fetch(1, 2, 3) }.should raise_error(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/core/thread/priority_spec.rb b/spec/ruby/core/thread/priority_spec.rb
index b986fb7a0d..40022da80d 100644
--- a/spec/ruby/core/thread/priority_spec.rb
+++ b/spec/ruby/core/thread/priority_spec.rb
@@ -2,13 +2,14 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
describe "Thread#priority" do
- before do
+ before :each do
@current_priority = Thread.current.priority
ThreadSpecs.clear_state
@thread = Thread.new { Thread.pass until ThreadSpecs.state == :exit }
+ Thread.pass until @thread.alive?
end
- after do
+ after :each do
ThreadSpecs.state = :exit
@thread.join
end
@@ -31,12 +32,14 @@ describe "Thread#priority" do
end
describe "Thread#priority=" do
- before do
+ before :each do
ThreadSpecs.clear_state
- @thread = Thread.new {}
+ @thread = Thread.new { Thread.pass until ThreadSpecs.state == :exit }
+ Thread.pass until @thread.alive?
end
- after do
+ after :each do
+ ThreadSpecs.state = :exit
@thread.join
end
@@ -61,8 +64,9 @@ describe "Thread#priority=" do
end
it "sets priority even when the thread has died" do
- @thread.join
- @thread.priority = 3
- @thread.priority.should == 3
+ thread = Thread.new {}
+ thread.join
+ thread.priority = 3
+ thread.priority.should == 3
end
end
diff --git a/spec/ruby/core/time/asctime_spec.rb b/spec/ruby/core/time/asctime_spec.rb
index 3303e06f21..1b2bb16fdf 100644
--- a/spec/ruby/core/time/asctime_spec.rb
+++ b/spec/ruby/core/time/asctime_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/asctime', __FILE__)
describe "Time#asctime" do
- it_behaves_like(:time_asctime, :asctime)
+ it_behaves_like :time_asctime, :asctime
end
diff --git a/spec/ruby/core/time/ctime_spec.rb b/spec/ruby/core/time/ctime_spec.rb
index cf9c1ee850..dce85620e0 100644
--- a/spec/ruby/core/time/ctime_spec.rb
+++ b/spec/ruby/core/time/ctime_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/asctime', __FILE__)
describe "Time#ctime" do
- it_behaves_like(:time_asctime, :ctime)
+ it_behaves_like :time_asctime, :ctime
end
diff --git a/spec/ruby/core/time/day_spec.rb b/spec/ruby/core/time/day_spec.rb
index 8e77446070..817942dbaf 100644
--- a/spec/ruby/core/time/day_spec.rb
+++ b/spec/ruby/core/time/day_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/day', __FILE__)
describe "Time#day" do
- it_behaves_like(:time_day, :day)
+ it_behaves_like :time_day, :day
end
diff --git a/spec/ruby/core/time/dst_spec.rb b/spec/ruby/core/time/dst_spec.rb
index 05a0a213c5..4a05fa93a5 100644
--- a/spec/ruby/core/time/dst_spec.rb
+++ b/spec/ruby/core/time/dst_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/isdst', __FILE__)
describe "Time#dst?" do
- it_behaves_like(:time_isdst, :dst?)
+ it_behaves_like :time_isdst, :dst?
end
diff --git a/spec/ruby/core/time/getgm_spec.rb b/spec/ruby/core/time/getgm_spec.rb
index f091b5c493..be8691feb1 100644
--- a/spec/ruby/core/time/getgm_spec.rb
+++ b/spec/ruby/core/time/getgm_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/getgm', __FILE__)
describe "Time#getgm" do
- it_behaves_like(:time_getgm, :getgm)
+ it_behaves_like :time_getgm, :getgm
end
diff --git a/spec/ruby/core/time/getutc_spec.rb b/spec/ruby/core/time/getutc_spec.rb
index a6e74cfb98..5c70e3e7cc 100644
--- a/spec/ruby/core/time/getutc_spec.rb
+++ b/spec/ruby/core/time/getutc_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/getgm', __FILE__)
describe "Time#getutc" do
- it_behaves_like(:time_getgm, :getutc)
+ it_behaves_like :time_getgm, :getutc
end
diff --git a/spec/ruby/core/time/gm_spec.rb b/spec/ruby/core/time/gm_spec.rb
index a6f2858216..3d3fdb16e7 100644
--- a/spec/ruby/core/time/gm_spec.rb
+++ b/spec/ruby/core/time/gm_spec.rb
@@ -3,8 +3,8 @@ require File.expand_path('../shared/gm', __FILE__)
require File.expand_path('../shared/time_params', __FILE__)
describe "Time.gm" do
- it_behaves_like(:time_gm, :gm)
- it_behaves_like(:time_params, :gm)
- it_behaves_like(:time_params_10_arg, :gm)
- it_behaves_like(:time_params_microseconds, :gm)
+ it_behaves_like :time_gm, :gm
+ it_behaves_like :time_params, :gm
+ it_behaves_like :time_params_10_arg, :gm
+ it_behaves_like :time_params_microseconds, :gm
end
diff --git a/spec/ruby/core/time/gmt_offset_spec.rb b/spec/ruby/core/time/gmt_offset_spec.rb
index b7613eed2f..bf2adb7d78 100644
--- a/spec/ruby/core/time/gmt_offset_spec.rb
+++ b/spec/ruby/core/time/gmt_offset_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/gmt_offset', __FILE__)
describe "Time#gmt_offset" do
- it_behaves_like(:time_gmt_offset, :gmt_offset)
+ it_behaves_like :time_gmt_offset, :gmt_offset
end
diff --git a/spec/ruby/core/time/gmtime_spec.rb b/spec/ruby/core/time/gmtime_spec.rb
index 49a1f10479..c888bb8f4d 100644
--- a/spec/ruby/core/time/gmtime_spec.rb
+++ b/spec/ruby/core/time/gmtime_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/gmtime', __FILE__)
describe "Time#gmtime" do
- it_behaves_like(:time_gmtime, :gmtime)
+ it_behaves_like :time_gmtime, :gmtime
end
diff --git a/spec/ruby/core/time/gmtoff_spec.rb b/spec/ruby/core/time/gmtoff_spec.rb
index 505b5d0c1b..8ef61997fe 100644
--- a/spec/ruby/core/time/gmtoff_spec.rb
+++ b/spec/ruby/core/time/gmtoff_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/gmt_offset', __FILE__)
describe "Time#gmtoff" do
- it_behaves_like(:time_gmt_offset, :gmtoff)
+ it_behaves_like :time_gmt_offset, :gmtoff
end
diff --git a/spec/ruby/core/time/isdst_spec.rb b/spec/ruby/core/time/isdst_spec.rb
index de71bf68ff..6c5664ce2a 100644
--- a/spec/ruby/core/time/isdst_spec.rb
+++ b/spec/ruby/core/time/isdst_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/isdst', __FILE__)
describe "Time#isdst" do
- it_behaves_like(:time_isdst, :isdst)
+ it_behaves_like :time_isdst, :isdst
end
diff --git a/spec/ruby/core/time/local_spec.rb b/spec/ruby/core/time/local_spec.rb
index 63c644e4ea..5c1894b910 100644
--- a/spec/ruby/core/time/local_spec.rb
+++ b/spec/ruby/core/time/local_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/local', __FILE__)
require File.expand_path('../shared/time_params', __FILE__)
describe "Time.local" do
- it_behaves_like(:time_local, :local)
- it_behaves_like(:time_local_10_arg, :local)
- it_behaves_like(:time_params, :local)
- it_behaves_like(:time_params_10_arg, :local)
- it_behaves_like(:time_params_microseconds, :local)
+ it_behaves_like :time_local, :local
+ it_behaves_like :time_local_10_arg, :local
+ it_behaves_like :time_params, :local
+ it_behaves_like :time_params_10_arg, :local
+ it_behaves_like :time_params_microseconds, :local
end
diff --git a/spec/ruby/core/time/mday_spec.rb b/spec/ruby/core/time/mday_spec.rb
index 5fbff299cc..e1b340e9cb 100644
--- a/spec/ruby/core/time/mday_spec.rb
+++ b/spec/ruby/core/time/mday_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/day', __FILE__)
describe "Time#mday" do
- it_behaves_like(:time_day, :mday)
+ it_behaves_like :time_day, :mday
end
diff --git a/spec/ruby/core/time/mktime_spec.rb b/spec/ruby/core/time/mktime_spec.rb
index 68ac1b90ac..9ff05d94a8 100644
--- a/spec/ruby/core/time/mktime_spec.rb
+++ b/spec/ruby/core/time/mktime_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/local', __FILE__)
require File.expand_path('../shared/time_params', __FILE__)
describe "Time.mktime" do
- it_behaves_like(:time_local, :mktime)
- it_behaves_like(:time_local_10_arg, :mktime)
- it_behaves_like(:time_params, :mktime)
- it_behaves_like(:time_params_10_arg, :mktime)
- it_behaves_like(:time_params_microseconds, :mktime)
+ it_behaves_like :time_local, :mktime
+ it_behaves_like :time_local_10_arg, :mktime
+ it_behaves_like :time_params, :mktime
+ it_behaves_like :time_params_10_arg, :mktime
+ it_behaves_like :time_params_microseconds, :mktime
end
diff --git a/spec/ruby/core/time/mon_spec.rb b/spec/ruby/core/time/mon_spec.rb
index 2408341143..0e52788ead 100644
--- a/spec/ruby/core/time/mon_spec.rb
+++ b/spec/ruby/core/time/mon_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/month', __FILE__)
describe "Time#mon" do
- it_behaves_like(:time_month, :mon)
+ it_behaves_like :time_month, :mon
end
diff --git a/spec/ruby/core/time/month_spec.rb b/spec/ruby/core/time/month_spec.rb
index 6323c6205a..c5e1c1c7fe 100644
--- a/spec/ruby/core/time/month_spec.rb
+++ b/spec/ruby/core/time/month_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/month', __FILE__)
describe "Time#month" do
- it_behaves_like(:time_month, :month)
+ it_behaves_like :time_month, :month
end
diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb
index a92715c81c..f81900a07b 100644
--- a/spec/ruby/core/time/new_spec.rb
+++ b/spec/ruby/core/time/new_spec.rb
@@ -4,12 +4,12 @@ require File.expand_path('../shared/local', __FILE__)
require File.expand_path('../shared/time_params', __FILE__)
describe "Time.new" do
- it_behaves_like(:time_now, :new)
+ it_behaves_like :time_now, :new
end
describe "Time.new" do
- it_behaves_like(:time_local, :new)
- it_behaves_like(:time_params, :new)
+ it_behaves_like :time_local, :new
+ it_behaves_like :time_params, :new
end
describe "Time.new with a utc_offset argument" do
diff --git a/spec/ruby/core/time/now_spec.rb b/spec/ruby/core/time/now_spec.rb
index 399a1a22e2..3dd86ff7d5 100644
--- a/spec/ruby/core/time/now_spec.rb
+++ b/spec/ruby/core/time/now_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/now', __FILE__)
describe "Time.now" do
- it_behaves_like(:time_now, :now)
+ it_behaves_like :time_now, :now
end
diff --git a/spec/ruby/core/time/to_i_spec.rb b/spec/ruby/core/time/to_i_spec.rb
index 1a733f02cf..1e88c12dd8 100644
--- a/spec/ruby/core/time/to_i_spec.rb
+++ b/spec/ruby/core/time/to_i_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Time#to_i" do
- it_behaves_like(:time_to_i, :to_i)
+ it_behaves_like :time_to_i, :to_i
end
diff --git a/spec/ruby/core/time/tv_sec_spec.rb b/spec/ruby/core/time/tv_sec_spec.rb
index 36f090be7b..40397d2e11 100644
--- a/spec/ruby/core/time/tv_sec_spec.rb
+++ b/spec/ruby/core/time/tv_sec_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/to_i', __FILE__)
describe "Time#tv_sec" do
- it_behaves_like(:time_to_i, :tv_sec)
+ it_behaves_like :time_to_i, :tv_sec
end
diff --git a/spec/ruby/core/time/utc_offset_spec.rb b/spec/ruby/core/time/utc_offset_spec.rb
index 4be885f2e3..ec5dd3c810 100644
--- a/spec/ruby/core/time/utc_offset_spec.rb
+++ b/spec/ruby/core/time/utc_offset_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/gmt_offset', __FILE__)
describe "Time#utc_offset" do
- it_behaves_like(:time_gmt_offset, :utc_offset)
+ it_behaves_like :time_gmt_offset, :utc_offset
end
diff --git a/spec/ruby/core/time/utc_spec.rb b/spec/ruby/core/time/utc_spec.rb
index f88b9c7cbc..cf267517fa 100644
--- a/spec/ruby/core/time/utc_spec.rb
+++ b/spec/ruby/core/time/utc_spec.rb
@@ -10,12 +10,12 @@ describe "Time#utc?" do
end
describe "Time.utc" do
- it_behaves_like(:time_gm, :utc)
- it_behaves_like(:time_params, :utc)
- it_behaves_like(:time_params_10_arg, :utc)
- it_behaves_like(:time_params_microseconds, :utc)
+ it_behaves_like :time_gm, :utc
+ it_behaves_like :time_params, :utc
+ it_behaves_like :time_params_10_arg, :utc
+ it_behaves_like :time_params_microseconds, :utc
end
describe "Time#utc" do
- it_behaves_like(:time_gmtime, :utc)
+ it_behaves_like :time_gmtime, :utc
end
diff --git a/spec/ruby/core/unboundmethod/inspect_spec.rb b/spec/ruby/core/unboundmethod/inspect_spec.rb
index ffef61a639..a393a1ead3 100644
--- a/spec/ruby/core/unboundmethod/inspect_spec.rb
+++ b/spec/ruby/core/unboundmethod/inspect_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/to_s', __FILE__)
describe "UnboundMethod#inspect" do
- it_behaves_like(:unboundmethod_to_s, :inspect)
+ it_behaves_like :unboundmethod_to_s, :inspect
end
diff --git a/spec/ruby/core/unboundmethod/to_s_spec.rb b/spec/ruby/core/unboundmethod/to_s_spec.rb
index 77e1d713f0..fbd9dc4ee8 100644
--- a/spec/ruby/core/unboundmethod/to_s_spec.rb
+++ b/spec/ruby/core/unboundmethod/to_s_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/to_s', __FILE__)
describe "UnboundMethod#to_s" do
- it_behaves_like(:unboundmethod_to_s, :to_s)
+ it_behaves_like :unboundmethod_to_s, :to_s
end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index c31a2afb41..c0b2efbfc7 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -488,7 +488,7 @@ describe "A nested method definition" do
DefSpecNested.should_not have_instance_method :body_method
end
- it "defines methods as public by default" do
+ it "creates an instance method inside Class.new" do
cls = Class.new do
def do_def
def new_def
@@ -500,6 +500,41 @@ describe "A nested method definition" do
obj = cls.new
obj.do_def
obj.new_def.should == 1
+
+ cls.new.new_def.should == 1
+
+ -> { Object.new.new_def }.should raise_error(NoMethodError)
+ end
+end
+
+describe "A method definition always resets the visibility to public for nested definitions" do
+ it "in Class.new" do
+ cls = Class.new do
+ private
+ def do_def
+ def new_def
+ 1
+ end
+ end
+ end
+
+ obj = cls.new
+ -> { obj.do_def }.should raise_error(NoMethodError, /private/)
+ obj.send :do_def
+ obj.new_def.should == 1
+
+ cls.new.new_def.should == 1
+
+ -> { Object.new.new_def }.should raise_error(NoMethodError)
+ end
+
+ it "at the toplevel" do
+ obj = Object.new
+ -> { obj.toplevel_define_other_method }.should raise_error(NoMethodError, /private/)
+ toplevel_define_other_method
+ nested_method_in_toplevel_method.should == 42
+
+ Object.new.nested_method_in_toplevel_method.should == 42
end
end
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index 08fa2d8fe3..98f4ee8829 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -505,6 +505,10 @@ describe "The defined? keyword for variables" do
DefinedSpecs::Basic.new.global_variable_read.should be_nil
end
+ it "returns 'global-variable' for a global variable that has been assigned nil" do
+ DefinedSpecs::Basic.new.global_variable_defined_as_nil.should == "global-variable"
+ end
+
# MRI appears to special case defined? for $! and $~ in that it returns
# 'global-variable' even when they are not set (or they are always "set"
# but the value may be nil). In other words, 'defined?($~)' will return
@@ -752,8 +756,16 @@ describe "The defined? keyword for a scoped constant" do
defined?(DefinedSpecs::String).should be_nil
end
- it "returns nil when a constant is defined on top-level but not on the class" do
- defined?(DefinedSpecs::Basic::String).should be_nil
+ ruby_version_is ""..."2.6" do
+ it "returns 'constant' when a constant is defined on top-level but not on the class" do
+ defined?(DefinedSpecs::Basic::String).should == 'constant'
+ end
+ end
+
+ ruby_version_is "2.6" do
+ it "returns nil when a constant is defined on top-level but not on the class" do
+ defined?(DefinedSpecs::Basic::String).should be_nil
+ end
end
it "returns 'constant' if the scoped-scoped constant is defined" do
diff --git a/spec/ruby/language/fixtures/def.rb b/spec/ruby/language/fixtures/def.rb
index 81bfce73d0..e07060ed74 100644
--- a/spec/ruby/language/fixtures/def.rb
+++ b/spec/ruby/language/fixtures/def.rb
@@ -1,3 +1,9 @@
+def toplevel_define_other_method
+ def nested_method_in_toplevel_method
+ 42
+ end
+end
+
def some_toplevel_method
end
diff --git a/spec/ruby/language/fixtures/defined.rb b/spec/ruby/language/fixtures/defined.rb
index d26e553c4b..8b6004c19f 100644
--- a/spec/ruby/language/fixtures/defined.rb
+++ b/spec/ruby/language/fixtures/defined.rb
@@ -94,6 +94,11 @@ module DefinedSpecs
defined? $defined_specs_global_variable_defined
end
+ def global_variable_defined_as_nil
+ $defined_specs_global_variable_defined_as_nil = nil
+ defined? $defined_specs_global_variable_defined_as_nil
+ end
+
def class_variable_undefined
defined? @@class_variable_undefined
end
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index d4b0c81128..684808f5ab 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -147,4 +147,24 @@ describe "Literal Regexps" do
pattern.should_not =~ 'fooF'
pattern.should_not =~ 'T'
end
+
+ escapable_terminators = ['!', '"', '#', '%', '&', "'", ',', '-', ':', ';', '@', '_', '`']
+
+ it "supports escaping characters when used as a terminator" do
+ escapable_terminators.each do |c|
+ ref = "(?-mix:#{c})"
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.to_s.should == ref
+ end
+ end
+
+ it "treats an escaped non-escapable character normally when used as a terminator" do
+ all_terminators = [*("!".."/"), *(":".."@"), *("[".."`"), *("{".."~")]
+ special_cases = ['(', '{', '[', '<', '\\', '=', '~']
+ (all_terminators - special_cases - escapable_terminators).each do |c|
+ ref = "(?-mix:\\#{c})"
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.to_s.should == ref
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/case_compare_spec.rb b/spec/ruby/library/bigdecimal/case_compare_spec.rb
index dcbde80e85..2cb7345d5a 100644
--- a/spec/ruby/library/bigdecimal/case_compare_spec.rb
+++ b/spec/ruby/library/bigdecimal/case_compare_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/eql.rb', __FILE__)
describe "BigDecimal#===" do
- it_behaves_like(:bigdecimal_eql, :===)
+ it_behaves_like :bigdecimal_eql, :===
end
diff --git a/spec/ruby/library/bigdecimal/eql_spec.rb b/spec/ruby/library/bigdecimal/eql_spec.rb
index f3f525a7ba..5018b1d670 100644
--- a/spec/ruby/library/bigdecimal/eql_spec.rb
+++ b/spec/ruby/library/bigdecimal/eql_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/eql.rb', __FILE__)
describe "BigDecimal#eql?" do
- it_behaves_like(:bigdecimal_eql, :eql?)
+ it_behaves_like :bigdecimal_eql, :eql?
end
diff --git a/spec/ruby/library/bigdecimal/equal_value_spec.rb b/spec/ruby/library/bigdecimal/equal_value_spec.rb
index bd07217b98..bcffdfe58a 100644
--- a/spec/ruby/library/bigdecimal/equal_value_spec.rb
+++ b/spec/ruby/library/bigdecimal/equal_value_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/eql.rb', __FILE__)
describe "BigDecimal#==" do
- it_behaves_like(:bigdecimal_eql, :==)
+ it_behaves_like :bigdecimal_eql, :==
end
diff --git a/spec/ruby/library/bigdecimal/exponent_spec.rb b/spec/ruby/library/bigdecimal/exponent_spec.rb
index 6bb678d4ed..449c55d8fe 100644
--- a/spec/ruby/library/bigdecimal/exponent_spec.rb
+++ b/spec/ruby/library/bigdecimal/exponent_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/power', __FILE__)
require 'bigdecimal'
describe "BigDecimal#**" do
- it_behaves_like(:bigdecimal_power, :**)
+ it_behaves_like :bigdecimal_power, :**
end
describe "BigDecimal#exponent" do
diff --git a/spec/ruby/library/bigdecimal/modulo_spec.rb b/spec/ruby/library/bigdecimal/modulo_spec.rb
index 6feeb685eb..04919c4362 100644
--- a/spec/ruby/library/bigdecimal/modulo_spec.rb
+++ b/spec/ruby/library/bigdecimal/modulo_spec.rb
@@ -2,11 +2,11 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/modulo', __FILE__)
describe "BigDecimal#%" do
- it_behaves_like(:bigdecimal_modulo, :%)
- it_behaves_like(:bigdecimal_modulo_zerodivisionerror, :%)
+ it_behaves_like :bigdecimal_modulo, :%
+ it_behaves_like :bigdecimal_modulo_zerodivisionerror, :%
end
describe "BigDecimal#modulo" do
- it_behaves_like(:bigdecimal_modulo, :modulo)
- it_behaves_like(:bigdecimal_modulo_zerodivisionerror, :modulo)
+ it_behaves_like :bigdecimal_modulo, :modulo
+ it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo
end
diff --git a/spec/ruby/library/bigdecimal/power_spec.rb b/spec/ruby/library/bigdecimal/power_spec.rb
index f2b1a9b5c8..c9aef58b12 100644
--- a/spec/ruby/library/bigdecimal/power_spec.rb
+++ b/spec/ruby/library/bigdecimal/power_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/power', __FILE__)
describe "BigDecimal#power" do
- it_behaves_like(:bigdecimal_power, :power)
+ it_behaves_like :bigdecimal_power, :power
end
diff --git a/spec/ruby/library/bigdecimal/to_i_spec.rb b/spec/ruby/library/bigdecimal/to_i_spec.rb
index 8db69003c5..4ec7b3ec7e 100644
--- a/spec/ruby/library/bigdecimal/to_i_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_i_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/to_int', __FILE__)
require 'bigdecimal'
describe "BigDecimal#to_i" do
- it_behaves_like(:bigdecimal_to_int, :to_i)
+ it_behaves_like :bigdecimal_to_int, :to_i
end
diff --git a/spec/ruby/library/bigdecimal/to_int_spec.rb b/spec/ruby/library/bigdecimal/to_int_spec.rb
index 56a60d4a03..abe8663a60 100644
--- a/spec/ruby/library/bigdecimal/to_int_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_int_spec.rb
@@ -4,5 +4,5 @@ require 'bigdecimal'
describe "BigDecimal#to_int" do
- it_behaves_like(:bigdecimal_to_int, :to_int)
+ it_behaves_like :bigdecimal_to_int, :to_int
end
diff --git a/spec/ruby/library/cgi/http_header_spec.rb b/spec/ruby/library/cgi/http_header_spec.rb
index 1960d009e4..0fb7033a68 100644
--- a/spec/ruby/library/cgi/http_header_spec.rb
+++ b/spec/ruby/library/cgi/http_header_spec.rb
@@ -4,5 +4,5 @@ require 'cgi'
require File.expand_path('../shared/http_header', __FILE__)
describe "CGI#http_header" do
- it_behaves_like(:cgi_http_header, :http_header)
+ it_behaves_like :cgi_http_header, :http_header
end
diff --git a/spec/ruby/library/date/civil_spec.rb b/spec/ruby/library/date/civil_spec.rb
index 36e790aecd..c0552e57a5 100644
--- a/spec/ruby/library/date/civil_spec.rb
+++ b/spec/ruby/library/date/civil_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/civil', __FILE__)
require 'date'
describe "Date#civil" do
- it_behaves_like(:date_civil, :civil)
+ it_behaves_like :date_civil, :civil
end
diff --git a/spec/ruby/library/date/commercial_spec.rb b/spec/ruby/library/date/commercial_spec.rb
index bb6671eda1..c815de141c 100644
--- a/spec/ruby/library/date/commercial_spec.rb
+++ b/spec/ruby/library/date/commercial_spec.rb
@@ -4,7 +4,7 @@ require File.expand_path('../shared/commercial', __FILE__)
describe "Date#commercial" do
- it_behaves_like(:date_commercial, :commercial)
+ it_behaves_like :date_commercial, :commercial
end
diff --git a/spec/ruby/library/date/new_spec.rb b/spec/ruby/library/date/new_spec.rb
index f468036a01..77bffd4876 100644
--- a/spec/ruby/library/date/new_spec.rb
+++ b/spec/ruby/library/date/new_spec.rb
@@ -4,5 +4,5 @@ require File.expand_path('../shared/civil', __FILE__)
require File.expand_path('../shared/new_bang', __FILE__)
describe "Date.new" do
- it_behaves_like(:date_civil, :new)
+ it_behaves_like :date_civil, :new
end
diff --git a/spec/ruby/library/digest/md5/append_spec.rb b/spec/ruby/library/digest/md5/append_spec.rb
index ad828c83c1..5c37981285 100644
--- a/spec/ruby/library/digest/md5/append_spec.rb
+++ b/spec/ruby/library/digest/md5/append_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/constants', __FILE__)
require File.expand_path('../shared/update', __FILE__)
describe "Digest::MD5#<<" do
- it_behaves_like(:md5_update, :<<)
+ it_behaves_like :md5_update, :<<
end
diff --git a/spec/ruby/library/digest/sha256/append_spec.rb b/spec/ruby/library/digest/sha256/append_spec.rb
index 53e623743a..a776869692 100644
--- a/spec/ruby/library/digest/sha256/append_spec.rb
+++ b/spec/ruby/library/digest/sha256/append_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/constants', __FILE__)
require File.expand_path('../shared/update', __FILE__)
describe "Digest::SHA256#<<" do
- it_behaves_like(:sha256_update, :<<)
+ it_behaves_like :sha256_update, :<<
end
diff --git a/spec/ruby/library/digest/sha384/append_spec.rb b/spec/ruby/library/digest/sha384/append_spec.rb
index d694812e85..6849bd0a9c 100644
--- a/spec/ruby/library/digest/sha384/append_spec.rb
+++ b/spec/ruby/library/digest/sha384/append_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/constants', __FILE__)
require File.expand_path('../shared/update', __FILE__)
describe "Digest::SHA384#<<" do
- it_behaves_like(:sha384_update, :<<)
+ it_behaves_like :sha384_update, :<<
end
diff --git a/spec/ruby/library/digest/sha512/append_spec.rb b/spec/ruby/library/digest/sha512/append_spec.rb
index 642e565bf6..de471fa51f 100644
--- a/spec/ruby/library/digest/sha512/append_spec.rb
+++ b/spec/ruby/library/digest/sha512/append_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/constants', __FILE__)
require File.expand_path('../shared/update', __FILE__)
describe "Digest::SHA512#<<" do
- it_behaves_like(:sha512_update, :<<)
+ it_behaves_like :sha512_update, :<<
end
diff --git a/spec/ruby/library/etc/endgrent_spec.rb b/spec/ruby/library/etc/endgrent_spec.rb
index 95f0dc05e3..4b9fd0d017 100644
--- a/spec/ruby/library/etc/endgrent_spec.rb
+++ b/spec/ruby/library/etc/endgrent_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/windows', __FILE__)
require 'etc'
describe "Etc.endgrent" do
- it_behaves_like(:etc_on_windows, :endgrent)
+ it_behaves_like :etc_on_windows, :endgrent
end
diff --git a/spec/ruby/library/etc/endpwent_spec.rb b/spec/ruby/library/etc/endpwent_spec.rb
index 7ce8f1925b..8875f4387d 100644
--- a/spec/ruby/library/etc/endpwent_spec.rb
+++ b/spec/ruby/library/etc/endpwent_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/windows', __FILE__)
require 'etc'
describe "Etc.endpwent" do
- it_behaves_like(:etc_on_windows, :endpwent)
+ it_behaves_like :etc_on_windows, :endpwent
end
diff --git a/spec/ruby/library/etc/getgrent_spec.rb b/spec/ruby/library/etc/getgrent_spec.rb
index 96225e351a..f0031b17ad 100644
--- a/spec/ruby/library/etc/getgrent_spec.rb
+++ b/spec/ruby/library/etc/getgrent_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/windows', __FILE__)
require 'etc'
describe "Etc.getgrent" do
- it_behaves_like(:etc_on_windows, :getgrent)
+ it_behaves_like :etc_on_windows, :getgrent
end
diff --git a/spec/ruby/library/etc/getpwent_spec.rb b/spec/ruby/library/etc/getpwent_spec.rb
index 1c8057c9e5..635aa8a478 100644
--- a/spec/ruby/library/etc/getpwent_spec.rb
+++ b/spec/ruby/library/etc/getpwent_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/windows', __FILE__)
require 'etc'
describe "Etc.getpwent" do
- it_behaves_like(:etc_on_windows, :getpwent)
+ it_behaves_like :etc_on_windows, :getpwent
end
diff --git a/spec/ruby/library/etc/group_spec.rb b/spec/ruby/library/etc/group_spec.rb
index 8b92cb7bf0..62596398e1 100644
--- a/spec/ruby/library/etc/group_spec.rb
+++ b/spec/ruby/library/etc/group_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/windows', __FILE__)
require 'etc'
describe "Etc.group" do
- it_behaves_like(:etc_on_windows, :group)
+ it_behaves_like :etc_on_windows, :group
platform_is_not :windows do
it "raises a RuntimeError for parallel iteration" do
diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb
index ad501c1d74..541aafc29d 100644
--- a/spec/ruby/library/fiber/transfer_spec.rb
+++ b/spec/ruby/library/fiber/transfer_spec.rb
@@ -47,5 +47,42 @@ with_feature :fiber_library do
fiber = Fiber.new { fiber.resume }
lambda { fiber.transfer }.should raise_error(FiberError)
end
+
+ it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do
+ # This catches a bug where Fibers are running on a thread-pool
+ # and Fibers from a different Ruby Thread reuse the same native thread.
+ # Caching the Ruby Thread based on the native thread is not correct in that case,
+ # and the check for "fiber called across threads" in Fiber#transfer
+ # might be incorrect based on that.
+ 2.times do
+ Thread.new do
+ io_fiber = Fiber.new do |calling_fiber|
+ calling_fiber.transfer
+ end
+ io_fiber.transfer(Fiber.current)
+ value = Object.new
+ io_fiber.transfer(value).should equal value
+ end.join
+ end
+ end
+
+ it "transfers control between a non-main thread's root fiber to a child fiber and back again" do
+ states = []
+ thread = Thread.new do
+ f1 = Fiber.new do |f0|
+ states << 0
+ value2 = f0.transfer(1)
+ states << value2
+ 3
+ end
+
+ value1 = f1.transfer(Fiber.current)
+ states << value1
+ value3 = f1.transfer(2)
+ states << value3
+ end
+ thread.join
+ states.should == [0, 1, 2, 3]
+ end
end
end
diff --git a/spec/ruby/library/getoptlong/each_option_spec.rb b/spec/ruby/library/getoptlong/each_option_spec.rb
index c58815bfa9..7ad50f7ca3 100644
--- a/spec/ruby/library/getoptlong/each_option_spec.rb
+++ b/spec/ruby/library/getoptlong/each_option_spec.rb
@@ -3,5 +3,5 @@ require 'getoptlong'
require File.expand_path('../shared/each', __FILE__)
describe "GetoptLong#each_option" do
- it_behaves_like(:getoptlong_each, :each_option)
+ it_behaves_like :getoptlong_each, :each_option
end
diff --git a/spec/ruby/library/getoptlong/each_spec.rb b/spec/ruby/library/getoptlong/each_spec.rb
index d09f84a6db..ffd2e9d0c6 100644
--- a/spec/ruby/library/getoptlong/each_spec.rb
+++ b/spec/ruby/library/getoptlong/each_spec.rb
@@ -3,5 +3,5 @@ require 'getoptlong'
require File.expand_path('../shared/each', __FILE__)
describe "GetoptLong#each" do
- it_behaves_like(:getoptlong_each, :each)
+ it_behaves_like :getoptlong_each, :each
end
diff --git a/spec/ruby/library/getoptlong/get_option_spec.rb b/spec/ruby/library/getoptlong/get_option_spec.rb
index c56903e68e..e73c391ef4 100644
--- a/spec/ruby/library/getoptlong/get_option_spec.rb
+++ b/spec/ruby/library/getoptlong/get_option_spec.rb
@@ -3,5 +3,5 @@ require 'getoptlong'
require File.expand_path('../shared/get', __FILE__)
describe "GetoptLong#get_option" do
- it_behaves_like(:getoptlong_get, :get_option)
+ it_behaves_like :getoptlong_get, :get_option
end
diff --git a/spec/ruby/library/getoptlong/get_spec.rb b/spec/ruby/library/getoptlong/get_spec.rb
index ba1a1be6ad..ec1aae437c 100644
--- a/spec/ruby/library/getoptlong/get_spec.rb
+++ b/spec/ruby/library/getoptlong/get_spec.rb
@@ -3,5 +3,5 @@ require 'getoptlong'
require File.expand_path('../shared/get', __FILE__)
describe "GetoptLong#get" do
- it_behaves_like(:getoptlong_get, :get)
+ it_behaves_like :getoptlong_get, :get
end
diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb
index f83cc3cec4..0253c6c11c 100644
--- a/spec/ruby/library/matrix/I_spec.rb
+++ b/spec/ruby/library/matrix/I_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/identity', __FILE__)
describe "Matrix.I" do
- it_behaves_like(:matrix_identity, :I)
+ it_behaves_like :matrix_identity, :I
end
diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb
index e5b2d51758..56347a1a22 100644
--- a/spec/ruby/library/matrix/antisymmetric_spec.rb
+++ b/spec/ruby/library/matrix/antisymmetric_spec.rb
@@ -1,35 +1,37 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-describe "Matrix#antisymmetric?" do
- it "returns true for an antisymmetric Matrix" do
- Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true
- end
+ruby_version_is "2.6" do
+ describe "Matrix#antisymmetric?" do
+ it "returns true for an antisymmetric Matrix" do
+ Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true
+ end
- it "returns true for a 0x0 empty matrix" do
- Matrix.empty.antisymmetric?.should be_true
- end
+ it "returns true for a 0x0 empty matrix" do
+ Matrix.empty.antisymmetric?.should be_true
+ end
- it "returns false for non-antisymmetric matrices" do
- [
- Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element
- Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong
- ].each do |matrix|
- matrix.antisymmetric?.should be_false
+ it "returns false for non-antisymmetric matrices" do
+ [
+ Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
+ Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element
+ Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong
+ ].each do |matrix|
+ matrix.antisymmetric?.should be_false
+ end
end
- end
- it "raises an error for rectangular matrices" do
- [
- Matrix[[0], [0]],
- Matrix[[0, 0]],
- Matrix.empty(0, 2),
- Matrix.empty(2, 0),
- ].each do |rectangular_matrix|
- lambda {
- rectangular_matrix.antisymmetric?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ it "raises an error for rectangular matrices" do
+ [
+ Matrix[[0], [0]],
+ Matrix[[0, 0]],
+ Matrix.empty(0, 2),
+ Matrix.empty(2, 0),
+ ].each do |rectangular_matrix|
+ lambda {
+ rectangular_matrix.antisymmetric?
+ }.should raise_error(Matrix::ErrDimensionMismatch)
+ end
end
end
end
diff --git a/spec/ruby/library/matrix/collect_spec.rb b/spec/ruby/library/matrix/collect_spec.rb
index 1830aed103..1c9d10130d 100644
--- a/spec/ruby/library/matrix/collect_spec.rb
+++ b/spec/ruby/library/matrix/collect_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Matrix#collect" do
- it_behaves_like(:collect, :collect)
+ it_behaves_like :collect, :collect
end
diff --git a/spec/ruby/library/matrix/conj_spec.rb b/spec/ruby/library/matrix/conj_spec.rb
index 33221f7055..cb07b0b0a8 100644
--- a/spec/ruby/library/matrix/conj_spec.rb
+++ b/spec/ruby/library/matrix/conj_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/conjugate', __FILE__)
describe "Matrix#conj" do
- it_behaves_like(:matrix_conjugate, :conj)
+ it_behaves_like :matrix_conjugate, :conj
end
diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb
index fd19f7689c..596af61654 100644
--- a/spec/ruby/library/matrix/conjugate_spec.rb
+++ b/spec/ruby/library/matrix/conjugate_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/conjugate', __FILE__)
describe "Matrix#conjugate" do
- it_behaves_like(:matrix_conjugate, :conjugate)
+ it_behaves_like :matrix_conjugate, :conjugate
end
diff --git a/spec/ruby/library/matrix/det_spec.rb b/spec/ruby/library/matrix/det_spec.rb
index 698de34fd1..565dbc7f6d 100644
--- a/spec/ruby/library/matrix/det_spec.rb
+++ b/spec/ruby/library/matrix/det_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/determinant', __FILE__)
require 'matrix'
describe "Matrix#det" do
- it_behaves_like(:determinant, :det)
+ it_behaves_like :determinant, :det
end
diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb
index 9ad34c6fc3..6d1ec53ce3 100644
--- a/spec/ruby/library/matrix/determinant_spec.rb
+++ b/spec/ruby/library/matrix/determinant_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/determinant', __FILE__)
require 'matrix'
describe "Matrix#determinant" do
- it_behaves_like(:determinant, :determinant)
+ it_behaves_like :determinant, :determinant
end
diff --git a/spec/ruby/library/matrix/eql_spec.rb b/spec/ruby/library/matrix/eql_spec.rb
index e76d26753a..c43c7a4216 100644
--- a/spec/ruby/library/matrix/eql_spec.rb
+++ b/spec/ruby/library/matrix/eql_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/equal_value', __FILE__)
require 'matrix'
describe "Matrix#eql?" do
- it_behaves_like(:equal, :eql?)
+ it_behaves_like :equal, :eql?
it "returns false if some elements are == but not eql?" do
Matrix[[1, 2],[3, 4]].eql?(Matrix[[1, 2],[3, 4.0]]).should be_false
diff --git a/spec/ruby/library/matrix/equal_value_spec.rb b/spec/ruby/library/matrix/equal_value_spec.rb
index e14a38b872..5378288930 100644
--- a/spec/ruby/library/matrix/equal_value_spec.rb
+++ b/spec/ruby/library/matrix/equal_value_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/equal_value', __FILE__)
require 'matrix'
describe "Matrix#==" do
- it_behaves_like(:equal, :==)
+ it_behaves_like :equal, :==
it "returns true if some elements are == but not eql?" do
Matrix[[1, 2],[3, 4]].should == Matrix[[1, 2],[3, 4.0]]
diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb
index bc7df98dde..6060a60c85 100644
--- a/spec/ruby/library/matrix/identity_spec.rb
+++ b/spec/ruby/library/matrix/identity_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/identity', __FILE__)
describe "Matrix.identity" do
- it_behaves_like(:matrix_identity, :identity)
+ it_behaves_like :matrix_identity, :identity
end
diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb
index 41083879e4..5caa7161f7 100644
--- a/spec/ruby/library/matrix/imag_spec.rb
+++ b/spec/ruby/library/matrix/imag_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/imaginary', __FILE__)
describe "Matrix#imag" do
- it_behaves_like(:matrix_imaginary, :imag)
+ it_behaves_like :matrix_imaginary, :imag
end
diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb
index 2a05f1d5c3..90e478682a 100644
--- a/spec/ruby/library/matrix/imaginary_spec.rb
+++ b/spec/ruby/library/matrix/imaginary_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/imaginary', __FILE__)
describe "Matrix#imaginary" do
- it_behaves_like(:matrix_imaginary, :imaginary)
+ it_behaves_like :matrix_imaginary, :imaginary
end
diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb
index 0491aa7b07..c0bfce2c44 100644
--- a/spec/ruby/library/matrix/inv_spec.rb
+++ b/spec/ruby/library/matrix/inv_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../spec_helper', __FILE__)
require File.expand_path('../shared/inverse', __FILE__)
describe "Matrix#inv" do
- it_behaves_like(:inverse, :inv)
+ it_behaves_like :inverse, :inv
end
diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb
index 33a1f2f5de..885962a666 100644
--- a/spec/ruby/library/matrix/inverse_spec.rb
+++ b/spec/ruby/library/matrix/inverse_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../spec_helper', __FILE__)
require File.expand_path('../shared/inverse', __FILE__)
describe "Matrix#inverse" do
- it_behaves_like(:inverse, :inverse)
+ it_behaves_like :inverse, :inverse
end
diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb
index e18ab6eb7a..834914d48d 100644
--- a/spec/ruby/library/matrix/map_spec.rb
+++ b/spec/ruby/library/matrix/map_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/collect', __FILE__)
describe "Matrix#map" do
- it_behaves_like(:collect, :map)
+ it_behaves_like :collect, :map
end
diff --git a/spec/ruby/library/matrix/rect_spec.rb b/spec/ruby/library/matrix/rect_spec.rb
index d0a3b2705b..0015445a4c 100644
--- a/spec/ruby/library/matrix/rect_spec.rb
+++ b/spec/ruby/library/matrix/rect_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/rectangular', __FILE__)
describe "Matrix#rect" do
- it_behaves_like(:matrix_rectangular, :rect)
+ it_behaves_like :matrix_rectangular, :rect
end
diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb
index 7af446cb18..0f6555d10e 100644
--- a/spec/ruby/library/matrix/rectangular_spec.rb
+++ b/spec/ruby/library/matrix/rectangular_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/rectangular', __FILE__)
describe "Matrix#rectangular" do
- it_behaves_like(:matrix_rectangular, :rectangular)
+ it_behaves_like :matrix_rectangular, :rectangular
end
diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb
index 1c57c25de3..68df5eae2e 100644
--- a/spec/ruby/library/matrix/t_spec.rb
+++ b/spec/ruby/library/matrix/t_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/transpose', __FILE__)
describe "Matrix#transpose" do
- it_behaves_like(:matrix_transpose, :t)
+ it_behaves_like :matrix_transpose, :t
end
diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb
index 4b07a70203..cf0bdaaec9 100644
--- a/spec/ruby/library/matrix/tr_spec.rb
+++ b/spec/ruby/library/matrix/tr_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/trace', __FILE__)
require 'matrix'
describe "Matrix#tr" do
- it_behaves_like(:trace, :tr)
+ it_behaves_like :trace, :tr
end
diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb
index 08adb256c0..1c3251eac5 100644
--- a/spec/ruby/library/matrix/trace_spec.rb
+++ b/spec/ruby/library/matrix/trace_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/trace', __FILE__)
require 'matrix'
describe "Matrix#trace" do
- it_behaves_like(:trace, :trace)
+ it_behaves_like :trace, :trace
end
diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb
index 2a30a80efc..6c38a3d0cd 100644
--- a/spec/ruby/library/matrix/transpose_spec.rb
+++ b/spec/ruby/library/matrix/transpose_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/transpose', __FILE__)
describe "Matrix#transpose" do
- it_behaves_like(:matrix_transpose, :transpose)
+ it_behaves_like :matrix_transpose, :transpose
end
diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb
index 058d719043..005a718d8e 100644
--- a/spec/ruby/library/matrix/unit_spec.rb
+++ b/spec/ruby/library/matrix/unit_spec.rb
@@ -2,5 +2,5 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/identity', __FILE__)
describe "Matrix.unit" do
- it_behaves_like(:matrix_identity, :unit)
+ it_behaves_like :matrix_identity, :unit
end
diff --git a/spec/ruby/library/net/ftp/initialize_spec.rb b/spec/ruby/library/net/ftp/initialize_spec.rb
index 65105b8831..b33d345f32 100644
--- a/spec/ruby/library/net/ftp/initialize_spec.rb
+++ b/spec/ruby/library/net/ftp/initialize_spec.rb
@@ -88,4 +88,322 @@ describe "Net::FTP#initialize" do
@ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
end
end
+
+ ruby_version_is '2.4' do
+ before :each do
+ @ftp.stub!(:login)
+ end
+
+ describe 'when the host' do
+ describe 'is set' do
+ describe 'and port option' do
+ describe 'is set' do
+ it 'tries to connect to the host on the specified port' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ port: 8080 })
+ @ftp.should_receive(:connect).with('localhost', 8080)
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+
+ describe 'is not set' do
+ it 'tries to connect to the host without a port' do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
+
+ @ftp.send(:initialize, 'localhost')
+ end
+ end
+ end
+
+ describe 'when the username option' do
+ describe 'is set' do
+ describe 'and the password option' do
+ describe 'is set' do
+ describe 'and the account option' do
+ describe 'is set' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' })
+ @ftp.should_receive(:login).with('a', 'topsecret', 'b')
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+
+ describe 'is unset' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' })
+ @ftp.should_receive(:login).with('a', 'topsecret', nil)
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+ end
+ end
+
+ describe 'is unset' do
+ describe 'and the account option' do
+ describe 'is set' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' })
+ @ftp.should_receive(:login).with('a', nil, 'b')
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+
+ describe 'is unset' do
+ it 'tries to log in with the supplied parameters' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ username: 'a'})
+ @ftp.should_receive(:login).with('a', nil, nil)
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+ end
+ end
+ end
+ end
+
+ describe 'is not set' do
+ it 'does not try to log in' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
+ @ftp.should_not_receive(:login)
+
+ @ftp.send(:initialize, 'localhost', options)
+ end
+ end
+ end
+ end
+
+ describe 'is unset' do
+ it 'does not try to connect' do
+ @ftp.should_not_receive(:connect)
+
+ @ftp.send(:initialize)
+ end
+
+ it 'does not try to log in' do
+ @ftp.should_not_receive(:login)
+
+ @ftp.send(:initialize)
+ end
+ end
+ end
+
+ describe 'when the passive option' do
+ describe 'is set' do
+ describe 'to true' do
+ it 'sets passive to true' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ passive: true })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.passive.should == true
+ end
+ end
+
+ describe 'to false' do
+ it 'sets passive to false' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ passive: false })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.passive.should == false
+ end
+ end
+ end
+
+ describe 'is unset' do
+ it 'sets passive to false' do
+ @ftp.send(:initialize)
+ @ftp.passive.should == false
+ end
+ end
+ end
+
+ describe 'when the debug_mode option' do
+ describe 'is set' do
+ describe 'to true' do
+ it 'sets debug_mode to true' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ debug_mode: true })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.debug_mode.should == true
+ end
+ end
+
+ describe 'to false' do
+ it 'sets debug_mode to false' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ debug_mode: false })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.debug_mode.should == false
+ end
+ end
+ end
+
+ describe 'is unset' do
+ it 'sets debug_mode to false' do
+ @ftp.send(:initialize)
+ @ftp.debug_mode.should == false
+ end
+ end
+ end
+
+ describe 'when the open_timeout option' do
+ describe 'is set' do
+ it 'sets open_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ open_timeout: 42 })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.open_timeout.should == 42
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets open_timeout to nil' do
+ @ftp.send(:initialize)
+ @ftp.open_timeout.should == nil
+ end
+ end
+ end
+
+ describe 'when the read_timeout option' do
+ describe 'is set' do
+ it 'sets read_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ read_timeout: 100 })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.read_timeout.should == 100
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets read_timeout to the default value' do
+ @ftp.send(:initialize)
+ @ftp.read_timeout.should == 60
+ end
+ end
+ end
+
+ describe 'when the ssl_handshake_timeout option' do
+ describe 'is set' do
+ it 'sets ssl_handshake_timeout to the specified value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.ssl_handshake_timeout.should == 23
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets ssl_handshake_timeout to nil' do
+ @ftp.send(:initialize)
+ @ftp.ssl_handshake_timeout.should == nil
+ end
+ end
+ end
+
+ describe 'when the ssl option' do
+ describe 'is set' do
+ describe "and the ssl option's value is true" do
+ it 'initializes ssl_context to a blank SSLContext object' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true })
+
+ ssl_context = OpenSSL::SSL::SSLContext.allocate
+ ssl_context.stub!(:set_params)
+
+ OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
+ ssl_context.should_receive(:set_params).with({})
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == ssl_context
+ end
+ end
+
+ describe "and the ssl option's value is a hash" do
+ it 'initializes ssl_context to a configured SSLContext object' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} })
+
+ ssl_context = OpenSSL::SSL::SSLContext.allocate
+ ssl_context.stub!(:set_params)
+
+ OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context)
+ ssl_context.should_receive(:set_params).with({key: 'value'})
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == ssl_context
+ end
+ end
+
+ describe 'and private_data_connection' do
+ describe 'is set' do
+ it 'sets private_data_connection to that value' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == 'true'
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets private_data_connection to nil' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ ssl: true })
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == true
+ end
+ end
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets ssl_context to nil' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@ssl_context).should == nil
+ end
+
+ describe 'private_data_connection' do
+ describe 'is set' do
+ it 'raises an ArgumentError' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ private_data_connection: true })
+
+ -> {
+ @ftp.send(:initialize, nil, options)
+ }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/)
+ end
+ end
+
+ describe 'is not set' do
+ it 'sets private_data_connection to false' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({})
+
+ @ftp.send(:initialize, nil, options)
+ @ftp.instance_variable_get(:@private_data_connection).should == false
+ end
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/library/rexml/document/add_spec.rb b/spec/ruby/library/rexml/document/add_spec.rb
index 491c28259b..484731fe9b 100644
--- a/spec/ruby/library/rexml/document/add_spec.rb
+++ b/spec/ruby/library/rexml/document/add_spec.rb
@@ -49,9 +49,9 @@ describe :rexml_document_add, shared: true do
end
describe "REXML::Document#add" do
- it_behaves_like(:rexml_document_add, :add)
+ it_behaves_like :rexml_document_add, :add
end
describe "REXML::Document#<<" do
- it_behaves_like(:rexml_document_add, :<<)
+ it_behaves_like :rexml_document_add, :<<
end
diff --git a/spec/ruby/library/rexml/document/expanded_name_spec.rb b/spec/ruby/library/rexml/document/expanded_name_spec.rb
index e18fd95c14..182f49eddd 100644
--- a/spec/ruby/library/rexml/document/expanded_name_spec.rb
+++ b/spec/ruby/library/rexml/document/expanded_name_spec.rb
@@ -8,9 +8,9 @@ describe :document_expanded_name, shared: true do
end
describe "REXML::Document#expanded_name" do
- it_behaves_like(:document_expanded_name, :expanded_name)
+ it_behaves_like :document_expanded_name, :expanded_name
end
describe "REXML::Document#name" do
- it_behaves_like(:document_expanded_name, :name)
+ it_behaves_like :document_expanded_name, :name
end
diff --git a/spec/ruby/library/scanf/io/block_scanf_spec.rb b/spec/ruby/library/scanf/io/block_scanf_spec.rb
index 0f6188f91c..aee6459199 100644
--- a/spec/ruby/library/scanf/io/block_scanf_spec.rb
+++ b/spec/ruby/library/scanf/io/block_scanf_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/block_scanf.rb', __FILE__)
require 'scanf'
describe "IO#block_scanf" do
- it_behaves_like(:scanf_io_block_scanf, :block_scanf)
+ it_behaves_like :scanf_io_block_scanf, :block_scanf
end
diff --git a/spec/ruby/library/scanf/io/scanf_spec.rb b/spec/ruby/library/scanf/io/scanf_spec.rb
index 27c3142678..7752036c09 100644
--- a/spec/ruby/library/scanf/io/scanf_spec.rb
+++ b/spec/ruby/library/scanf/io/scanf_spec.rb
@@ -31,5 +31,5 @@ describe "IO#scanf" do
end
describe "IO#scanf with block" do
- it_behaves_like(:scanf_io_block_scanf, :scanf)
+ it_behaves_like :scanf_io_block_scanf, :scanf
end
diff --git a/spec/ruby/library/scanf/string/block_scanf_spec.rb b/spec/ruby/library/scanf/string/block_scanf_spec.rb
index 1444cc2975..9dc5b52a84 100644
--- a/spec/ruby/library/scanf/string/block_scanf_spec.rb
+++ b/spec/ruby/library/scanf/string/block_scanf_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/block_scanf.rb', __FILE__)
require 'scanf'
describe "String#block_scanf" do
- it_behaves_like(:scanf_string_block_scanf, :block_scanf)
+ it_behaves_like :scanf_string_block_scanf, :block_scanf
end
diff --git a/spec/ruby/library/scanf/string/scanf_spec.rb b/spec/ruby/library/scanf/string/scanf_spec.rb
index 360c72fba8..885361d5af 100644
--- a/spec/ruby/library/scanf/string/scanf_spec.rb
+++ b/spec/ruby/library/scanf/string/scanf_spec.rb
@@ -49,5 +49,5 @@ describe "String#scanf" do
end
describe "String#scanf with block" do
- it_behaves_like(:scanf_string_block_scanf, :scanf)
+ it_behaves_like :scanf_string_block_scanf, :scanf
end
diff --git a/spec/ruby/library/socket/addrinfo/to_s_spec.rb b/spec/ruby/library/socket/addrinfo/to_s_spec.rb
index 7205bdc823..3d2072fe02 100644
--- a/spec/ruby/library/socket/addrinfo/to_s_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/to_s_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/to_sockaddr', __FILE__)
require 'socket'
describe "Addrinfo#to_s" do
- it_behaves_like(:socket_addrinfo_to_sockaddr, :to_s)
+ it_behaves_like :socket_addrinfo_to_sockaddr, :to_s
end
diff --git a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
index f3f926c2b6..cbe7c903aa 100644
--- a/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/to_sockaddr', __FILE__)
require 'socket'
describe "Addrinfo#to_sockaddr" do
- it_behaves_like(:socket_addrinfo_to_sockaddr, :to_sockaddr)
+ it_behaves_like :socket_addrinfo_to_sockaddr, :to_sockaddr
end
diff --git a/spec/ruby/library/stringio/codepoints_spec.rb b/spec/ruby/library/stringio/codepoints_spec.rb
index 098bd3c4c3..5e6fa681e7 100644
--- a/spec/ruby/library/stringio/codepoints_spec.rb
+++ b/spec/ruby/library/stringio/codepoints_spec.rb
@@ -5,5 +5,5 @@ require File.expand_path('../shared/codepoints', __FILE__)
# See redmine #1667
describe "StringIO#codepoints" do
- it_behaves_like(:stringio_codepoints, :codepoints)
+ it_behaves_like :stringio_codepoints, :codepoints
end
diff --git a/spec/ruby/library/stringio/each_codepoint_spec.rb b/spec/ruby/library/stringio/each_codepoint_spec.rb
index 25a0bf4c81..8351bf4175 100644
--- a/spec/ruby/library/stringio/each_codepoint_spec.rb
+++ b/spec/ruby/library/stringio/each_codepoint_spec.rb
@@ -5,6 +5,6 @@ require File.expand_path('../shared/codepoints', __FILE__)
# See redmine #1667
describe "StringIO#each_codepoint" do
- it_behaves_like(:stringio_codepoints, :codepoints)
+ it_behaves_like :stringio_codepoints, :codepoints
end
diff --git a/spec/ruby/library/stringscanner/beginning_of_line_spec.rb b/spec/ruby/library/stringscanner/beginning_of_line_spec.rb
index 192a83f2c9..f4e820e099 100644
--- a/spec/ruby/library/stringscanner/beginning_of_line_spec.rb
+++ b/spec/ruby/library/stringscanner/beginning_of_line_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/bol.rb', __FILE__)
require 'strscan'
describe "StringScanner#beginning_of_line?" do
- it_behaves_like(:strscan_bol, :beginning_of_line?)
+ it_behaves_like :strscan_bol, :beginning_of_line?
end
diff --git a/spec/ruby/library/stringscanner/bol_spec.rb b/spec/ruby/library/stringscanner/bol_spec.rb
index ee5257529a..17a8c1cbff 100644
--- a/spec/ruby/library/stringscanner/bol_spec.rb
+++ b/spec/ruby/library/stringscanner/bol_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/bol.rb', __FILE__)
require 'strscan'
describe "StringScanner#bol?" do
- it_behaves_like(:strscan_bol, :bol?)
+ it_behaves_like :strscan_bol, :bol?
end
diff --git a/spec/ruby/library/stringscanner/clear_spec.rb b/spec/ruby/library/stringscanner/clear_spec.rb
index 81b2e68897..3ab0955819 100644
--- a/spec/ruby/library/stringscanner/clear_spec.rb
+++ b/spec/ruby/library/stringscanner/clear_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/terminate.rb', __FILE__)
require 'strscan'
describe "StringScanner#clear" do
- it_behaves_like(:strscan_terminate, :clear)
+ it_behaves_like :strscan_terminate, :clear
it "warns in verbose mode that the method is obsolete" do
s = StringScanner.new("abc")
diff --git a/spec/ruby/library/stringscanner/concat_spec.rb b/spec/ruby/library/stringscanner/concat_spec.rb
index dccc7d0efd..2f3e7d1694 100644
--- a/spec/ruby/library/stringscanner/concat_spec.rb
+++ b/spec/ruby/library/stringscanner/concat_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/concat.rb', __FILE__)
require 'strscan'
describe "StringScanner#concat" do
- it_behaves_like(:strscan_concat, :concat)
+ it_behaves_like :strscan_concat, :concat
end
describe "StringScanner#concat when passed a Fixnum" do
- it_behaves_like(:strscan_concat_fixnum, :concat)
+ it_behaves_like :strscan_concat_fixnum, :concat
end
diff --git a/spec/ruby/library/stringscanner/empty_spec.rb b/spec/ruby/library/stringscanner/empty_spec.rb
index ebbc2c2703..c6b9444215 100644
--- a/spec/ruby/library/stringscanner/empty_spec.rb
+++ b/spec/ruby/library/stringscanner/empty_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/eos.rb', __FILE__)
require 'strscan'
describe "StringScanner#empty?" do
- it_behaves_like(:strscan_eos, :empty?)
+ it_behaves_like :strscan_eos, :empty?
it "warns in verbose mode that the method is obsolete" do
s = StringScanner.new("abc")
diff --git a/spec/ruby/library/stringscanner/eos_spec.rb b/spec/ruby/library/stringscanner/eos_spec.rb
index 3fdeceb25d..3016a3fc52 100644
--- a/spec/ruby/library/stringscanner/eos_spec.rb
+++ b/spec/ruby/library/stringscanner/eos_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/eos.rb', __FILE__)
require 'strscan'
describe "StringScanner#eos?" do
- it_behaves_like(:strscan_eos, :eos?)
+ it_behaves_like :strscan_eos, :eos?
end
diff --git a/spec/ruby/library/stringscanner/matched_size_spec.rb b/spec/ruby/library/stringscanner/matched_size_spec.rb
index 7aac71878a..641d530be4 100644
--- a/spec/ruby/library/stringscanner/matched_size_spec.rb
+++ b/spec/ruby/library/stringscanner/matched_size_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/matched_size.rb', __FILE__)
require 'strscan'
describe "StringScanner#matched_size" do
- it_behaves_like(:strscan_matched_size, :matched_size)
+ it_behaves_like :strscan_matched_size, :matched_size
end
diff --git a/spec/ruby/library/stringscanner/peek_spec.rb b/spec/ruby/library/stringscanner/peek_spec.rb
index 49490ec3da..af40dbcb42 100644
--- a/spec/ruby/library/stringscanner/peek_spec.rb
+++ b/spec/ruby/library/stringscanner/peek_spec.rb
@@ -3,6 +3,6 @@ require File.expand_path('../shared/peek.rb', __FILE__)
require 'strscan'
describe "StringScanner#peek" do
- it_behaves_like(:strscan_peek, :peek)
+ it_behaves_like :strscan_peek, :peek
end
diff --git a/spec/ruby/library/stringscanner/peep_spec.rb b/spec/ruby/library/stringscanner/peep_spec.rb
index 677c6f8a21..1b1864c340 100644
--- a/spec/ruby/library/stringscanner/peep_spec.rb
+++ b/spec/ruby/library/stringscanner/peep_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/peek.rb', __FILE__)
require 'strscan'
describe "StringScanner#peep" do
- it_behaves_like(:strscan_peek, :peep)
+ it_behaves_like :strscan_peek, :peep
it "warns in verbose mode that the method is obsolete" do
s = StringScanner.new("abc")
diff --git a/spec/ruby/library/stringscanner/pointer_spec.rb b/spec/ruby/library/stringscanner/pointer_spec.rb
index 8c993c5a71..d9c6d163fe 100644
--- a/spec/ruby/library/stringscanner/pointer_spec.rb
+++ b/spec/ruby/library/stringscanner/pointer_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/pos.rb', __FILE__)
require 'strscan'
describe "StringScanner#pointer" do
- it_behaves_like(:strscan_pos, :pointer)
+ it_behaves_like :strscan_pos, :pointer
end
describe "StringScanner#pointer=" do
- it_behaves_like(:strscan_pos_set, :pointer=)
+ it_behaves_like :strscan_pos_set, :pointer=
end
diff --git a/spec/ruby/library/stringscanner/pos_spec.rb b/spec/ruby/library/stringscanner/pos_spec.rb
index 059e6ff846..b23a89e592 100644
--- a/spec/ruby/library/stringscanner/pos_spec.rb
+++ b/spec/ruby/library/stringscanner/pos_spec.rb
@@ -3,9 +3,9 @@ require File.expand_path('../shared/pos.rb', __FILE__)
require 'strscan'
describe "StringScanner#pos" do
- it_behaves_like(:strscan_pos, :pos)
+ it_behaves_like :strscan_pos, :pos
end
describe "StringScanner#pos=" do
- it_behaves_like(:strscan_pos_set, :pos=)
+ it_behaves_like :strscan_pos_set, :pos=
end
diff --git a/spec/ruby/library/stringscanner/rest_size_spec.rb b/spec/ruby/library/stringscanner/rest_size_spec.rb
index ad019f2a6b..97d8546967 100644
--- a/spec/ruby/library/stringscanner/rest_size_spec.rb
+++ b/spec/ruby/library/stringscanner/rest_size_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/rest_size.rb', __FILE__)
require 'strscan'
describe "StringScanner#rest_size" do
- it_behaves_like(:strscan_rest_size, :rest_size)
+ it_behaves_like :strscan_rest_size, :rest_size
end
diff --git a/spec/ruby/library/stringscanner/restsize_spec.rb b/spec/ruby/library/stringscanner/restsize_spec.rb
index 9822d69d84..ffef3c59e9 100644
--- a/spec/ruby/library/stringscanner/restsize_spec.rb
+++ b/spec/ruby/library/stringscanner/restsize_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../shared/rest_size.rb', __FILE__)
require 'strscan'
describe "StringScanner#restsize" do
- it_behaves_like(:strscan_rest_size, :restsize)
+ it_behaves_like :strscan_rest_size, :restsize
it "warns in verbose mode that the method is obsolete" do
s = StringScanner.new("abc")
diff --git a/spec/ruby/library/stringscanner/terminate_spec.rb b/spec/ruby/library/stringscanner/terminate_spec.rb
index 01cea3dbdf..3090bd76ba 100644
--- a/spec/ruby/library/stringscanner/terminate_spec.rb
+++ b/spec/ruby/library/stringscanner/terminate_spec.rb
@@ -3,5 +3,5 @@ require File.expand_path('../shared/terminate.rb', __FILE__)
require 'strscan'
describe "StringScanner#terminate" do
- it_behaves_like(:strscan_terminate, :terminate)
+ it_behaves_like :strscan_terminate, :terminate
end
diff --git a/spec/ruby/library/weakref/fixtures/classes.rb b/spec/ruby/library/weakref/fixtures/classes.rb
index 9a1d3ce370..560c58b041 100644
--- a/spec/ruby/library/weakref/fixtures/classes.rb
+++ b/spec/ruby/library/weakref/fixtures/classes.rb
@@ -15,7 +15,8 @@ class WeakRefSpec
weak = nil
10_000.times do
weaks << make_weakref
- 10.times { GC.start }
+ GC.start
+ GC.start
break if weak = weaks.find { |w| !w.weakref_alive? }
end
weak
diff --git a/spec/ruby/optional/capi/ext/numeric_spec.c b/spec/ruby/optional/capi/ext/numeric_spec.c
index 0b7fbabd1c..2f66c7bac7 100644
--- a/spec/ruby/optional/capi/ext/numeric_spec.c
+++ b/spec/ruby/optional/capi/ext/numeric_spec.c
@@ -9,6 +9,10 @@ static VALUE numeric_spec_size_of_VALUE(VALUE self) {
return INT2FIX(sizeof(VALUE));
}
+static VALUE numeric_spec_size_of_long_long(VALUE self) {
+ return INT2FIX(sizeof(LONG_LONG));
+}
+
#ifdef HAVE_NUM2CHR
static VALUE numeric_spec_NUM2CHR(VALUE self, VALUE value) {
return INT2FIX(NUM2CHR(value));
@@ -43,6 +47,16 @@ static VALUE numeric_spec_rb_ll2inum_14(VALUE self) {
}
#endif
+#ifdef HAVE_RB_ULL2INUM
+static VALUE numeric_spec_rb_ull2inum_14(VALUE self) {
+ return rb_ull2inum(14);
+}
+
+static VALUE numeric_spec_rb_ull2inum_n14(VALUE self) {
+ return rb_ull2inum(-14);
+}
+#endif
+
#ifdef HAVE_RB_NUM2DBL
static VALUE numeric_spec_rb_num2dbl(VALUE self, VALUE num) {
return rb_float_new(rb_num2dbl(num));
@@ -121,6 +135,7 @@ void Init_numeric_spec(void) {
cls = rb_define_class("CApiNumericSpecs", rb_cObject);
rb_define_method(cls, "size_of_VALUE", numeric_spec_size_of_VALUE, 0);
+ rb_define_method(cls, "size_of_long_long", numeric_spec_size_of_long_long, 0);
#ifdef HAVE_NUM2CHR
rb_define_method(cls, "NUM2CHR", numeric_spec_NUM2CHR, 1);
@@ -143,6 +158,11 @@ void Init_numeric_spec(void) {
rb_define_method(cls, "rb_ll2inum_14", numeric_spec_rb_ll2inum_14, 0);
#endif
+#ifdef HAVE_RB_ULL2INUM
+ rb_define_method(cls, "rb_ull2inum_14", numeric_spec_rb_ull2inum_14, 0);
+ rb_define_method(cls, "rb_ull2inum_n14", numeric_spec_rb_ull2inum_n14, 0);
+#endif
+
#ifdef HAVE_RB_NUM2DBL
rb_define_method(cls, "rb_num2dbl", numeric_spec_rb_num2dbl, 1);
#endif
diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h
index 50bc9033f0..780c2ab20f 100644
--- a/spec/ruby/optional/capi/ext/rubyspec.h
+++ b/spec/ruby/optional/capi/ext/rubyspec.h
@@ -412,6 +412,7 @@
#define HAVE_RB_UINT2INUM 1
#define HAVE_RB_INTEGER 1
#define HAVE_RB_LL2INUM 1
+#define HAVE_RB_ULL2INUM 1
#define HAVE_RB_NUM2DBL 1
#if SIZEOF_INT < SIZEOF_LONG
#define HAVE_RB_NUM2INT 1
diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb
index 1c406f0394..1a117bfbf8 100644
--- a/spec/ruby/optional/capi/hash_spec.rb
+++ b/spec/ruby/optional/capi/hash_spec.rb
@@ -1,4 +1,5 @@
require File.expand_path('../spec_helper', __FILE__)
+require File.expand_path('../../../shared/hash/key_error', __FILE__)
load_extension("hash")
@@ -136,6 +137,12 @@ describe "C-API Hash function" do
it "raises a KeyError if the key is not found and no default is set" do
lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError)
end
+
+ context "when key is not found" do
+ it_behaves_like :key_error, -> (obj, key) {
+ @s.rb_hash_fetch(obj, key)
+ }, { a: 1 }
+ end
end
describe "rb_hash_foreach" do
diff --git a/spec/ruby/optional/capi/numeric_spec.rb b/spec/ruby/optional/capi/numeric_spec.rb
index ff7880a986..b2f629c1ab 100644
--- a/spec/ruby/optional/capi/numeric_spec.rb
+++ b/spec/ruby/optional/capi/numeric_spec.rb
@@ -238,7 +238,7 @@ describe "CApiNumericSpecs" do
end
describe "rb_Integer" do
- it "creates a new Integer from a String" do
+ it "creates an Integer from a String" do
i = @s.rb_Integer("8675309")
i.should be_kind_of(Integer)
i.should eql(8675309)
@@ -246,15 +246,29 @@ describe "CApiNumericSpecs" do
end
describe "rb_ll2inum" do
- it "creates a new Fixnum from a small signed long long" do
+ it "creates a Fixnum from a small signed long long" do
i = @s.rb_ll2inum_14()
i.should be_kind_of(Fixnum)
i.should eql(14)
end
end
+ describe "rb_ull2inum" do
+ it "creates a Fixnum from a small unsigned long long" do
+ i = @s.rb_ull2inum_14()
+ i.should be_kind_of(Fixnum)
+ i.should eql(14)
+ end
+
+ it "creates a positive Bignum from a negative long long" do
+ i = @s.rb_ull2inum_n14()
+ i.should be_kind_of(Bignum)
+ i.should eql(2 ** (@s.size_of_long_long * 8) - 14)
+ end
+ end
+
describe "rb_int2inum" do
- it "creates a new Fixnum from a long" do
+ it "creates a Fixnum from a long" do
i = @s.rb_int2inum_14()
i.should be_kind_of(Fixnum)
i.should eql(14)
@@ -262,13 +276,13 @@ describe "CApiNumericSpecs" do
end
describe "rb_uint2inum" do
- it "creates a new Fixnum from a long" do
+ it "creates a Fixnum from a long" do
i = @s.rb_uint2inum_14()
i.should be_kind_of(Fixnum)
i.should eql(14)
end
- it "creates a new Bignum from a negative long" do
+ it "creates a positive Bignum from a negative long" do
i = @s.rb_uint2inum_n14()
i.should be_kind_of(Bignum)
i.should eql(2 ** (@s.size_of_VALUE * 8) - 14)
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 5f2309d1cd..024a153b1a 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -479,14 +479,16 @@ describe "C-API String function" do
describe "SafeStringValue" do
it "raises for tained string when $SAFE is 1" do
- Thread.new {
- $SAFE = 1
- lambda {
- @s.SafeStringValue("str".taint)
- }.should raise_error(SecurityError)
- }.join
- ensure
- $SAFE = 0
+ begin
+ Thread.new {
+ $SAFE = 1
+ lambda {
+ @s.SafeStringValue("str".taint)
+ }.should raise_error(SecurityError)
+ }.join
+ ensure
+ $SAFE = 0
+ end
end
it_behaves_like :string_value_macro, :SafeStringValue
diff --git a/spec/ruby/security/cve_2011_4815_spec.rb b/spec/ruby/security/cve_2011_4815_spec.rb
index 0a353b742a..74f0054850 100644
--- a/spec/ruby/security/cve_2011_4815_spec.rb
+++ b/spec/ruby/security/cve_2011_4815_spec.rb
@@ -22,6 +22,17 @@ describe "Float#hash" do
it_behaves_like :resists_cve_2011_4815, '3.14'
end
+# https://bugs.ruby-lang.org/issues/14420
+guard_not -> { platform_is :windows and PlatformGuard.implementation?(:ruby) } do
+ describe "Rational#hash" do
+ it_behaves_like :resists_cve_2011_4815, 'Rational(1, 2)'
+ end
+
+ describe "Complex#hash" do
+ it_behaves_like :resists_cve_2011_4815, 'Complex(1, 2)'
+ end
+end
+
describe "String#hash" do
it_behaves_like :resists_cve_2011_4815, '"abc"'
end
diff --git a/spec/ruby/shared/complex/Complex.rb b/spec/ruby/shared/complex/Complex.rb
index 15feb65754..0bed5c1a36 100644
--- a/spec/ruby/shared/complex/Complex.rb
+++ b/spec/ruby/shared/complex/Complex.rb
@@ -35,7 +35,7 @@ describe :kernel_Complex, shared: true do
end
end
- describe "when passed [Integer]" do
+ describe "when passed [Integer/Float]" do
it "returns a new Complex number with 0 as the imaginary component" do
# Guard against the Mathn library
conflicts_with :Prime do
@@ -62,7 +62,7 @@ describe :kernel_Complex, shared: true do
it "needs to be reviewed for spec completeness"
end
- describe "when passed an Objectc which responds to #to_c" do
+ describe "when passed an Object which responds to #to_c" do
it "returns the passed argument" do
obj = Object.new; def obj.to_c; 1i end
Complex(obj).should == Complex(0, 1)
@@ -130,4 +130,12 @@ describe :kernel_Complex, shared: true do
lambda { Complex.send(@method, 0, :sym) }.should raise_error(TypeError)
end
end
+
+ describe "when passed nil" do
+ it "raises TypeError" do
+ lambda { Complex(nil) }.should raise_error(TypeError, "can't convert nil into Complex")
+ lambda { Complex(0, nil) }.should raise_error(TypeError, "can't convert nil into Complex")
+ lambda { Complex(nil, 0) }.should raise_error(TypeError, "can't convert nil into Complex")
+ end
+ end
end
diff --git a/spec/ruby/shared/complex/hash.rb b/spec/ruby/shared/complex/hash.rb
deleted file mode 100644
index 26ca59aeaf..0000000000
--- a/spec/ruby/shared/complex/hash.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe :complex_hash, shared: true do
- it "is static" do
- Complex(1).hash.should == Complex(1).hash
- Complex(1, 0).hash.should == Complex(1).hash
- Complex(1, 1).hash.should == Complex(1, 1).hash
- end
-
- it "is different for different instances" do
- Complex(1, 2).hash.should_not == Complex(1, 1).hash
- Complex(2, 1).hash.should_not == Complex(1, 1).hash
-
- Complex(1, 2).hash.should_not == Complex(2, 1).hash
- end
-end
diff --git a/spec/ruby/shared/fiber/resume.rb b/spec/ruby/shared/fiber/resume.rb
index 058ef4e15a..e2d30d781b 100644
--- a/spec/ruby/shared/fiber/resume.rb
+++ b/spec/ruby/shared/fiber/resume.rb
@@ -4,19 +4,16 @@ describe :fiber_resume, shared: true do
fiber.send(@method).should == :fiber
end
- it "raises a FiberError if the Fiber tries to resume itself" do
- fiber = Fiber.new { fiber.resume }
- -> { fiber.resume }.should raise_error(FiberError, /double resume/)
- end
-
it "raises a FiberError if invoked from a different Thread" do
fiber = Fiber.new { 42 }
Thread.new do
-> {
- fiber.resume
+ fiber.send(@method)
}.should raise_error(FiberError)
end.join
- fiber.resume.should == 42
+
+ # Check the Fiber can still be used
+ fiber.send(@method).should == 42
end
it "passes control to the beginning of the block on first invocation" do
diff --git a/spec/ruby/shared/hash/key_error.rb b/spec/ruby/shared/hash/key_error.rb
new file mode 100644
index 0000000000..061c88c483
--- /dev/null
+++ b/spec/ruby/shared/hash/key_error.rb
@@ -0,0 +1,25 @@
+describe :key_error, shared: true do
+ it "raises a KeyError" do
+ -> {
+ @method.call(@object, 'foo')
+ }.should raise_error(KeyError)
+ end
+
+ ruby_version_is "2.5" do
+ it "sets the Hash as the receiver of KeyError" do
+ -> {
+ @method.call(@object, 'foo')
+ }.should raise_error(KeyError) { |err|
+ err.receiver.should equal(@object)
+ }
+ end
+
+ it "sets the unmatched key as the key of KeyError" do
+ -> {
+ @method.call(@object, 'foo')
+ }.should raise_error(KeyError) { |err|
+ err.key.to_s.should == 'foo'
+ }
+ end
+ end
+end